Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Navigate to the first room with notifications when clicked on space notification dot #5974

Merged
merged 15 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/stores/SpaceStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +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;
jaiwanth-v marked this conversation as resolved.
Show resolved Hide resolved
if (space === this.activeSpace) {
const notificationState = this.getNotificationState(space ? space.roomId : HOME_SPACE);
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);
Expand Down
5 changes: 5 additions & 0 deletions src/stores/notifications/SpaceNotificationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down