Skip to content

Commit

Permalink
Prevent messages from being sent if other messages have failed to send
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Nov 8, 2018
1 parent eafba9c commit c9a79bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 4 additions & 0 deletions src/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit c9a79bf

Please sign in to comment.