From a6b31741c34b4ddd5bed3b54766678cade51f687 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 6 Dec 2021 15:50:31 +0000 Subject: [PATCH] Broken room list WIP --- src/domain/session/SessionViewModel.js | 2 +- .../session/leftpanel/LeftPanelViewModel.js | 38 ++++++++++--------- .../leftpanel/PlaceholderRoomTileViewModel.js | 3 +- src/matrix/Sync3.ts | 5 --- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index fdc96409..6fcad7a9 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -40,8 +40,8 @@ export class SessionViewModel extends ViewModel { this._leftPanelViewModel = this.track(new LeftPanelViewModel(this.childOptions({ invites: this._sessionContainer.session.invites, rooms: this._sessionContainer.session.rooms, + sync: this._sessionContainer.sync, compareFn: this._sessionContainer.sync.compare.bind(this._sessionContainer.sync), - includeRoomFn: this._sessionContainer.sync.includeRoom.bind(this._sessionContainer.sync), }))); this._settingsViewModel = null; this._roomViewModelObservable = null; diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index b0fd60c0..9713d71b 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -19,7 +19,9 @@ import {ViewModel} from "../../ViewModel.js"; import {RoomTileViewModel} from "./RoomTileViewModel.js"; import {InviteTileViewModel} from "./InviteTileViewModel.js"; import {RoomFilter} from "./RoomFilter.js"; +import { ConcatList, MappedList } from "../../../observable/index.js"; import {FilteredMap} from "../../../observable/map/FilteredMap.js"; +import {Sync3ObservableList} from "../../../matrix/Sync3ObservableList"; import {ApplyMap} from "../../../observable/map/ApplyMap.js"; import {addPanelIfNeeded} from "../../navigation/index.js"; import { PlaceholderRoomTileViewModel } from "./PlaceholderRoomTileViewModel.js"; @@ -27,14 +29,13 @@ import { PlaceholderRoomTileViewModel } from "./PlaceholderRoomTileViewModel.js" export class LeftPanelViewModel extends ViewModel { constructor(options) { super(options); - const {rooms, invites, compareFn, includeRoomFn} = options; - this._tileViewModelsMap = this._mapTileViewModels(rooms, invites); - this._tileViewModelsSlidingWindow = new FilteredMap(this._tileViewModelsMap, (r, roomId) => { - const include = includeRoomFn(roomId); - return include; - }); - this._tileViewModelsFilterMap = new ApplyMap(this._tileViewModelsSlidingWindow); - this._tileViewModels = this._tileViewModelsFilterMap.sortValues((a, b) => a.compare(b)); + const {rooms, invites, compareFn, sync} = options; + const sync3List = new Sync3ObservableList(sync, rooms); + const list = new ConcatList(invites.sortValues((a,b) => a.compare(b)), sync3List); + this._tileViewModelsMap = this._mapTileViewModels(list); + this._tileViewModelsFilterMap = new ApplyMap(this._tileViewModelsMap); + console.log(this._tileViewModelsMap); + this._tileViewModels = this._tileViewModelsFilterMap;//.sortValues((a, b) => a.compare(b)); this._currentTileVM = null; this._setupNavigation(); this._closeUrl = this.urlCreator.urlForSegment("session"); @@ -42,14 +43,13 @@ export class LeftPanelViewModel extends ViewModel { this._compareFn = compareFn; } - _mapTileViewModels(rooms, invites) { - // join is not commutative, invites will take precedence over rooms - return invites.join(rooms).mapValues((roomOrInvite, emitChange) => { + _mapTileViewModels(list) { + return new MappedList(list, (roomOrInvite, emitChange) => { let vm; - if (roomOrInvite.isInvite) { + if (roomOrInvite === null) { + vm = new PlaceholderRoomTileViewModel(this.childOptions({room: null, emitChange})); + } else if (roomOrInvite.isInvite) { vm = new InviteTileViewModel(this.childOptions({invite: roomOrInvite, emitChange})); - } else if (roomOrInvite.isPlaceholder) { - vm = new PlaceholderRoomTileViewModel(this.childOptions({room: roomOrInvite, emitChange})); } else { vm = new RoomTileViewModel(this.childOptions({ room: roomOrInvite, @@ -57,10 +57,12 @@ export class LeftPanelViewModel extends ViewModel { emitChange, })); } - const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; - if (isOpen) { - vm.open(); - this._updateCurrentVM(vm); + if (roomOrInvite) { + const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; + if (isOpen) { + vm.open(); + this._updateCurrentVM(vm); + } } return vm; }); diff --git a/src/domain/session/leftpanel/PlaceholderRoomTileViewModel.js b/src/domain/session/leftpanel/PlaceholderRoomTileViewModel.js index b4ae62a5..e67d21c8 100644 --- a/src/domain/session/leftpanel/PlaceholderRoomTileViewModel.js +++ b/src/domain/session/leftpanel/PlaceholderRoomTileViewModel.js @@ -37,6 +37,7 @@ export class PlaceholderRoomTileViewModel extends BaseTileViewModel { compare(other) { // TODO: factor this out with the compare(other) of the room tile as it does this check as well. + // TODO _room is null if (other._room.index !== undefined) { return this._room.index > other._room.index ? 1 : -1; } @@ -44,7 +45,7 @@ export class PlaceholderRoomTileViewModel extends BaseTileViewModel { } get name() { - return "Placeholder " + this._room.index; + return "Placeholder"; } get avatarLetter() { diff --git a/src/matrix/Sync3.ts b/src/matrix/Sync3.ts index 542ea2cd..f475e4a0 100644 --- a/src/matrix/Sync3.ts +++ b/src/matrix/Sync3.ts @@ -177,11 +177,6 @@ export class Sync3 { return roomID; } - // TODO REMOVE - includeRoom(roomId: string): boolean { - return this.roomIdToRoomIndex[roomId] !== undefined; - } - // TODO REMOVE compare(roomIdA: string, roomIdB: string): number { if (roomIdA === roomIdB) {