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; }