Navigate to room with maximum notifications when clicked on already selected space

pull/21833/head
Jaiwanth 2021-05-05 12:38:44 +05:30
parent 2bf931b9d3
commit 73b9ad41da
2 changed files with 18 additions and 2 deletions

View File

@ -120,8 +120,19 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
* should not be done when the space switch is done implicitly due to another event like switching room.
*/
public async setActiveSpace(space: Room | null, contextSwitch = true) {
if (space === this.activeSpace || (space && !space?.isSpaceRoom())) return;
if (space && !space?.isSpaceRoom()) return;
if (space === this.activeSpace) {
const notificationState = this.getNotificationState(space.roomId);
if (notificationState.count) {
const roomId = notificationState.getRoomWithMaxNotifications();
defaultDispatcher.dispatch({
action: "view_room",
room_id: roomId,
context_switch: true,
});
}
return;
}
this._activeSpace = space;
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);

View File

@ -53,6 +53,11 @@ export class SpaceNotificationState extends NotificationState {
this.calculateTotalState();
}
public getRoomWithMaxNotifications() {
return this.rooms.reduce((prev, curr) =>
(prev._notificationCounts.total > curr._notificationCounts.total ? prev : curr)).roomId;
}
public destroy() {
super.destroy();
for (const state of Object.values(this.states)) {