mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-15 23:01:30 +03:00
Navigate to room with maximum notifications when clicked on already selected space
This commit is contained in:
parent
2bf931b9d3
commit
73b9ad41da
2 changed files with 18 additions and 2 deletions
|
@ -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 = []);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue