From 46a5a64ddac06c8847394d3466d9bbc3be8849a3 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Tue, 25 Jan 2022 13:04:14 +0100 Subject: [PATCH] Set `id` on MUC join presence This is necessary for the Bifrost Matrix-XMPP bridge --- src/headless/plugins/muc/muc.js | 15 ++++++++------- src/headless/plugins/muc/tests/muc.js | 2 +- src/headless/utils/core.js | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 8d478cb2c..a6b62c739 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -14,7 +14,7 @@ import { computeAffiliationsDelta, setAffiliations, getAffiliationList } from ' import { getOpenPromise } from '@converse/openpromise'; import { initStorage } from '@converse/headless/utils/storage.js'; import { isArchived, getMediaURLsMetadata } from '@converse/headless/shared/parsers'; -import { isUniView } from '@converse/headless/utils/core.js'; +import { isUniView, getUniqueId } from '@converse/headless/utils/core.js'; import { parseMUCMessage, parseMUCPresence } from './parsers.js'; import { sendMarker } from '@converse/headless/shared/actions'; @@ -188,6 +188,7 @@ const ChatRoomMixin = { async constructPresence (password) { let stanza = $pres({ + 'id': getUniqueId(), 'from': _converse.connection.jid, 'to': this.getRoomJIDAndNick() }).c('x', { 'xmlns': Strophe.NS.MUC }) @@ -732,7 +733,7 @@ const ChatRoomMixin = { } const editable = message.get('editable'); const stanza = $msg({ - 'id': u.getUniqueId(), + 'id': getUniqueId(), 'to': this.get('jid'), 'type': 'groupchat' }) @@ -980,7 +981,7 @@ const ChatRoomMixin = { if (attrs?.body) { [text, references] = this.parseTextForReferences(attrs.body); } - const origin_id = u.getUniqueId(); + const origin_id = getUniqueId(); const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined; return Object.assign({}, attrs, { body, @@ -1073,7 +1074,7 @@ const ChatRoomMixin = { const invitation = $msg({ 'from': _converse.connection.jid, 'to': recipient, - 'id': u.getUniqueId() + 'id': getUniqueId() }).c('x', attrs); api.send(invitation); /** @@ -1424,9 +1425,9 @@ const ChatRoomMixin = { const jid = Strophe.getBareJidFromJid(this.get('jid')); api.send( $pres({ - from: _converse.connection.jid, - to: `${jid}/${nick}`, - id: u.getUniqueId() + 'from': _converse.connection.jid, + 'to': `${jid}/${nick}`, + 'id': getUniqueId() }).tree() ) }, diff --git a/src/headless/plugins/muc/tests/muc.js b/src/headless/plugins/muc/tests/muc.js index 946287373..08de80dbc 100644 --- a/src/headless/plugins/muc/tests/muc.js +++ b/src/headless/plugins/muc/tests/muc.js @@ -85,7 +85,7 @@ describe("Groupchats", function () { const pres = await u.waitUntil( () => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop()); expect(Strophe.serialize(pres)).toBe( - ``+ + ``+ ``+ ``+ ``); diff --git a/src/headless/utils/core.js b/src/headless/utils/core.js index ec9c63a41..78a7f023b 100644 --- a/src/headless/utils/core.js +++ b/src/headless/utils/core.js @@ -433,7 +433,7 @@ u.placeCaretAtEnd = function (textarea) { this.scrollTop = 999999; }; -u.getUniqueId = function (suffix) { +export function getUniqueId (suffix) { const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : r & 0x3 | 0x8; @@ -574,5 +574,6 @@ export function decodeHTMLEntities (str) { } export default Object.assign({ - isEmptyMessage + isEmptyMessage, + getUniqueId }, u);