Set id on MUC join presence

This is necessary for the Bifrost Matrix-XMPP bridge
This commit is contained in:
JC Brand 2022-01-25 13:04:14 +01:00
parent 72eb9d9595
commit 46a5a64dda
3 changed files with 12 additions and 10 deletions

View File

@ -14,7 +14,7 @@ import { computeAffiliationsDelta, setAffiliations, getAffiliationList } from '
import { getOpenPromise } from '@converse/openpromise'; import { getOpenPromise } from '@converse/openpromise';
import { initStorage } from '@converse/headless/utils/storage.js'; import { initStorage } from '@converse/headless/utils/storage.js';
import { isArchived, getMediaURLsMetadata } from '@converse/headless/shared/parsers'; 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 { parseMUCMessage, parseMUCPresence } from './parsers.js';
import { sendMarker } from '@converse/headless/shared/actions'; import { sendMarker } from '@converse/headless/shared/actions';
@ -188,6 +188,7 @@ const ChatRoomMixin = {
async constructPresence (password) { async constructPresence (password) {
let stanza = $pres({ let stanza = $pres({
'id': getUniqueId(),
'from': _converse.connection.jid, 'from': _converse.connection.jid,
'to': this.getRoomJIDAndNick() 'to': this.getRoomJIDAndNick()
}).c('x', { 'xmlns': Strophe.NS.MUC }) }).c('x', { 'xmlns': Strophe.NS.MUC })
@ -732,7 +733,7 @@ const ChatRoomMixin = {
} }
const editable = message.get('editable'); const editable = message.get('editable');
const stanza = $msg({ const stanza = $msg({
'id': u.getUniqueId(), 'id': getUniqueId(),
'to': this.get('jid'), 'to': this.get('jid'),
'type': 'groupchat' 'type': 'groupchat'
}) })
@ -980,7 +981,7 @@ const ChatRoomMixin = {
if (attrs?.body) { if (attrs?.body) {
[text, references] = this.parseTextForReferences(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; const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined;
return Object.assign({}, attrs, { return Object.assign({}, attrs, {
body, body,
@ -1073,7 +1074,7 @@ const ChatRoomMixin = {
const invitation = $msg({ const invitation = $msg({
'from': _converse.connection.jid, 'from': _converse.connection.jid,
'to': recipient, 'to': recipient,
'id': u.getUniqueId() 'id': getUniqueId()
}).c('x', attrs); }).c('x', attrs);
api.send(invitation); api.send(invitation);
/** /**
@ -1424,9 +1425,9 @@ const ChatRoomMixin = {
const jid = Strophe.getBareJidFromJid(this.get('jid')); const jid = Strophe.getBareJidFromJid(this.get('jid'));
api.send( api.send(
$pres({ $pres({
from: _converse.connection.jid, 'from': _converse.connection.jid,
to: `${jid}/${nick}`, 'to': `${jid}/${nick}`,
id: u.getUniqueId() 'id': getUniqueId()
}).tree() }).tree()
) )
}, },

View File

@ -85,7 +85,7 @@ describe("Groupchats", function () {
const pres = await u.waitUntil( const pres = await u.waitUntil(
() => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop()); () => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop());
expect(Strophe.serialize(pres)).toBe( expect(Strophe.serialize(pres)).toBe(
`<presence from="${_converse.jid}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">`+ `<presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">`+
`<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>`+ `<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>`+
`<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+ `<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+
`</presence>`); `</presence>`);

View File

@ -433,7 +433,7 @@ u.placeCaretAtEnd = function (textarea) {
this.scrollTop = 999999; this.scrollTop = 999999;
}; };
u.getUniqueId = function (suffix) { export function getUniqueId (suffix) {
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0; const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : r & 0x3 | 0x8; const v = c === 'x' ? r : r & 0x3 | 0x8;
@ -574,5 +574,6 @@ export function decodeHTMLEntities (str) {
} }
export default Object.assign({ export default Object.assign({
isEmptyMessage isEmptyMessage,
getUniqueId
}, u); }, u);