Skip to content

Commit

Permalink
Also use the message id when matching retractions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Feb 7, 2025
1 parent 147be37 commit 84e1024
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/headless/plugins/chat/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion src/headless/plugins/disco/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ export default {
return api.disco.features.has(feature, jid);
} catch (e) {
log.error(e);
debugger;
return false;
}
},
Expand Down
1 change: 0 additions & 1 deletion src/headless/plugins/muc/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 10 additions & 6 deletions src/headless/shared/model-with-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions src/headless/shared/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down
12 changes: 5 additions & 7 deletions src/plugins/chatview/tests/retractions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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);
})
);
Expand Down
1 change: 0 additions & 1 deletion src/shared/chat/templates/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 84e1024

Please sign in to comment.