Commit 2c7b2204 authored by JC Brand's avatar JC Brand

RAI: Always send the presence to enable RAI when leaving a MUC

Looking at the Prosody code, it appears to be cheap since
Prosody will do nothing if you're already registered and this works
around a bug in mod_muc_rai where events aren't fired for each resource
of the same joined nick joining or leaving the MUC.
parent 8bd2114d
......@@ -190,7 +190,6 @@ describe("XEP-0437 Room Activity Indicators", function () {
expect(_converse.session.get('rai_enabled_domains')).toBe(undefined);
const muc_jid = 'lounge@montague.lit';
const muc_domain = Strophe.getDomainFromJid(muc_jid);
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.api.chatviews.get(muc_jid);
expect(view.model.get('hidden')).toBe(false);
......@@ -212,9 +211,6 @@ describe("XEP-0437 Room Activity Indicators", function () {
`<rai xmlns="urn:xmpp:rai:0"/>`+
`</presence>`
);
expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.DISCONNECTED);
expect(_converse.session.get('rai_enabled_domains')).toBe(` ${muc_domain}`);
// If an error presence with "resource-constraint" is returned, we rejoin
const activity_stanza = u.toStanza(`
<presence type="error" from="${Strophe.getDomainFromJid(muc_jid)}">
......@@ -224,8 +220,6 @@ describe("XEP-0437 Room Activity Indicators", function () {
_converse.connection._dataRecv(mock.createRequest(activity_stanza));
await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
expect(_converse.session.get('rai_enabled_domains')).toBe(' ');
done();
}));
......
......@@ -432,8 +432,6 @@ converse.plugins.add('converse-muc', {
api.listen.on('reconnected', registerDirectInvitationHandler);
}
api.listen.on('reconnected', () => _converse.session.save('rai_enabled_domains', ''));
api.listen.on('beforeTearDown', () => {
const groupchats = _converse.chatboxes.where({ 'type': _converse.CHATROOMS_TYPE });
groupchats.forEach(muc =>
......
......@@ -211,12 +211,8 @@ const ChatRoomMixin = {
*/
enableRAI () {
if (api.settings.get('muc_subscribe_to_rai')) {
const rai_enabled = _converse.session.get('rai_enabled_domains') || '';
const muc_domain = Strophe.getDomainFromJid(this.get('jid'));
if (!rai_enabled.includes(muc_domain)) {
api.user.presence.send(null, muc_domain, null, $build('rai', { 'xmlns': Strophe.NS.RAI }));
_converse.session.save({ 'rai_enabled_domains': `${rai_enabled} ${muc_domain}` });
}
}
},
......@@ -2250,18 +2246,12 @@ const ChatRoomMixin = {
if (error?.getAttribute('type') === 'wait' && error?.querySelector('resource-constraint')) {
// If we get a <resource-constraint> error, we assume it's in context of XEP-0437 RAI.
// We remove this MUC's host from the list of enabled domains and rejoin the MUC.
const rai_enabled = _converse.session.get('rai_enabled_domains') || '';
const muc_domain = Strophe.getDomainFromJid(this.get('jid'));
if (rai_enabled.includes(muc_domain)) {
const regex = new RegExp(muc_domain, 'g');
_converse.session.save({ 'rai_enabled_domains': rai_enabled.replace(regex, '') });
if (this.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) {
this.rejoin();
}
}
}
}
},
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment