Procházet zdrojové kódy

Don't strip the resource from the `from` value for incoming messages.

This caused an issue with matching duplicates where we send a message
and the full JID is stored, and then for the incoming MAM message we
have only the bare JID, so the matching failed.
JC Brand před 4 měsíci
rodič
revize
ceceb66fa9

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

@@ -114,7 +114,7 @@ export async function parseMessage (stanza) {
             is_server_message,
             'body': stanza.querySelector('body')?.textContent?.trim(),
             'chat_state': getChatState(stanza),
-            'from': Strophe.getBareJidFromJid(stanza.getAttribute('from')),
+            'from': stanza.getAttribute('from'),
             'is_carbon': isCarbon(original_stanza),
             'is_delayed': !!delay,
             'is_markable': !!sizzle(`markable[xmlns="${Strophe.NS.MARKERS}"]`, stanza).length,

+ 1 - 3
src/plugins/omemo/api.js

@@ -56,9 +56,7 @@ export default {
         },
 
         /**
-         * The "bundle" namespace groups methods relevant to the user's
-         * OMEMO bundle.
-         *
+         * The "bundle" namespace groups methods relevant to the user's OMEMO bundle.
          * @namespace _converse.api.omemo.bundle
          * @memberOf _converse.api.omemo
          */

+ 10 - 7
src/plugins/omemo/tests/omemo.js

@@ -266,7 +266,8 @@ describe("The OMEMO module", function() {
         const my_devicelist = _converse.state.devicelists.get({'jid': _converse.bare_jid});
         expect(my_devicelist.devices.length).toBe(2);
 
-        const stanza = stx`<iq from="${contact_jid}"
+        const stanza = stx`
+            <iq from="${contact_jid}"
                 id="${iq_stanza.getAttribute('id')}"
                 to="${_converse.api.connection.get().jid}"
                 xmlns="jabber:server"
@@ -292,7 +293,8 @@ describe("The OMEMO module", function() {
 
         // Test reception of an encrypted carbon message
         const obj = await omemo.encryptMessage('This is an encrypted carbon message from another device of mine')
-        const carbon = stx`<message xmlns="jabber:client" to="romeo@montague.lit/orchard" from="romeo@montague.lit" type="chat">
+        const carbon = stx`
+            <message xmlns="jabber:client" to="romeo@montague.lit/orchard" from="romeo@montague.lit" type="chat">
                 <sent xmlns="urn:xmpp:carbons:2">
                     <forwarded xmlns="urn:xmpp:forward:0">
                     <message xmlns="jabber:client"
@@ -334,11 +336,12 @@ describe("The OMEMO module", function() {
         // The message received is a prekey message, so missing prekeys are
         // generated and a new bundle published.
         iq_stanza = await u.waitUntil(() => mock.bundleHasBeenPublished(_converse));
-        const result_iq = $iq({
-            'from': _converse.bare_jid,
-            'id': iq_stanza.getAttribute('id'),
-            'to': _converse.bare_jid,
-            'type': 'result'});
+        const result_iq = stx`
+            <iq xmlns="jabber:client"
+                from="${_converse.bare_jid}"
+                id="${iq_stanza.getAttribute('id')}"
+                to="${_converse.bare_jid}"
+                type="result"/>`;
         _converse.api.connection.get()._dataRecv(mock.createRequest(result_iq));
 
         await new Promise(resolve => view.model.messages.once('rendered', resolve));

+ 12 - 1
src/plugins/omemo/utils.js

@@ -425,10 +425,21 @@ export function getSessionCipher(jid, id) {
 }
 
 /**
+ * We use the bare, real (i.e. non-MUC) JID as encrypted session identifier.
  * @param {MUCMessageAttributes|MessageAttributes} attrs
  */
 function getJIDForDecryption(attrs) {
-    const from_jid = "from_muc" in attrs ? attrs.from_real_jid : attrs.from;
+    let from_jid;
+    if (attrs.sender === 'me') {
+        from_jid = _converse.session.get('bare_jid');
+    } else if (attrs.contact_jid) {
+        from_jid = attrs.contact_jid;
+    } else if ('from_real_jid' in attrs) {
+        from_jid = attrs.from_real_jid;
+    } else {
+        from_jid = attrs.from;
+    }
+
     if (!from_jid) {
         Object.assign(attrs, {
             error_text: __(