From c9a79bf32e86dae7fb060851b76276c9468d3e49 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 8 Nov 2018 16:46:03 -0700 Subject: [PATCH] Prevent messages from being sent if other messages have failed to send Fixes https://github.com/vector-im/riot-web/issues/5408 --- src/client.js | 7 +++++++ src/models/room.js | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/client.js b/src/client.js index d8f0d67ca..64bbf5082 100644 --- a/src/client.js +++ b/src/client.js @@ -1186,6 +1186,13 @@ MatrixClient.prototype.sendEvent = function(roomId, eventType, content, txnId, room.addPendingEvent(localEvent, txnId); } + // addPendingEvent can change the state to NOT_SENT if it believes + // that there's other events that have failed. We won't bother to + // try sending the event if the state has changed as such. + if (localEvent.status === EventStatus.NOT_SENT) { + return Promise.reject(new Error("Event blocked by other events not yet sent")); + } + return _sendEvent(this, room, localEvent, callback); }; diff --git a/src/models/room.js b/src/models/room.js index 4b685c878..6f05b48aa 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -999,6 +999,10 @@ Room.prototype.addPendingEvent = function(event, txnId) { this._txnToEvent[txnId] = event; if (this._opts.pendingEventOrdering == "detached") { + if (this._pendingEventList.some(e => e.status === EventStatus.NOT_SENT)) { + console.warn("Setting new event's status as " + EventStatus.NOT_SENT + " due to other similar messages"); + event.status = EventStatus.NOT_SENT; + } this._pendingEventList.push(event); } else { for (let i = 0; i < this._timelineSets.length; i++) {