remove room from room list when leaving

This commit is contained in:
Bruno Windels 2021-05-05 16:54:38 +02:00
parent 89461bf69a
commit 644698aed7
3 changed files with 12 additions and 2 deletions

View file

@ -35,9 +35,8 @@ export class LeftPanelViewModel extends ViewModel {
} }
_mapTileViewModels(rooms, invites) { _mapTileViewModels(rooms, invites) {
const joinedRooms = rooms.filterValues(room => room.membership === "join");
// join is not commutative, invites will take precedence over rooms // 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; const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id;
let vm; let vm;
if (roomOrInvite.isInvite) { if (roomOrInvite.isInvite) {

View file

@ -54,6 +54,7 @@ export class Session {
this._sessionInfo = sessionInfo; this._sessionInfo = sessionInfo;
this._rooms = new ObservableMap(); this._rooms = new ObservableMap();
this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params); this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params);
this._archivedRooms = null;
this._invites = new ObservableMap(); this._invites = new ObservableMap();
this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params); this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params);
this._user = new User(sessionInfo.userId); this._user = new User(sessionInfo.userId);
@ -426,6 +427,14 @@ export class Session {
this._invites.remove(invite.id); 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) { async obtainSyncLock(syncResponse) {
const toDeviceEvents = syncResponse.to_device?.events; const toDeviceEvents = syncResponse.to_device?.events;
if (Array.isArray(toDeviceEvents) && toDeviceEvents.length) { if (Array.isArray(toDeviceEvents) && toDeviceEvents.length) {

View file

@ -295,6 +295,8 @@ export class Sync {
// so the room will be found if looking for it when the invite // so the room will be found if looking for it when the invite
// is removed // is removed
this._session.addRoomAfterSync(rs.room); this._session.addRoomAfterSync(rs.room);
} else if (rs.membership === "leave") {
this._session.archiveRoomAfterSync(rs.room);
} }
} }
// emit invite related events after txn has been closed // emit invite related events after txn has been closed