Skip to content

Commit 41b11d5

Browse files
committed
Don't include maxstanzas if no value is available
Updates #3714
1 parent 8d20d29 commit 41b11d5

File tree

7 files changed

+73
-27
lines changed

7 files changed

+73
-27
lines changed

src/headless/plugins/muc/muc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
224224
* @param {boolean} is_new
225225
*/
226226
async constructJoinPresence(password, is_new) {
227-
const maxstanzas = is_new || this.features.get('mam_enabled') ? 0 : api.settings.get('muc_history_max_stanzas');
227+
const exclude_maxstanzas = is_new || this.features.get('mam_enabled');
228+
const maxstanzas = exclude_maxstanzas ? 0 : api.settings.get('muc_history_max_stanzas');
228229
password = password || this.get('password');
229230

230231
const { profile } = _converse.state;
@@ -236,7 +237,7 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
236237
from="${api.connection.get().jid}"
237238
to="${this.getRoomJIDAndNick()}">
238239
<x xmlns="${Strophe.NS.MUC}">
239-
<history maxstanzas="${maxstanzas}"/>
240+
${maxstanzas ? stx`<history maxstanzas="${maxstanzas}"/>` : ''}
240241
${password ? stx`<password>${password}</password>` : ''}
241242
</x>
242243
${PRES_SHOW_VALUES.includes(show) ? stx`<show>${show}</show>` : ''}

src/headless/plugins/muc/tests/muc.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Groupchats", function () {
5757
let pres = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence').pop());
5858
expect(pres).toEqualStanza(stx`
5959
<presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="${muc_jid}/romeo" xmlns="jabber:client">
60-
<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>
60+
<x xmlns="http://jabber.org/protocol/muc"/>
6161
<show>away</show>
6262
<c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
6363
</presence>`);
@@ -86,7 +86,7 @@ describe("Groupchats", function () {
8686
pres = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence').pop());
8787
expect(pres).toEqualStanza(stx`
8888
<presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="${muc2_jid}/romeo" xmlns="jabber:client">
89-
<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>
89+
<x xmlns="http://jabber.org/protocol/muc"/>
9090
<show>dnd</show>
9191
<status>Do not disturb</status>
9292
<c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
@@ -142,11 +142,11 @@ describe("Groupchats", function () {
142142

143143
const pres = await u.waitUntil(
144144
() => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop());
145-
expect(Strophe.serialize(pres)).toBe(
146-
`<presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">`+
147-
`<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>`+
148-
`<c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>`+
149-
`</presence>`);
145+
expect(pres).toEqualStanza(stx`
146+
<presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">
147+
<x xmlns="http://jabber.org/protocol/muc"/>
148+
<c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
149+
</presence>`);
150150
}));
151151
});
152152
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*global converse */
2+
import mock from '../../../tests/mock.js';
3+
4+
const { stx, u } = converse.env;
5+
6+
describe('MUC presence history element', function () {
7+
beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
8+
9+
it(
10+
'includes history when maxstanzas is set',
11+
mock.initConverse(['statusInitialized'], { muc_history_max_stanzas: 5 }, async function (_converse) {
12+
const { api } = _converse;
13+
const muc_jid = 'room@server';
14+
const nick = 'test';
15+
const jid = _converse.session.get('jid');
16+
await mock.openAndEnterMUC(_converse, muc_jid, nick, ['http://jabber.org/protocol/muc']);
17+
const { sent_stanzas } = _converse.api.connection.get();
18+
19+
let sent_stanza = await u.waitUntil(() =>
20+
sent_stanzas
21+
.filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc_jid}/${nick}`)
22+
.pop()
23+
);
24+
expect(sent_stanza).toEqualStanza(stx`
25+
<presence to="${muc_jid}/${nick}" xmlns="jabber:client" id="${sent_stanza.getAttribute('id')}" from="${jid}">
26+
<x xmlns="http://jabber.org/protocol/muc">
27+
<history maxstanzas="5"/>
28+
</x>
29+
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI="/>
30+
</presence>`);
31+
32+
api.settings.set('muc_history_max_stanzas', 0);
33+
34+
const muc2_jid = 'room2@server';
35+
await mock.openAndEnterMUC(_converse, muc2_jid, nick);
36+
sent_stanza = await u.waitUntil(() =>
37+
sent_stanzas
38+
.filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc2_jid}/${nick}`)
39+
.pop()
40+
);
41+
expect(sent_stanza).toEqualStanza(stx`
42+
<presence to="${muc2_jid}/${nick}" xmlns="jabber:client" id="${sent_stanza.getAttribute('id')}" from="${jid}">
43+
<x xmlns="http://jabber.org/protocol/muc"/>
44+
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI="/>
45+
</presence>`);
46+
})
47+
);
48+
});

