From 1b21c8f7328478a56262a9e5dc2dbcbfe1f947c1 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 30 Jun 2021 10:53:46 +0530 Subject: [PATCH] Remove unreadRoomId from summarized notification state --- src/components/views/rooms/RoomList.tsx | 2 +- src/stores/SpaceStore.tsx | 34 ++++++++++++++----- .../notifications/SpaceNotificationState.ts | 2 +- .../SummarizedNotificationState.ts | 6 ---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index eb50224a60..6511c12372 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -68,7 +68,7 @@ interface IState { suggestedRooms: ISuggestedRoom[]; } -const TAG_ORDER: TagID[] = [ +export const TAG_ORDER: TagID[] = [ DefaultTagID.Invite, DefaultTagID.Favourite, DefaultTagID.DM, diff --git a/src/stores/SpaceStore.tsx b/src/stores/SpaceStore.tsx index c8144902c9..105d98a8e0 100644 --- a/src/stores/SpaceStore.tsx +++ b/src/stores/SpaceStore.tsx @@ -38,6 +38,7 @@ import { arrayHasDiff } from "../utils/arrays"; import { objectDiff } from "../utils/objects"; import { arrayHasOrderChange } from "../utils/arrays"; import { reorderLexicographically } from "../utils/stringOrderField"; +import { TAG_ORDER } from "../components/views/rooms/RoomList"; type SpaceKey = string | symbol; @@ -128,16 +129,33 @@ export class SpaceStoreClass extends AsyncStoreWithClient { if (space && !space.isSpaceRoom()) return; if (space !== this.activeSpace) await this.setActiveSpace(space); - const notificationState = space - ? this.getNotificationState(space.roomId) - : RoomNotificationStateStore.instance.globalState; - - if (notificationState.count) { + if (space) { + const notificationState = this.getNotificationState(space.roomId) const roomId = notificationState.getFirstRoomWithNotifications(); defaultDispatcher.dispatch({ - action: "view_room", - room_id: roomId, - context_switch: true, + action: "view_room", + room_id: roomId, + context_switch: true, + }); + } else { + const lists = RoomListStore.instance.unfilteredLists; + TAG_ORDER.every(t => { + const listRooms = lists[t]; + const unreadRoom = listRooms.find((r: Room)=> { + if (this.showInHomeSpace(r)) { + const state = RoomNotificationStateStore.instance.getRoomState(r); + return state.isUnread; + } + }); + if (unreadRoom) { + defaultDispatcher.dispatch({ + action: "view_room", + room_id: unreadRoom.roomId, + context_switch: true, + }); + return false; + } + return true; }); } } diff --git a/src/stores/notifications/SpaceNotificationState.ts b/src/stores/notifications/SpaceNotificationState.ts index cdb9f2d06a..4c0a582f3f 100644 --- a/src/stores/notifications/SpaceNotificationState.ts +++ b/src/stores/notifications/SpaceNotificationState.ts @@ -54,7 +54,7 @@ export class SpaceNotificationState extends NotificationState { } public getFirstRoomWithNotifications() { - return this.rooms.find((room) => room._notificationCounts.total > 0).roomId; + return this.rooms.find((room) => room.getUnreadNotificationCount() > 0).roomId; } public destroy() { diff --git a/src/stores/notifications/SummarizedNotificationState.ts b/src/stores/notifications/SummarizedNotificationState.ts index ec6db1015d..6b69e1d470 100644 --- a/src/stores/notifications/SummarizedNotificationState.ts +++ b/src/stores/notifications/SummarizedNotificationState.ts @@ -32,7 +32,6 @@ export class SummarizedNotificationState extends NotificationState { super(); this._symbol = null; this._count = 0; - this.unreadRoomId = null; this._color = NotificationColor.None; } @@ -40,10 +39,6 @@ export class SummarizedNotificationState extends NotificationState { return this.totalStatesWithUnread; } - public getFirstRoomWithNotifications() { - return this.unreadRoomId; - } - /** * Append a notification state to this snapshot, taking the loudest NotificationColor * of the two. By default this will not adopt the symbol of the other notification @@ -63,7 +58,6 @@ export class SummarizedNotificationState extends NotificationState { this._color = other.color; } if (other.hasUnreadCount) { - this.unreadRoomId = !this.unreadRoomId ? other.room.roomId : this.unreadRoomId; this.totalStatesWithUnread++; } }