2
0
Эх сурвалжийг харах

Also use the message id when matching retractions

JC Brand 5 сар өмнө
parent
commit
84e102424b

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

@@ -121,7 +121,6 @@ export async function parseMessage (stanza) {
             'is_marker': !!marker,
             'is_unstyled': !!sizzle(`unstyled[xmlns="${Strophe.NS.STYLING}"]`, stanza).length,
             'marker_id': marker && marker.getAttribute('id'),
-            'msgid': stanza.getAttribute('id') || original_stanza.getAttribute('id'),
             'nick': contact?.attributes?.nickname,
             'receipt_id': getReceiptId(stanza),
             'received': new Date().toISOString(),

+ 0 - 1
src/headless/plugins/disco/api.js

@@ -359,7 +359,6 @@ export default {
                 return api.disco.features.has(feature, jid);
             } catch (e) {
                 log.error(e);
-                debugger;
                 return false;
             }
         },

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

@@ -267,7 +267,6 @@ export async function parseMUCMessage(original_stanza, chatbox) {
                 'is_marker': !!marker,
                 'is_unstyled': !!sizzle(`message > unstyled[xmlns="${Strophe.NS.STYLING}"]`, stanza).length,
                 'marker_id': marker && marker.getAttribute('id'),
-                'msgid': stanza.getAttribute('id') || original_stanza.getAttribute('id'),
                 'nick': Strophe.unescapeNode(Strophe.getResourceFromJid(from)),
                 'occupant_id': getOccupantID(stanza, chatbox),
                 'receipt_id': getReceiptId(stanza),

+ 10 - 6
src/headless/shared/model-with-messages.js

@@ -846,13 +846,17 @@ export default function ModelWithMessages(BaseModel) {
             if (attrs.retracted) {
                 if (attrs.is_tombstone) return false;
 
-                const message = this.messages.findWhere({ origin_id: attrs.retracted_id, from: attrs.from });
-                if (!message) {
-                    attrs['dangling_retraction'] = true;
-                    await this.createMessage(attrs);
-                    return true;
+                for (const m of this.messages.models) {
+                    if (m.get('from') !== attrs.from) continue;
+                    if (m.get('origin_id') === attrs.retracted_id ||
+                            m.get('msgid') === attrs.retracted_id) {
+                        m.save(pick(attrs, RETRACTION_ATTRIBUTES));
+                        return true;
+                    }
                 }
-                message.save(pick(attrs, RETRACTION_ATTRIBUTES));
+
+                attrs['dangling_retraction'] = true;
+                await this.createMessage(attrs);
                 return true;
             } else {
                 // Check if we have dangling retraction

+ 10 - 8
src/headless/shared/parsers.js

@@ -96,14 +96,21 @@ export async function parseErrorStanza(stanza) {
  * @returns {Object}
  */
 export function getStanzaIDs (stanza, original_stanza) {
-    const attrs = {};
-    // Store generic stanza ids
+    // Generic stanza ids
     const sids = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza);
     const sid_attrs = sids.reduce((acc, s) => {
         acc[`stanza_id ${s.getAttribute('by')}`] = s.getAttribute('id');
         return acc;
     }, {});
-    Object.assign(attrs, sid_attrs);
+
+    // Origin id
+    const origin_id = sizzle(`origin-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop()?.getAttribute('id');
+
+    const attrs = {
+        origin_id,
+        msgid: stanza.getAttribute('id') || original_stanza.getAttribute('id'),
+        ...sid_attrs,
+    };
 
     // Store the archive id
     const result = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop();
@@ -113,11 +120,6 @@ export function getStanzaIDs (stanza, original_stanza) {
         attrs[`stanza_id ${by_jid}`] = result.getAttribute('id');
     }
 
-    // Store the origin id
-    const origin_id = sizzle(`origin-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
-    if (origin_id) {
-        attrs['origin_id'] = origin_id.getAttribute('id');
-    }
     return attrs;
 }
 

+ 5 - 7
src/plugins/chatview/tests/retractions.js

@@ -224,7 +224,6 @@ describe('A message retraction', function () {
                         <forwarded xmlns="urn:xmpp:forward:0">
                             <delay xmlns="urn:xmpp:delay" stamp="2019-09-20T23:01:15Z"/>
                             <message type="chat" from="${contact_jid}" to="${_converse.bare_jid}" id="message-id-0">
-                                <origin-id xmlns="urn:xmpp:sid:0" id="origin-id-0"/>
                                 <body>😊</body>
                             </message>
                         </forwarded>
@@ -238,7 +237,6 @@ describe('A message retraction', function () {
                         <forwarded xmlns="urn:xmpp:forward:0">
                             <delay xmlns="urn:xmpp:delay" stamp="2019-09-20T23:08:25Z"/>
                             <message type="chat" from="${contact_jid}" to="${_converse.bare_jid}" id="message-id-1">
-                                <origin-id xmlns="urn:xmpp:sid:0" id="origin-id-1"/>
                                 <retracted id="retract-message-1" stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:1"/>
                             </message>
                         </forwarded>
@@ -253,9 +251,9 @@ describe('A message retraction', function () {
                         <forwarded xmlns="urn:xmpp:forward:0">
                             <delay xmlns="urn:xmpp:delay" stamp="2019-09-20T23:08:25Z"/>
                             <message from="${contact_jid}" to="${_converse.bare_jid}" id="retract-message-1">
-                                <apply-to id="origin-id-1" xmlns="urn:xmpp:fasten:0">
-                                    <retract xmlns="urn:xmpp:message-retract:0"/>
-                                </apply-to>
+                                <retract id="message-id-1" xmlns='urn:xmpp:message-retract:1'/>
+                                <fallback xmlns="urn:xmpp:fallback:0" for='urn:xmpp:message-retract:1'/>
+                                <body>/me retracted a previous message, but it's unsupported by your client.</body>
                             </message>
                         </forwarded>
                     </result>
@@ -285,8 +283,8 @@ describe('A message retraction', function () {
             expect(await view.model.handleRetraction.calls.all()[2].returnValue).toBe(true);
             await u.waitUntil(() => view.querySelectorAll('.chat-msg').length === 2);
             expect(view.querySelectorAll('.chat-msg--retracted').length).toBe(1);
-            const el = view.querySelector('.chat-msg--retracted .chat-msg__message div');
-            expect(el.textContent.trim()).toBe('Mercutio has removed this message');
+            const el = view.querySelector('.chat-msg--retracted .chat-msg__message .retraction');
+            expect(el.firstElementChild.textContent.trim()).toBe('Mercutio has removed a message');
             expect(u.hasClass('chat-msg--followup', el.parentElement)).toBe(false);
         })
     );

+ 0 - 1
src/shared/chat/templates/message.js

@@ -32,7 +32,6 @@ export default (el) => {
     const username = el.model.getDisplayName();
 
     const is_action = is_me_message || is_retracted;
-    debugger;
     const should_show_header = !is_action && !is_followup;
     const should_show_avatar = el.shouldShowAvatar() && should_show_header;