diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index 8811af4c..9e37a05e 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -30,6 +30,7 @@ export class LeftPanelViewModel extends ViewModel { constructor(options) { super(options); const {rooms, invites, compareFn, sync} = options; + this._sync = sync; const sync3List = new Sync3ObservableList(sync, rooms); const list = new ConcatList(invites.sortValues((a,b) => a.compare(b)), sync3List); this._tileViewModelsMap = this._mapTileViewModels(list); @@ -151,8 +152,7 @@ export class LeftPanelViewModel extends ViewModel { } } - // TODO: used in sync v3 loadRoomRange(range) { - + this._sync.loadRange(range.start, range.end); } } diff --git a/src/matrix/Sync3.ts b/src/matrix/Sync3.ts index f475e4a0..ea108c29 100644 --- a/src/matrix/Sync3.ts +++ b/src/matrix/Sync3.ts @@ -135,6 +135,33 @@ export class Sync3 { this.totalRooms = 0; } + loadRange(start, end) { + let range = [start, end]; + if (end < this.ranges[0][1]) { + // asked to load a range we are already loading, ignore + // E.g [0-20] and [5-15] + return; + } + // Somewhat elaborate bounds checking: + // - Ensure we start above the first range, bumping the start index if necessary. + // - Ensure bumping the start didn't cause overlap on ranges, bumping the end if necessary. + if (start < this.ranges[0][1]) { + // overlapping range e.g 0-20 and 15-30, so bump up this range to one above the first range + start = this.ranges[0][1] + 1; + } + if (start >= end) { // E.g [20,20] or [25,20] + end += 1; + } + if (this.ranges.length === 1) { + this.ranges.push([]); + } + this.ranges[1][0] = start; + this.ranges[1][1] = end; + console.log("new ranges: ", JSON.stringify(this.ranges), this.roomIndexToRoomId); + // interrupt the sync request to send up the new ranges + this.currentRequest?.abort(); + } + // Start syncing. Probably call this at startup once you have an access_token. // If we're already syncing, this does nothing. start(): void {