From 644698aed76791c68dc377df1ac8deb5b4de58a4 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 5 May 2021 16:54:38 +0200 Subject: [PATCH] remove room from room list when leaving --- src/domain/session/leftpanel/LeftPanelViewModel.js | 3 +-- src/matrix/Session.js | 9 +++++++++ src/matrix/Sync.js | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index dd9c89ac..a1a577a9 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -35,9 +35,8 @@ export class LeftPanelViewModel extends ViewModel { } _mapTileViewModels(rooms, invites) { - const joinedRooms = rooms.filterValues(room => room.membership === "join"); // join is not commutative, invites will take precedence over rooms - return invites.join(joinedRooms).mapValues((roomOrInvite, emitChange) => { + return invites.join(rooms).mapValues((roomOrInvite, emitChange) => { const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; let vm; if (roomOrInvite.isInvite) { diff --git a/src/matrix/Session.js b/src/matrix/Session.js index db44a463..93088df3 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -54,6 +54,7 @@ export class Session { this._sessionInfo = sessionInfo; this._rooms = new ObservableMap(); this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params); + this._archivedRooms = null; this._invites = new ObservableMap(); this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params); this._user = new User(sessionInfo.userId); @@ -426,6 +427,14 @@ export class Session { this._invites.remove(invite.id); } + /** @internal */ + archiveRoomAfterSync(room) { + this._rooms.remove(room.id); + if (this._archivedRooms) { + this._archivedRooms.add(room.id, room); + } + } + async obtainSyncLock(syncResponse) { const toDeviceEvents = syncResponse.to_device?.events; if (Array.isArray(toDeviceEvents) && toDeviceEvents.length) { diff --git a/src/matrix/Sync.js b/src/matrix/Sync.js index e888ab01..f459297d 100644 --- a/src/matrix/Sync.js +++ b/src/matrix/Sync.js @@ -295,6 +295,8 @@ export class Sync { // so the room will be found if looking for it when the invite // is removed this._session.addRoomAfterSync(rs.room); + } else if (rs.membership === "leave") { + this._session.archiveRoomAfterSync(rs.room); } } // emit invite related events after txn has been closed