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

Commit 158d436

Browse files
authored
Merge pull request #5974 from jaiwanth-v/spaces-jump-to-room
Navigate to the first room with notifications when clicked on space notification dot
2 parents 05353d0 + 517e895 commit 158d436

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

src/components/views/rooms/RoomList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface IState {
6868
suggestedRooms: ISuggestedRoom[];
6969
}
7070

71-
const TAG_ORDER: TagID[] = [
71+
export const TAG_ORDER: TagID[] = [
7272
DefaultTagID.Invite,
7373
DefaultTagID.Favourite,
7474
DefaultTagID.DM,

src/components/views/spaces/SpacePanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ const SpaceButton: React.FC<IButtonProps> = ({
7676
let notifBadge;
7777
if (notificationState) {
7878
notifBadge = <div className="mx_SpacePanel_badgeContainer">
79-
<NotificationBadge forceCount={false} notification={notificationState} />
79+
<NotificationBadge
80+
onClick={() => SpaceStore.instance.setActiveRoomInSpace(space)}
81+
forceCount={false}
82+
notification={notificationState}
83+
/>
8084
</div>;
8185
}
8286

src/components/views/spaces/SpaceTreeLevel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
401401
let notifBadge;
402402
if (notificationState) {
403403
notifBadge = <div className="mx_SpacePanel_badgeContainer">
404-
<NotificationBadge forceCount={false} notification={notificationState} />
404+
<NotificationBadge
405+
onClick={() => SpaceStore.instance.setActiveRoomInSpace(space)}
406+
forceCount={false}
407+
notification={notificationState}
408+
/>
405409
</div>;
406410
}
407411

src/stores/SpaceStore.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { arrayHasDiff } from "../utils/arrays";
3838
import { objectDiff } from "../utils/objects";
3939
import { arrayHasOrderChange } from "../utils/arrays";
4040
import { reorderLexicographically } from "../utils/stringOrderField";
41+
import { TAG_ORDER } from "../components/views/rooms/RoomList";
4142

4243
type SpaceKey = string | symbol;
4344

@@ -130,6 +131,41 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
130131
return this._suggestedRooms;
131132
}
132133

134+
public async setActiveRoomInSpace(space: Room | null) {
135+
if (space && !space.isSpaceRoom()) return;
136+
if (space !== this.activeSpace) await this.setActiveSpace(space);
137+
138+
if (space) {
139+
const notificationState = this.getNotificationState(space.roomId);
140+
const roomId = notificationState.getFirstRoomWithNotifications();
141+
defaultDispatcher.dispatch({
142+
action: "view_room",
143+
room_id: roomId,
144+
context_switch: true,
145+
});
146+
} else {
147+
const lists = RoomListStore.instance.unfilteredLists;
148+
for (let i = 0; i < TAG_ORDER.length; i++) {
149+
const t = TAG_ORDER[i];
150+
const listRooms = lists[t];
151+
const unreadRoom = listRooms.find((r: Room) => {
152+
if (this.showInHomeSpace(r)) {
153+
const state = RoomNotificationStateStore.instance.getRoomState(r);
154+
return state.isUnread;
155+
}
156+
});
157+
if (unreadRoom) {
158+
defaultDispatcher.dispatch({
159+
action: "view_room",
160+
room_id: unreadRoom.roomId,
161+
context_switch: true,
162+
});
163+
break;
164+
}
165+
}
166+
}
167+
}
168+
133169
/**
134170
* Sets the active space, updates room list filters,
135171
* optionally switches the user's room back to where they were when they last viewed that space.
@@ -138,7 +174,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
138174
* should not be done when the space switch is done implicitly due to another event like switching room.
139175
*/
140176
public async setActiveSpace(space: Room | null, contextSwitch = true) {
141-
if (space === this.activeSpace || (space && !space?.isSpaceRoom())) return;
177+
if (space === this.activeSpace || (space && !space.isSpaceRoom())) return;
142178

143179
this._activeSpace = space;
144180
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);

src/stores/notifications/SpaceNotificationState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class SpaceNotificationState extends NotificationState {
5353
this.calculateTotalState();
5454
}
5555

56+
public getFirstRoomWithNotifications() {
57+
return this.rooms.find((room) => room.getUnreadNotificationCount() > 0).roomId;
58+
}
59+
5660
public destroy() {
5761
super.destroy();
5862
for (const state of Object.values(this.states)) {

0 commit comments

Comments
 (0)