From 1e209b86139fc720c001dad3584a472d7d25f89b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 14:14:04 +0100 Subject: [PATCH] Prevent pending events being skipped when remote echo comes This fixes #241 --- src/matrix/room/sending/SendQueue.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index cccee083..5b0bf7f9 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -46,13 +46,26 @@ export class SendQueue { this._roomEncryption = roomEncryption; } + _nextPendingEvent(current) { + if (!current) { + return this._pendingEvents.get(0); + } else { + const idx = this._pendingEvents.indexOf(current); + if (idx !== -1) { + return this._pendingEvents.get(idx + 1); + } + return; + } + } + _sendLoop(log) { this._isSending = true; this._sendLoopLogItem = log.runDetached("send queue flush", async log => { + let pendingEvent; try { - for (let i = 0; i < this._pendingEvents.length; i += 1) { + // eslint-disable-next-line no-cond-assign + while (pendingEvent = this._nextPendingEvent(pendingEvent)) { await log.wrap("send event", async log => { - const pendingEvent = this._pendingEvents.get(i); log.set("queueIndex", pendingEvent.queueIndex); try { await this._sendEvent(pendingEvent, log);