From 2e9ddf9c2c86e8f5119f305dd995a7fafc3cd95c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 22 Apr 2021 17:22:47 +0200 Subject: [PATCH] prevent key collisions between rooms and invites before creating tile vm --- .../session/leftpanel/LeftPanelViewModel.js | 21 ++++++++----------- src/matrix/room/Invite.js | 4 ++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index c9a8b436..a1a577a9 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -35,23 +35,20 @@ export class LeftPanelViewModel extends ViewModel { } _mapTileViewModels(rooms, invites) { - const roomTileViewModels = rooms.mapValues((room, emitChange) => { - const isOpen = this.navigation.path.get("room")?.value === room.id; - const vm = new RoomTileViewModel(this.childOptions({isOpen, room, emitChange})); + // join is not commutative, invites will take precedence over rooms + return invites.join(rooms).mapValues((roomOrInvite, emitChange) => { + const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; + let vm; + if (roomOrInvite.isInvite) { + vm = new InviteTileViewModel(this.childOptions({isOpen, invite: roomOrInvite, emitChange})); + } else { + vm = new RoomTileViewModel(this.childOptions({isOpen, room: roomOrInvite, emitChange})); + } if (isOpen) { this._updateCurrentVM(vm); } return vm; }); - const inviteTileViewModels = invites.mapValues((invite, emitChange) => { - const isOpen = this.navigation.path.get("room")?.value === invite.id; - const vm = new InviteTileViewModel(this.childOptions({isOpen, invite, emitChange})); - if (isOpen) { - this._updateCurrentVM(vm); - } - return vm; - }); - return roomTileViewModels.join(inviteTileViewModels); } _updateCurrentVM(vm) { diff --git a/src/matrix/room/Invite.js b/src/matrix/room/Invite.js index f9547828..db6306d6 100644 --- a/src/matrix/room/Invite.js +++ b/src/matrix/room/Invite.js @@ -35,6 +35,10 @@ export class Invite extends EventEmitter { this._rejected = false; } + get isInvite() { + return true; + } + get id() { return this._roomId; }