diff --git a/lib/client.js b/lib/client.js index c4aee6fe2..9fc843730 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1792,7 +1792,8 @@ MatrixClient.prototype.paginateEventTimeline = function(eventTimeline, opts) { ).then(function(res) { var token = res.end; var matrixEvents = utils.map(res.chunk, self.getEventMapper()); - room.addEventsToTimeline(matrixEvents, backwards, eventTimeline, token); + eventTimeline.getTimelineSet() + .addEventsToTimeline(matrixEvents, backwards, eventTimeline, token); // if we've hit the end of the timeline, we need to stop trying to // paginate. We need to keep the 'forwards' token though, to make sure diff --git a/lib/models/room.js b/lib/models/room.js index 61c809366..1af9cd18a 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -389,12 +389,10 @@ Room.prototype.getCanonicalAlias = function() { */ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline, timeline, paginationToken) { - for (var i = 0; i < this._timelineSets.length; i++) { - this._timelineSets[i].addEventsToTimeline( - events, toStartOfTimeline, - timeline, paginationToken - ); - } + timeline.getTimelineSet().addEventsToTimeline( + events, toStartOfTimeline, + timeline, paginationToken + ); }; /** diff --git a/lib/sync.js b/lib/sync.js index f4823c81c..27b17dc98 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -808,8 +808,12 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) { accountDataEvents.forEach(function(e) { client.emit("event", e); }); }); - // update the notification timeline, if appropriate - if (this._notifEvents.length) { + // update the notification timeline, if appropriate. + // we only do this for live events, as otherwise we can't order them sanely + // in the timeline relative to ones paginated in by /notifications. + // XXX: we could fix this by making EventTimeline support chronological + // ordering... but it doesn't, right now. + if (syncToken && this._notifEvents.length) { this._notifEvents.sort(function(a, b) { return a.getTs() - b.getTs(); });