Browse Source

Merge remote-tracking branch 'origin/master'

Hosted Weblate 3 weeks ago
parent
commit
a660338f3f

+ 1 - 1
Makefile

@@ -196,7 +196,7 @@ logo/conversejs-filled%.png:: logo/conversejs-filled.svg
 @converse/headless: src/headless
 
 src/headless/dist/converse-headless.js: src rspack/rspack.common.js node_modules @converse/headless
-	npm run headless-dev
+	npm run dev:headless
 
 src/headless/dist/converse-headless.min.js: src rspack/rspack.common.js node_modules @converse/headless
 	npm run headless

+ 12 - 12
package.json

@@ -47,27 +47,27 @@
     "3rdparty/*.js"
   ],
   "scripts": {
-    "build": "npm run build:website-min-css && rspack build --config rspack/rspack.build.js",
+    "build": "npm run build:website-min-css && DROP_DEBUGGER=true rspack build --config rspack/rspack.build.js",
     "build:website-css": "sass --quiet --load-path=node_modules src/shared/styles/website.scss dist/website.css",
     "build:website-min-css": "npm run build:website-css && npx clean-css-cli dist/website.css > dist/website.min.css",
-    "lint": "eslint src/**/*.js",
-    "test": "karma start karma.conf",
-    "test:headless": "cd src/headless && karma start karma.conf.js",
-    "test:all": "npm run test:headless -- --single-run && npm run test -- --single-run",
     "cdn": "ASSET_PATH=https://cdn.conversejs.org/dist/ npm run build",
     "clean": "rm -rf node_modules dist *.zip src/headless/dist src/headless/node_modules",
-    "dev": "rspack build --config rspack/rspack.build.js --mode=development",
+    "dev": "DROP_DEBUGGER=false rspack build --config rspack/rspack.build.js --mode=development",
+    "dev:headless": "DROP_DEBUGGER=false rspack build --config rspack/rspack.headless.js --mode=development",
+    "devserver": "npm run dev:headless && npx rspack serve --config rspack/rspack.serve.js",
     "headless": "rspack build --config rspack/rspack.headless.js",
-    "headless-dev": "rspack build --config rspack/rspack.headless.js --mode=development",
+    "lint": "eslint src/**/*.js",
     "nodeps": "rspack build --config rspack/rspack.nodeps.js",
     "serve": "http-server -c-1",
     "serve-tls": "http-server -S -C certs/chat.example.org.crt -K certs/chat.example.org.key",
-    "devserver": "npm run headless-dev && npx rspack serve --config rspack/rspack.serve.js",
-    "watch": "concurrently \"npm run watch:headless\" \"npm run watch:main\"",
-    "watch:headless": "rspack --watch --config rspack/rspack.headless.js --mode=development",
-    "watch:main": "rspack --watch --config rspack/rspack.build.js --mode=development",
+    "test": "karma start karma.conf",
+    "test:all": "npm run test:headless -- --single-run && npm run test -- --single-run",
+    "test:headless": "cd src/headless && karma start karma.conf.js",
     "types": "tsc -p ./src/log/tsconfig.json && tsc -p ./src/headless/tsconfig.json && tsc",
-    "check:types": "tsc --noEmit"
+    "types:check": "tsc --noEmit",
+    "watch": "concurrently \"npm run watch:headless\" \"npm run watch:main\"",
+    "watch:headless": "DROP_DEBUGGER=false rspack --watch --config rspack/rspack.headless.js --mode=development",
+    "watch:main": "DROP_DEBUGGER=false rspack --watch --config rspack/rspack.build.js --mode=development"
   },
   "repository": {
     "type": "git",

+ 1 - 0
rspack/rspack.build.js

@@ -18,6 +18,7 @@ const sharedConfig = {
                     minify: true,
                     mangle: true,
                     compress: {
+                        drop_debugger: process.env.DROP_DEBUGGER === 'true',
                         passes: 2,
                     },
                     format: {

+ 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"

+ 12 - 6
src/plugins/controlbox/templates/controlbox.js

@@ -11,21 +11,27 @@ const { ANONYMOUS } = constants;
 function whenNotConnected(el) {
     const is_fullscreen = api.settings.get('view_mode') === 'fullscreen';
     const connection_status = _converse.state.connfeedback.get('connection_status');
-    const connecting = [Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING].includes(connection_status);
+    const connecting = [Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING, Strophe.Status.CONNECTED].includes(
+        connection_status
+    );
     const view_mode = api.settings.get('view_mode');
     const show_bg = api.settings.get('show_background');
+
     return html`
         ${show_bg && view_mode === 'fullscreen' ? html`<converse-bg></converse-bg>` : ''}
         <converse-controlbox-buttons class="controlbox-padded"></converse-controlbox-buttons>
         <div class="controlbox-pane d-flex flex-column justify-content-between">
-            ${is_fullscreen ? html`<converse-controlbox-navbar></converse-controlbox-navbar>` : ''}
-            <converse-brand-logo></converse-brand-logo>
             ${connecting
                 ? html`<converse-spinner class="vertically-centered fade-in"></converse-spinner>`
                 : el.model.get('active-form') === 'register'
-                  ? html`<converse-registration-form class="fade-in rounded"></converse-registration-form>`
-                  : html`<converse-login-form class="fade-in rounded"></converse-login-form>`}
-            ${is_fullscreen ? html`<converse-footer></converse-footer>` : ''}
+                  ? html`${is_fullscreen ? html`<converse-controlbox-navbar></converse-controlbox-navbar>` : ''}
+                        <converse-brand-logo></converse-brand-logo>
+                        <converse-registration-form class="fade-in rounded"></converse-registration-form>
+                        ${is_fullscreen ? html`<converse-footer></converse-footer>` : ''} `
+                  : html`${is_fullscreen ? html`<converse-controlbox-navbar></converse-controlbox-navbar>` : ''}
+                        <converse-brand-logo></converse-brand-logo>
+                        <converse-login-form class="fade-in rounded"></converse-login-form>
+                        ${is_fullscreen ? html`<converse-footer></converse-footer>` : ''} `}
         </div>
     `;
 }

+ 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>`);

+ 1 - 1
src/types/plugins/disco-views/disco-browser.d.ts

@@ -34,7 +34,7 @@ declare class DiscoBrowser extends CustomElement {
     } | {
         features: any;
         identities: any;
-        items: any[];
+        items: any;
         error?: undefined;
     }>;
 }