From a0599dedf0b39e66c3ee49f4e772e3380667cd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 21 Jan 2020 15:45:29 +0100 Subject: [PATCH] EventIndex: Use the newly exposed TimelineWindow methods. --- src/indexing/EventIndex.js | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/indexing/EventIndex.js b/src/indexing/EventIndex.js index cb77d92c27..c081440233 100644 --- a/src/indexing/EventIndex.js +++ b/src/indexing/EventIndex.js @@ -494,35 +494,12 @@ export default class EventIndex { } paginateTimelineWindow(room, timelineWindow, direction, limit) { - let tl; - - // TODO this is from the js-sdk, this should probably be exposed to - // us through the js-sdk. - const moveWindowCap = (titmelineWindow, timeline, direction, limit) => { - const count = (direction === EventTimeline.BACKWARDS) ? - timeline.retreat(limit) : timeline.advance(limit); - - if (count) { - timelineWindow._eventCount += count; - const excess = timelineWindow._eventCount - timelineWindow._windowLimit; - - if (excess > 0) { - timelineWindow.unpaginate(3, direction !== EventTimeline.BACKWARDS); - } - return true; - } - - return false; - }; - - // TODO these private fields should be somehow exposed in the js-sdk. - if (direction == EventTimeline.BACKWARDS) tl = timelineWindow._start; - else if (direction == EventTimeline.FORWARDS) tl = timelineWindow._end; + const tl = timelineWindow.getTimelineIndex(direction); if (!tl) return Promise.resolve(false); if (tl.pendingPaginate) return tl.pendingPaginate; - if (moveWindowCap(timelineWindow, tl, direction, limit)) { + if (timelineWindow.extend(direction, limit)) { return Promise.resolve(true); } @@ -532,8 +509,8 @@ export default class EventIndex { const ret = await this.populateFileTimeline(timelineSet, timeline.timeline, room, limit, token, direction); - moveWindowCap(timelineWindow, timeline, direction, limit); timeline.pendingPaginate = null; + timelineWindow.extend(direction, limit); return ret; };