Skip to content
Snippets Groups Projects
Commit f8d233df authored by Luke Barnard's avatar Luke Barnard Committed by GitHub
Browse files

Merge branch 'develop' into luke/fix-timeline-window-load-syncish

parents e6e2f0b3 17cc1284
No related branches found
No related tags found
No related merge requests found
...@@ -95,10 +95,30 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) { ...@@ -95,10 +95,30 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
const self = this; const self = this;
initialWindowSize = initialWindowSize || 20; initialWindowSize = initialWindowSize || 20;
// given an EventTimeline, and an event index within it, initialise our // given an EventTimeline, find the event we were looking for, and initialise our
// fields so that the event in question is in the middle of the window. // fields so that the event in question is in the middle of the window.
const initFields = function(timeline, eventIndex) { const initFields = function(timeline) {
const endIndex = Math.min(timeline.getEvents().length, let eventIndex;
const events = timeline.getEvents();
if (!initialEventId) {
// we were looking for the live timeline: initialise to the end
eventIndex = events.length;
} else {
for (let i = 0; i < events.length; i++) {
if (events[i].getId() == initialEventId) {
eventIndex = i;
break;
}
}
if (eventIndex === undefined) {
throw new Error("getEventTimeline result didn't include requested event");
}
}
const endIndex = Math.min(events.length,
eventIndex + Math.ceil(initialWindowSize / 2)); eventIndex + Math.ceil(initialWindowSize / 2));
const startIndex = Math.max(0, endIndex - initialWindowSize); const startIndex = Math.max(0, endIndex - initialWindowSize);
self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex()); self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex());
...@@ -133,9 +153,8 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) { ...@@ -133,9 +153,8 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
throw new Error("getEventTimeline result didn't include requested event"); throw new Error("getEventTimeline result didn't include requested event");
}); });
} else { } else {
// start with the most recent events
const tl = this._timelineSet.getLiveTimeline(); const tl = this._timelineSet.getLiveTimeline();
initFields(tl, tl.getEvents().length); initFields(tl);
return q(); return q();
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment