Select the immediate body, not the one in fallback.

This commit is contained in:
Keith Maika 2022-08-12 09:21:24 -04:00 committed by JC Brand
parent fd9e41a917
commit 17e5804be7
3 changed files with 24 additions and 1 deletions

View File

@ -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)

View File

@ -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),

View File

@ -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');
}));
});