mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 00:41:31 +03:00
Adjust behaviour for the home space
This commit is contained in:
parent
1974d47e4e
commit
3e8863fc9a
2 changed files with 15 additions and 2 deletions
|
@ -118,7 +118,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
public async setActiveSpace(space: Room | null, contextSwitch = true) {
|
||||
if (space && !space.isSpaceRoom()) return;
|
||||
if (space === this.activeSpace) {
|
||||
const notificationState = this.getNotificationState(space ? space.roomId : HOME_SPACE);
|
||||
const notificationState = space
|
||||
? this.getNotificationState(space.roomId)
|
||||
: RoomNotificationStateStore.instance.globalState;
|
||||
|
||||
if (notificationState.count) {
|
||||
const roomId = notificationState.getRoomWithMaxNotifications();
|
||||
defaultDispatcher.dispatch({
|
||||
|
|
|
@ -16,6 +16,8 @@ limitations under the License.
|
|||
|
||||
import { NotificationColor } from "./NotificationColor";
|
||||
import { NotificationState } from "./NotificationState";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomNotificationState } from "./RoomNotificationState";
|
||||
|
||||
/**
|
||||
* Summarizes a number of states into a unique snapshot. To populate, call
|
||||
|
@ -25,11 +27,13 @@ import { NotificationState } from "./NotificationState";
|
|||
*/
|
||||
export class SummarizedNotificationState extends NotificationState {
|
||||
private totalStatesWithUnread = 0;
|
||||
unreadRooms: Room[];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._symbol = null;
|
||||
this._count = 0;
|
||||
this.unreadRooms = [];
|
||||
this._color = NotificationColor.None;
|
||||
}
|
||||
|
||||
|
@ -37,6 +41,11 @@ export class SummarizedNotificationState extends NotificationState {
|
|||
return this.totalStatesWithUnread;
|
||||
}
|
||||
|
||||
public getRoomWithMaxNotifications() {
|
||||
return this.unreadRooms.reduce((prev, curr) =>
|
||||
(prev._notificationCounts.total > curr._notificationCounts.total ? prev : curr)).roomId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -45,7 +54,7 @@ export class SummarizedNotificationState extends NotificationState {
|
|||
* @param includeSymbol If true, the notification state's symbol will be taken if one
|
||||
* is present.
|
||||
*/
|
||||
public add(other: NotificationState, includeSymbol = false) {
|
||||
public add(other: RoomNotificationState, includeSymbol = false) {
|
||||
if (other.symbol && includeSymbol) {
|
||||
this._symbol = other.symbol;
|
||||
}
|
||||
|
@ -56,6 +65,7 @@ export class SummarizedNotificationState extends NotificationState {
|
|||
this._color = other.color;
|
||||
}
|
||||
if (other.hasUnreadCount) {
|
||||
this.unreadRooms.push(other.room);
|
||||
this.totalStatesWithUnread++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue