From c46c330efb93b550d0907123dcec1851f9bb83e5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 24 Jun 2021 13:14:54 +0200 Subject: [PATCH] prevent duplicate redactions from distorting reaction local echo --- src/matrix/room/sending/SendQueue.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index 90d6a988..8bc40d61 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -226,6 +226,14 @@ export class SendQueue { } async enqueueRedaction(eventIdOrTxnId, reason, log) { + const existingRedaction = this._pendingEvents.array.find(pe => { + return pe.eventType === REDACTION_TYPE && + (pe.relatedTxnId === eventIdOrTxnId || pe.relatedEventId === eventIdOrTxnId); + }); + if (existingRedaction) { + log.set("already_redacting", true); + return; + } let relatedTxnId; let relatedEventId; if (isTxnId(eventIdOrTxnId)) { @@ -393,6 +401,18 @@ export function tests() { assert.equal(index, 1); assert.equal(txnId, value.txnId); } + }, + "duplicate redaction gets dropped": async assert => { + const queue = new SendQueue({ + roomId: "!abc", + storage: await createMockStorage(), + hsApi: new MockHomeServer().api + }); + assert.equal(queue.pendingEvents.length, 0); + await queue.enqueueRedaction("!event", null, new NullLogItem()); + assert.equal(queue.pendingEvents.length, 1); + await queue.enqueueRedaction("!event", null, new NullLogItem()); + assert.equal(queue.pendingEvents.length, 1); } } }