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

Commit 81c01a0

Browse files
author
Germain Souquet
committed
Update RoomNotificationState on threads update
1 parent e688929 commit 81c01a0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/stores/notifications/RoomNotificationState.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ import { EffectiveMembership, getEffectiveMembership } from "../../utils/members
2525
import { readReceiptChangeIsFor } from "../../utils/read-receipts";
2626
import * as RoomNotifs from '../../RoomNotifs';
2727
import * as Unread from '../../Unread';
28-
import { NotificationState } from "./NotificationState";
28+
import { NotificationState, NotificationStateEvents } from "./NotificationState";
2929
import { getUnsentMessages } from "../../components/structures/RoomStatusBar";
30+
import { ThreadsRoomNotificationState } from "./ThreadsRoomNotificationState";
3031

3132
export class RoomNotificationState extends NotificationState implements IDestroyable {
32-
constructor(public readonly room: Room) {
33+
constructor(public readonly room: Room, private readonly threadsState?: ThreadsRoomNotificationState) {
3334
super();
3435
this.room.on(RoomEvent.Receipt, this.handleReadReceipt);
3536
this.room.on(RoomEvent.Timeline, this.handleRoomEventUpdate);
3637
this.room.on(RoomEvent.Redaction, this.handleRoomEventUpdate);
3738
this.room.on(RoomEvent.MyMembership, this.handleMembershipUpdate);
3839
this.room.on(RoomEvent.LocalEchoUpdated, this.handleLocalEchoUpdated);
40+
if (threadsState) {
41+
threadsState.on(NotificationStateEvents.Update, this.handleThreadsUpdate);
42+
}
3943
MatrixClientPeg.get().on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
4044
MatrixClientPeg.get().on(ClientEvent.AccountData, this.handleAccountDataUpdate);
4145
this.updateNotificationState();
@@ -52,12 +56,19 @@ export class RoomNotificationState extends NotificationState implements IDestroy
5256
this.room.removeListener(RoomEvent.Redaction, this.handleRoomEventUpdate);
5357
this.room.removeListener(RoomEvent.MyMembership, this.handleMembershipUpdate);
5458
this.room.removeListener(RoomEvent.LocalEchoUpdated, this.handleLocalEchoUpdated);
59+
if (this.threadsState) {
60+
this.threadsState.removeListener(NotificationStateEvents.Update, this.handleThreadsUpdate);
61+
}
5562
if (MatrixClientPeg.get()) {
5663
MatrixClientPeg.get().removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
5764
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, this.handleAccountDataUpdate);
5865
}
5966
}
6067

68+
private handleThreadsUpdate = () => {
69+
this.updateNotificationState();
70+
};
71+
6172
private handleLocalEchoUpdated = () => {
6273
this.updateNotificationState();
6374
};

src/stores/notifications/RoomNotificationStateStore.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ export class RoomNotificationStateStore extends AsyncStoreWithClient<IState> {
8282
*/
8383
public getRoomState(room: Room): RoomNotificationState {
8484
if (!this.roomMap.has(room)) {
85-
this.roomMap.set(room, new RoomNotificationState(room));
8685
// Not very elegant, but that way we ensure that we start tracking
8786
// threads notification at the same time at rooms.
8887
// There are multiple entry points, and it's unclear which one gets
8988
// called first
90-
this.roomThreadsMap.set(room, new ThreadsRoomNotificationState(room));
89+
const threadState = new ThreadsRoomNotificationState(room);
90+
this.roomThreadsMap.set(room, threadState);
91+
this.roomMap.set(room, new RoomNotificationState(room, threadState));
9192
}
9293
return this.roomMap.get(room);
9394
}

0 commit comments

Comments
 (0)