Jelajahi Sumber

Select the immediate body, not the one in fallback.

Keith Maika 2 tahun lalu
induk
melakukan
17e5804be7

+ 1 - 0
CHANGES.md

@@ -13,6 +13,7 @@
 - Restrict editing of MUC messages to ones with the same XEP-0421 occupant ID
 - #2936: Fix documentation about enable_smacks option, which is true by default.
 - #2925: Fix missing disco-items in browser storage.
+- Fix MUC messages with a fallback body not rendering.
 
 ## 9.1.1 (2022-05-05)
 

+ 1 - 1
src/headless/plugins/muc/parsers.js

@@ -224,7 +224,7 @@ export async function parseMUCMessage (stanza, chatbox) {
         {
             from,
             'activities': getMEPActivities(stanza),
-            'body': stanza.querySelector('body')?.textContent?.trim(),
+            'body': stanza.querySelector(':scope > body')?.textContent?.trim(),
             'chat_state': getChatState(stanza),
             'from_muc': Strophe.getBareJidFromJid(from),
             'is_archived': isArchived(original_stanza),

+ 22 - 0
src/headless/plugins/muc/tests/messages.js

@@ -117,4 +117,26 @@ describe("A MUC message", function () {
         const model = _converse.chatboxes.get(muc_jid);
         expect(model.messages.length).toBe(0);
     }));
+
+    it('parses the correct body element',
+            mock.initConverse(['chatBoxesFetched'], {}, async function(_converse) {
+
+        const muc_jid = 'lounge@montague.lit';
+        const model = await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
+        const received_stanza = u.toStanza(`
+        <message to='${_converse.jid}' from='${muc_jid}/mallory' type='groupchat' id='${_converse.connection.getUniqueId()}' >
+            <reply xmlns='urn:xmpp:reply:0' id='${_converse.connection.getUniqueId()}' to='${_converse.jid}'/>
+            <fallback xmlns='urn:xmpp:feature-fallback:0' for='urn:xmpp:reply:0'>
+                <body start='0' end='10'/>
+            </fallback>
+            <active xmlns='http://jabber.org/protocol/chatstates'/>
+            <body>&gt; ping
+pong</body>
+            <request xmlns='urn:xmpp:receipts'/>
+        </message>
+    `);
+        await model.handleMessageStanza(received_stanza);
+        await u.waitUntil(() => model.messages.last());
+        expect(model.messages.last().get('body')).toBe('> ping\npong');
+    }));
 });