From 48d1bc31583d04449e3912ce47510f204c52001c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 26 Jan 2016 11:15:46 +0000 Subject: [PATCH] Fix incompatibility with peeking. The peek code needs to make sure it sets the pagination token /after/ adding the events to the timeline, otherwise it will get reset when the events are added. --- lib/sync.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/sync.js b/lib/sync.js index e944145cb..1ba77e6cc 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -216,10 +216,6 @@ SyncApi.prototype.peek = function(roomId) { response.messages.chunk, client.getEventMapper() ); - if (response.messages.start) { - peekRoom.oldState.paginationToken = response.messages.start; - } - // set the state of the room to as it was after the timeline executes peekRoom.oldState.setStateEvents(oldStateEvents); peekRoom.currentState.setStateEvents(stateEvents); @@ -230,6 +226,12 @@ SyncApi.prototype.peek = function(roomId) { // roll backwards to diverge old state: peekRoom.addEventsToTimeline(messages.reverse(), true); + // set the pagination token. Make sure this happens after adding + // events to the timeline, otherwise it will get reset. + if (response.messages.start) { + peekRoom.oldState.paginationToken = response.messages.start; + } + client.store.storeRoom(peekRoom); client.emit("Room", peekRoom);