src/headless/tests/mock.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const chatroom_names = [
1010
'Dirk Theissen',
1111
'Felix Hofmann',
1212
'Ka Lek',
13-
'Anne Ebersbacher'
13+
'Anne Ebersbacher',
1414
];
1515

1616
export const default_muc_features = [
@@ -246,9 +246,13 @@ export async function receiveOwnMUCPresence(
246246
role = 'moderator',
247247
features = []
248248
) {
249-
const { u, sizzle } = window.converse.env;
249+
const { u } = window.converse.env;
250250
const sent_stanzas = _converse.api.connection.get().sent_stanzas;
251-
await u.waitUntil(() => sent_stanzas.filter((iq) => sizzle('presence history', iq).length).pop());
251+
await u.waitUntil(
252+
() =>
253+
sent_stanzas.filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc_jid}/${nick}`)
254+
.length
255+
);
252256

253257
_converse.api.connection.get()._dataRecv(
254258
createRequest(stx`

src/plugins/bookmark-views/tests/bookmarks.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ describe("Bookmarks", function () {
272272
id="${sent_stanza.getAttribute('id')}"
273273
to="${autojoin_muc}/JC">
274274
<x xmlns="http://jabber.org/protocol/muc">
275-
<history maxstanzas="0"/>
276275
<password>secret</password>
277276
</x>
278277
<c xmlns="http://jabber.org/protocol/caps"

src/plugins/muc-views/tests/muc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ describe("Groupchats", function () {
18221822
await mock.openAndEnterMUC(_converse, muc_jid, 'romeo', features);
18231823
const view = _converse.chatboxviews.get(muc_jid);
18241824

1825-
const info_el = view.querySelector(".show-muc-details-modal");
1825+
const info_el = await u.waitUntil(() => view.querySelector(".show-muc-details-modal"));
18261826
info_el.click();
18271827
let modal = _converse.api.modal.get('converse-muc-details-modal');
18281828
await u.waitUntil(() => u.isVisible(modal), 1000);

src/plugins/muc-views/tests/nickname.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe("A MUC", function () {
357357

358358
const connection = api.connection.get();
359359
const sent_stanzas = connection.sent_stanzas;
360-
await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
360+
await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
361361

362362
const { IQ_stanzas } = api.connection.get();
363363

@@ -381,15 +381,13 @@ describe("A MUC", function () {
381381

382382
await mock.waitForMUCDiscoInfo(_converse, muc_jid);
383383

384-
let sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
384+
let sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
385385
expect(sent_stanza).toEqualStanza(stx`
386386
<presence id="${sent_stanza.getAttribute('id')}"
387387
from="${connection.jid}"
388388
to="${muc_jid}/romeo-2"
389389
xmlns="jabber:client">
390-
<x xmlns="http://jabber.org/protocol/muc">
391-
<history maxstanzas="0"/>
392-
</x>
390+
<x xmlns="http://jabber.org/protocol/muc"/>
393391
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
394392
ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
395393
</presence>`);
@@ -413,15 +411,13 @@ describe("A MUC", function () {
413411

414412
await mock.waitForMUCDiscoInfo(_converse, muc_jid);
415413

416-
sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
414+
sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
417415
expect(sent_stanza).toEqualStanza(stx`
418416
<presence id="${sent_stanza.getAttribute('id')}"
419417
from="${connection.jid}"
420418
to="${muc_jid}/romeo-3"
421419
xmlns="jabber:client">
422-
<x xmlns="http://jabber.org/protocol/muc">
423-
<history maxstanzas="0"/>
424-
</x>
420+
<x xmlns="http://jabber.org/protocol/muc"/>
425421
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
426422
ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
427423
</presence>`);
@@ -445,15 +441,13 @@ describe("A MUC", function () {
445441

446442
await mock.waitForMUCDiscoInfo(_converse, muc_jid);
447443

448-
sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
444+
sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
449445
expect(sent_stanza).toEqualStanza(stx`
450446
<presence id="${sent_stanza.getAttribute('id')}"
451447
from="${connection.jid}"
452448
to="${muc_jid}/romeo-4"
453449
xmlns="jabber:client">
454-
<x xmlns="http://jabber.org/protocol/muc">
455-
<history maxstanzas="0"/>
456-
</x>
450+
<x xmlns="http://jabber.org/protocol/muc"/>
457451
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
458452
ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
459453
</presence>`);

0 commit comments

Comments
 (0)