From 616d701ebb9d9bee5b11720b9238704ec42c4bd4 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 21 Jun 2021 19:02:42 +0200 Subject: [PATCH] add test that redaction for non-sending event aborts it --- src/matrix/room/sending/SendQueue.js | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index 041b1aef..9d6af88e 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -39,7 +39,7 @@ export class SendQueue { const pendingEvent = new PendingEvent({ data, remove: () => this._removeEvent(pendingEvent), - emitUpdate: () => this._pendingEvents.update(pendingEvent), + emitUpdate: params => this._pendingEvents.update(pendingEvent, params), attachments }); return pendingEvent; @@ -326,7 +326,8 @@ export class SendQueue { import {HomeServer as MockHomeServer} from "../../../mocks/HomeServer.js"; import {createMockStorage} from "../../../mocks/Storage.js"; -import {NullLogger} from "../../../logging/NullLogger.js"; +import {ListObserver} from "../../../mocks/ListObserver.js"; +import {NullLogger, NullLogItem} from "../../../logging/NullLogger.js"; import {createEvent, withTextBody, withTxnId} from "../../../mocks/event.js"; import {poll} from "../../../mocks/poll.js"; @@ -362,6 +363,34 @@ export function tests() { const sendRequest2 = await poll(() => hs.requests.send[1]); sendRequest2.respond({event_id: event2.event_id}); await poll(() => !queue._isSending); + }, + "redaction of pending event that hasn't started sending yet aborts it": async assert => { + const queue = new SendQueue({ + roomId: "!abc", + storage: await createMockStorage(), + hsApi: new MockHomeServer().api + }); + // first, enqueue a message that will be attempted to send, but we don't respond + await queue.enqueueEvent("m.room.message", {body: "hello!"}, null, new NullLogItem()); + + const observer = new ListObserver(); + queue.pendingEvents.subscribe(observer); + await queue.enqueueEvent("m.room.message", {body: "...world"}, null, new NullLogItem()); + let txnId; + { + const {type, index, value} = await observer.next(); + assert.equal(type, "add"); + assert.equal(index, 1); + assert.equal(typeof value.txnId, "string"); + txnId = value.txnId; + } + await queue.enqueueRedaction(txnId, null, new NullLogItem()); + { + const {type, value, index} = await observer.next(); + assert.equal(type, "remove"); + assert.equal(index, 1); + assert.equal(txnId, value.txnId); + } } } }