Skip to content

Commit

Permalink
Add x element to MUC private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Jan 21, 2025
1 parent 985243c commit b6d4c6d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
12 changes: 12 additions & 0 deletions src/headless/plugins/muc/occupant.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Model } from '@converse/skeletor';
import log from '../../log';
import api from '../../shared/api/index.js';
import _converse from '../../shared/_converse.js';
import converse from '../../shared/api/public.js';
import ColorAwareModel from '../../shared/color.js';
import ModelWithMessages from '../../shared/model-with-messages.js';
import { AFFILIATIONS, ROLES } from './constants.js';
Expand All @@ -10,6 +11,8 @@ import u from '../../utils/index.js';
import { shouldCreateGroupchatMessage } from './utils';
import { sendChatState } from '../../shared/actions';

const { Strophe, stx } = converse.env;

/**
* Represents a participant in a MUC
*/
Expand Down Expand Up @@ -189,6 +192,15 @@ class MUCOccupant extends ModelWithMessages(ColorAwareModel(Model)) {
attrs = await api.hook('getOutgoingMessageAttributes', this, attrs);
return attrs;
}

/**
* @param {import('../chat/message').default} message - The message object
*/
async createMessageStanza(message) {
const stanza = await super.createMessageStanza(message);
stanza.cnode(stx`<x xmlns="${Strophe.NS.MUC}#user"/>`).root();
return stanza;
}
}

export default MUCOccupant;
29 changes: 15 additions & 14 deletions src/headless/types/plugins/muc/occupant.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ declare const MUCOccupant_base: {
fetchMessages(): any;
afterMessagesFetched(): void;
onMessage(_attrs_or_error: import("../chat/types").MessageAttributes | Error): Promise<void>;
getUpdatedMessageAttributes(message: import("../chat").Message, attrs: import("../chat/types").MessageAttributes): object;
updateMessage(message: import("../chat").Message, attrs: import("../chat/types").MessageAttributes): void;
handleCorrection(attrs: import("../chat/types").MessageAttributes | import("./types").MUCMessageAttributes): Promise<import("../chat").Message | void>;
getUpdatedMessageAttributes(message: import("../chat/message").default, attrs: import("../chat/types").MessageAttributes): object;
updateMessage(message: import("../chat/message").default, attrs: import("../chat/types").MessageAttributes): void;
handleCorrection(attrs: import("../chat/types").MessageAttributes | import("./types").MUCMessageAttributes): Promise<import("../chat/message").default | void>;
queueMessage(attrs: import("../chat/types").MessageAttributes): any;
msg_chain: any;
getOutgoingMessageAttributes(_attrs?: import("../chat/types").MessageAttributes): Promise<import("../chat/types").MessageAttributes>;
sendMessage(attrs?: any): Promise<import("../chat").Message>;
retractOwnMessage(message: import("../chat").Message): void;
sendMessage(attrs?: any): Promise<import("../chat/message").default>;
retractOwnMessage(message: import("../chat/message").default): void;
sendFiles(files: File[]): Promise<void>;
setEditable(attrs: any, send_time: string): void;
setChatState(state: string, options?: object): any;
chat_state_timeout: NodeJS.Timeout;
onMessageAdded(message: import("../chat").Message): void;
onMessageUploadChanged(message: import("../chat").Message): Promise<void>;
onMessageAdded(message: import("../chat/message").default): void;
onMessageUploadChanged(message: import("../chat/message").default): Promise<void>;
onScrolledChanged(): void;
pruneHistoryWhenScrolledDown(): void;
shouldShowErrorMessage(attrs: import("../chat/types").MessageAttributes): Promise<boolean>;
Expand All @@ -41,8 +41,8 @@ declare const MUCOccupant_base: {
getOldestMessage(): any;
getMostRecentMessage(): any;
getMessageReferencedByError(attrs: object): any;
findDanglingRetraction(attrs: object): import("../chat").Message | null;
getDuplicateMessage(attrs: object): import("../chat").Message;
findDanglingRetraction(attrs: object): import("../chat/message").default | null;
getDuplicateMessage(attrs: object): import("../chat/message").default;
getOriginIdQueryAttrs(attrs: object): {
origin_id: any;
from: any;
Expand All @@ -52,15 +52,15 @@ declare const MUCOccupant_base: {
from: any;
msgid: any;
};
sendMarkerForMessage(msg: import("../chat").Message, type?: ("received" | "displayed" | "acknowledged"), force?: boolean): Promise<void>;
handleUnreadMessage(message: import("../chat").Message): void;
getErrorAttributesForMessage(message: import("../chat").Message, attrs: import("../chat/types").MessageAttributes): Promise<any>;
sendMarkerForMessage(msg: import("../chat/message").default, type?: ("received" | "displayed" | "acknowledged"), force?: boolean): Promise<void>;
handleUnreadMessage(message: import("../chat/message").default): void;
getErrorAttributesForMessage(message: import("../chat/message").default, attrs: import("../chat/types").MessageAttributes): Promise<any>;
handleErrorMessageStanza(stanza: Element): Promise<void>;
incrementUnreadMsgsCounter(message: import("../chat").Message): void;
incrementUnreadMsgsCounter(message: import("../chat/message").default): void;
clearUnreadMsgCounter(): void;
handleRetraction(attrs: import("../chat/types").MessageAttributes): Promise<boolean>;
handleReceipt(attrs: import("../chat/types").MessageAttributes): boolean;
createMessageStanza(message: import("../chat").Message): Promise<any>;
createMessageStanza(message: import("../chat/message").default): Promise<any>;
pruneHistory(): void;
debouncedPruneHistory: import("lodash").DebouncedFunc<() => void>;
isScrolledUp(): any;
Expand Down Expand Up @@ -214,6 +214,7 @@ declare class MUCOccupant extends MUCOccupant_base {
states: any[];
hidden: boolean;
num_unread: number;
message_type: string;
};
save(key: any, val: any, options: any): any;
getMessagesCollection(): MUCMessages;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/muc-views/tests/muc-private-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ describe('MUC Private Messages', () => {
<active xmlns="http://jabber.org/protocol/chatstates"/>
<request xmlns="urn:xmpp:receipts"/>
<origin-id xmlns="urn:xmpp:sid:0" id="${sent_stanza.querySelector('origin-id')?.getAttribute('id')}"/>
<x xmlns="http://jabber.org/protocol/muc#user"/>
</message>`);
})
);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/rosterview/contactview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Model } from '@converse/skeletor';
import { _converse, converse, api, log } from '@converse/headless';
import { _converse, converse, api } from '@converse/headless';
import { CustomElement } from 'shared/components/element.js';
import tplRequestingContact from './templates/requesting_contact.js';
import tplRosterItem from './templates/roster_item.js';
Expand Down
1 change: 0 additions & 1 deletion src/types/plugins/omemo/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function parseEncryptedMessage(stanza: Element, attrs: (MUCMessageAttribu
export function onChatBoxesInitialized(): void;
export function onChatInitialized(el: any): void;
export function getSessionCipher(jid: any, id: any): any;
export function addKeysToMessageStanza(stanza: any, dicts: any, iv: any): Promise<any>;
/**
* Given an XML element representing a user's OMEMO bundle, parse it
* and return a map.
Expand Down

0 comments on commit b6d4c6d

Please sign in to comment.