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

Commit

Permalink
Remove unreadRoomId from summarized notification state
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiwanth-v committed Jun 30, 2021
1 parent 746b11b commit 1b21c8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/views/rooms/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface IState {
suggestedRooms: ISuggestedRoom[];
}

const TAG_ORDER: TagID[] = [
export const TAG_ORDER: TagID[] = [
DefaultTagID.Invite,
DefaultTagID.Favourite,
DefaultTagID.DM,
Expand Down
34 changes: 26 additions & 8 deletions src/stores/SpaceStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -128,16 +129,33 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
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;
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/notifications/SpaceNotificationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 0 additions & 6 deletions src/stores/notifications/SummarizedNotificationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ export class SummarizedNotificationState extends NotificationState {
super();
this._symbol = null;
this._count = 0;
this.unreadRoomId = null;
this._color = NotificationColor.None;
}

public get numUnreadStates(): number {
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
Expand All @@ -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++;
}
}
Expand Down

0 comments on commit 1b21c8f

Please sign in to comment.