Răsfoiți Sursa

Don't include `maxstanzas` if no value is available

Updates #3714
JC Brand 3 săptămâni în urmă
părinte
comite
41b11d5fe7

+ 3 - 2
src/headless/plugins/muc/muc.js

@@ -224,7 +224,8 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
      * @param {boolean} is_new
      */
     async constructJoinPresence(password, is_new) {
-        const maxstanzas = is_new || this.features.get('mam_enabled') ? 0 : api.settings.get('muc_history_max_stanzas');
+        const exclude_maxstanzas = is_new || this.features.get('mam_enabled');
+        const maxstanzas = exclude_maxstanzas ? 0 : api.settings.get('muc_history_max_stanzas');
         password = password || this.get('password');
 
         const { profile } = _converse.state;
@@ -236,7 +237,7 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
                       from="${api.connection.get().jid}"
                       to="${this.getRoomJIDAndNick()}">
                 <x xmlns="${Strophe.NS.MUC}">
-                    <history maxstanzas="${maxstanzas}"/>
+                    ${maxstanzas ? stx`<history maxstanzas="${maxstanzas}"/>` : ''}
                     ${password ? stx`<password>${password}</password>` : ''}
                 </x>
                 ${PRES_SHOW_VALUES.includes(show) ? stx`<show>${show}</show>` : ''}

+ 7 - 7
src/headless/plugins/muc/tests/muc.js

@@ -57,7 +57,7 @@ describe("Groupchats", function () {
             let pres = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence').pop());
             expect(pres).toEqualStanza(stx`
                 <presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="${muc_jid}/romeo" xmlns="jabber:client">
-                    <x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>
+                    <x xmlns="http://jabber.org/protocol/muc"/>
                     <show>away</show>
                     <c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
                 </presence>`);
@@ -86,7 +86,7 @@ describe("Groupchats", function () {
             pres = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence').pop());
             expect(pres).toEqualStanza(stx`
                 <presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="${muc2_jid}/romeo" xmlns="jabber:client">
-                    <x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>
+                    <x xmlns="http://jabber.org/protocol/muc"/>
                     <show>dnd</show>
                     <status>Do not disturb</status>
                     <c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
@@ -142,11 +142,11 @@ describe("Groupchats", function () {
 
             const pres = await u.waitUntil(
                 () => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop());
-            expect(Strophe.serialize(pres)).toBe(
-                `<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>`+
-                    `<c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>`+
-                `</presence>`);
+            expect(pres).toEqualStanza(stx`
+                <presence from="${_converse.jid}" id="${pres.getAttribute('id')}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">
+                    <x xmlns="http://jabber.org/protocol/muc"/>
+                    <c hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI=" xmlns="http://jabber.org/protocol/caps"/>
+                </presence>`);
         }));
     });
 });

+ 48 - 0
src/headless/plugins/muc/tests/presence.js

@@ -0,0 +1,48 @@
+/*global converse */
+import mock from '../../../tests/mock.js';
+
+const { stx, u } = converse.env;
+
+describe('MUC presence history element', function () {
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
+    it(
+        'includes history when maxstanzas is set',
+        mock.initConverse(['statusInitialized'], { muc_history_max_stanzas: 5 }, async function (_converse) {
+            const { api } = _converse;
+            const muc_jid = 'room@server';
+            const nick = 'test';
+            const jid = _converse.session.get('jid');
+            await mock.openAndEnterMUC(_converse, muc_jid, nick, ['http://jabber.org/protocol/muc']);
+            const { sent_stanzas } = _converse.api.connection.get();
+
+            let sent_stanza = await u.waitUntil(() =>
+                sent_stanzas
+                    .filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc_jid}/${nick}`)
+                    .pop()
+            );
+            expect(sent_stanza).toEqualStanza(stx`
+              <presence to="${muc_jid}/${nick}" xmlns="jabber:client" id="${sent_stanza.getAttribute('id')}" from="${jid}">
+                <x xmlns="http://jabber.org/protocol/muc">
+                  <history maxstanzas="5"/>
+                </x>
+                <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI="/>
+              </presence>`);
+
+            api.settings.set('muc_history_max_stanzas', 0);
+
+            const muc2_jid = 'room2@server';
+            await mock.openAndEnterMUC(_converse, muc2_jid, nick);
+            sent_stanza = await u.waitUntil(() =>
+                sent_stanzas
+                    .filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc2_jid}/${nick}`)
+                    .pop()
+            );
+            expect(sent_stanza).toEqualStanza(stx`
+              <presence to="${muc2_jid}/${nick}" xmlns="jabber:client" id="${sent_stanza.getAttribute('id')}" from="${jid}">
+                <x xmlns="http://jabber.org/protocol/muc"/>
+                <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org" ver="t7NrIuCRhg80cJKAq33v3LKogjI="/>
+              </presence>`);
+        })
+    );
+});

+ 7 - 3
src/headless/tests/mock.js

@@ -10,7 +10,7 @@ export const chatroom_names = [
     'Dirk Theissen',
     'Felix Hofmann',
     'Ka Lek',
-    'Anne Ebersbacher'
+    'Anne Ebersbacher',
 ];
 
 export const default_muc_features = [
@@ -246,9 +246,13 @@ export async function receiveOwnMUCPresence(
     role = 'moderator',
     features = []
 ) {
-    const { u, sizzle } = window.converse.env;
+    const { u } = window.converse.env;
     const sent_stanzas = _converse.api.connection.get().sent_stanzas;
-    await u.waitUntil(() => sent_stanzas.filter((iq) => sizzle('presence history', iq).length).pop());
+    await u.waitUntil(
+        () =>
+            sent_stanzas.filter((s) => s.nodeName === 'presence' && s.getAttribute('to') === `${muc_jid}/${nick}`)
+                .length
+    );
 
     _converse.api.connection.get()._dataRecv(
         createRequest(stx`

+ 0 - 1
src/plugins/bookmark-views/tests/bookmarks.js

@@ -272,7 +272,6 @@ describe("Bookmarks", function () {
                 id="${sent_stanza.getAttribute('id')}"
                 to="${autojoin_muc}/JC">
             <x xmlns="http://jabber.org/protocol/muc">
-                <history maxstanzas="0"/>
                 <password>secret</password>
             </x>
             <c xmlns="http://jabber.org/protocol/caps"

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

@@ -1822,7 +1822,7 @@ describe("Groupchats", function () {
             await mock.openAndEnterMUC(_converse, muc_jid, 'romeo', features);
             const view = _converse.chatboxviews.get(muc_jid);
 
-            const info_el = view.querySelector(".show-muc-details-modal");
+            const info_el = await u.waitUntil(() => view.querySelector(".show-muc-details-modal"));
             info_el.click();
             let modal = _converse.api.modal.get('converse-muc-details-modal');
             await u.waitUntil(() => u.isVisible(modal), 1000);

+ 7 - 13
src/plugins/muc-views/tests/nickname.js

@@ -357,7 +357,7 @@ describe("A MUC", function () {
 
             const connection = api.connection.get();
             const sent_stanzas = connection.sent_stanzas;
-            await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
+            await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
 
             const { IQ_stanzas } = api.connection.get();
 
@@ -381,15 +381,13 @@ describe("A MUC", function () {
 
             await mock.waitForMUCDiscoInfo(_converse, muc_jid);
 
-            let sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
+            let sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
             expect(sent_stanza).toEqualStanza(stx`
                 <presence id="${sent_stanza.getAttribute('id')}"
                         from="${connection.jid}"
                         to="${muc_jid}/romeo-2"
                         xmlns="jabber:client">
-                    <x xmlns="http://jabber.org/protocol/muc">
-                        <history maxstanzas="0"/>
-                    </x>
+                    <x xmlns="http://jabber.org/protocol/muc"/>
                     <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
                         ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
                 </presence>`);
@@ -413,15 +411,13 @@ describe("A MUC", function () {
 
             await mock.waitForMUCDiscoInfo(_converse, muc_jid);
 
-            sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
+            sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
             expect(sent_stanza).toEqualStanza(stx`
                 <presence id="${sent_stanza.getAttribute('id')}"
                         from="${connection.jid}"
                         to="${muc_jid}/romeo-3"
                         xmlns="jabber:client">
-                    <x xmlns="http://jabber.org/protocol/muc">
-                        <history maxstanzas="0"/>
-                    </x>
+                    <x xmlns="http://jabber.org/protocol/muc"/>
                     <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
                         ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
                 </presence>`);
@@ -445,15 +441,13 @@ describe("A MUC", function () {
 
             await mock.waitForMUCDiscoInfo(_converse, muc_jid);
 
-            sent_stanza = await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
+            sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName === 'presence' && s.getAttribute('to').startsWith(muc_jid)).pop());
             expect(sent_stanza).toEqualStanza(stx`
                 <presence id="${sent_stanza.getAttribute('id')}"
                         from="${connection.jid}"
                         to="${muc_jid}/romeo-4"
                         xmlns="jabber:client">
-                    <x xmlns="http://jabber.org/protocol/muc">
-                        <history maxstanzas="0"/>
-                    </x>
+                    <x xmlns="http://jabber.org/protocol/muc"/>
                     <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://conversejs.org"
                         ver="qgxN8hmrdSa2/4/7PUoM9bPFN2s="/>
                 </presence>`);