From 00851df25cd47c4bd90b6a04ec9871a4865178f8 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 10 May 2019 16:33:49 +0100 Subject: [PATCH] Always add pending relation events to the timeline sets directly This special cases pending relation events to go directly to the timeline sets and ignores the `pendingEventOrdering` option. This feels a bit strange in the code, so we should revisit this choice when we stabilized relation support. --- src/models/event.js | 10 ++++++++++ src/models/room.js | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/models/event.js b/src/models/event.js index 76544b6da..ba5abf366 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -730,6 +730,16 @@ utils.extend(module.exports.MatrixEvent.prototype, { // successfully sent. this.status = null; }, + + /** + * Get whether the event is a relation event. + * @return {boolean} + */ + isRelation() { + const content = this.getContent(); + const relation = content && content["m.relates_to"]; + return relation && relation.rel_type && relation.event_id; + }, }); diff --git a/src/models/room.js b/src/models/room.js index e50edf07b..b0930f38b 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -1101,7 +1101,11 @@ Room.prototype.addPendingEvent = function(event, txnId) { this._txnToEvent[txnId] = event; - if (this._opts.pendingEventOrdering == "detached") { + // TODO: We currently ignore `pendingEventOrdering` for relation events. + // They are aggregated by the timeline set, and we want that to happen right + // away for easy local echo, but it complicates what should be a general + // code path by branching on the event type. + if (!event.isRelation() && this._opts.pendingEventOrdering == "detached") { if (this._pendingEventList.some((e) => e.status === EventStatus.NOT_SENT)) { console.warn("Setting event as NOT_SENT due to messages in the same state"); event.status = EventStatus.NOT_SENT;