prevent key collisions between rooms and invites before creating tile vm
This commit is contained in:
parent
ec0de15da6
commit
2e9ddf9c2c
2 changed files with 13 additions and 12 deletions
|
@ -35,23 +35,20 @@ export class LeftPanelViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
_mapTileViewModels(rooms, invites) {
|
_mapTileViewModels(rooms, invites) {
|
||||||
const roomTileViewModels = rooms.mapValues((room, emitChange) => {
|
// join is not commutative, invites will take precedence over rooms
|
||||||
const isOpen = this.navigation.path.get("room")?.value === room.id;
|
return invites.join(rooms).mapValues((roomOrInvite, emitChange) => {
|
||||||
const vm = new RoomTileViewModel(this.childOptions({isOpen, room, 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) {
|
if (isOpen) {
|
||||||
this._updateCurrentVM(vm);
|
this._updateCurrentVM(vm);
|
||||||
}
|
}
|
||||||
return 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) {
|
_updateCurrentVM(vm) {
|
||||||
|
|
|
@ -35,6 +35,10 @@ export class Invite extends EventEmitter {
|
||||||
this._rejected = false;
|
this._rejected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isInvite() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
get id() {
|
get id() {
|
||||||
return this._roomId;
|
return this._roomId;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue