diff --git a/spec/unit/room.spec.js b/spec/unit/room.spec.js index a809dd6ee..b257ec637 100644 --- a/spec/unit/room.spec.js +++ b/spec/unit/room.spec.js @@ -104,7 +104,7 @@ describe("Room", function() { user_ids: [userA], }, }); - room.addLiveEvents([typing]); + room.addEphemeralEvents([typing]); expect(room.currentState.setTypingEvent).toHaveBeenCalledWith(typing); }); diff --git a/src/models/room.js b/src/models/room.js index 7f5c031a3..ef7c34c8d 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -1420,18 +1420,23 @@ Room.prototype.addLiveEvents = function(events, duplicateStrategy) { } for (i = 0; i < events.length; i++) { - if (events[i].getType() === "m.typing") { - this.currentState.setTypingEvent(events[i]); - } else if (events[i].getType() === "m.receipt") { - this.addReceipt(events[i]); - } - // N.B. account_data is added directly by /sync to avoid - // having to maintain an event.isAccountData() here - else { - // TODO: We should have a filter to say "only add state event - // types X Y Z to the timeline". - this._addLiveEvent(events[i], duplicateStrategy); - } + // TODO: We should have a filter to say "only add state event + // types X Y Z to the timeline". + this._addLiveEvent(events[i], duplicateStrategy); + } +}; + +/** + * Adds/handles ephemeral events such as typing notifications and read receipts. + * @param {MatrixEvent[]} events A list of events to process + */ +Room.prototype.addEphemeralEvents = function(events) { + for (const event of events) { + if (event.getType() === 'm.typing') { + this.currentState.setTypingEvent(event); + } else if (event.getType() === 'm.receipt') { + this.addReceipt(event); + } // else ignore - life is too short for us to care about these events } }; diff --git a/src/sync.js b/src/sync.js index 106e4e2fc..12775903e 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1245,10 +1245,8 @@ SyncApi.prototype._processSyncResponse = async function( room.setSummary(joinObj.summary); } - // XXX: should we be adding ephemeralEvents to the timeline? - // It feels like that for symmetry with room.addAccountData() - // there should be a room.addEphemeralEvents() or similar. - room.addLiveEvents(ephemeralEvents); + // we deliberately don't add ephemeral events to the timeline + room.addEphemeralEvents(ephemeralEvents); // we deliberately don't add accountData to the timeline room.addAccountData(accountDataEvents);