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

Commit 20dfe86

Browse files
committed
Cleanup pre MSC3773 thread unread notif logic
1 parent e9d7232 commit 20dfe86

File tree

8 files changed

+23
-365
lines changed

8 files changed

+23
-365
lines changed

src/components/views/right_panel/RoomHeaderButtons.tsx

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import React from "react";
2222
import classNames from "classnames";
2323
import { NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room";
2424
import { ThreadEvent } from "matrix-js-sdk/src/models/thread";
25-
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
2625

2726
import { _t } from "../../../languageHandler";
2827
import HeaderButton from "./HeaderButton";
@@ -39,12 +38,9 @@ import {
3938
UPDATE_STATUS_INDICATOR,
4039
} from "../../../stores/notifications/RoomNotificationStateStore";
4140
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
42-
import { ThreadsRoomNotificationState } from "../../../stores/notifications/ThreadsRoomNotificationState";
4341
import { SummarizedNotificationState } from "../../../stores/notifications/SummarizedNotificationState";
44-
import { NotificationStateEvents } from "../../../stores/notifications/NotificationState";
4542
import PosthogTrackers from "../../../PosthogTrackers";
4643
import { ButtonEvent } from "../elements/AccessibleButton";
47-
import { MatrixClientPeg } from "../../../MatrixClientPeg";
4844
import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread";
4945

5046
const ROOM_INFO_PHASES = [
@@ -133,74 +129,48 @@ interface IProps {
133129

134130
export default class RoomHeaderButtons extends HeaderButtons<IProps> {
135131
private static readonly THREAD_PHASES = [RightPanelPhases.ThreadPanel, RightPanelPhases.ThreadView];
136-
private threadNotificationState: ThreadsRoomNotificationState | null;
137132
private globalNotificationState: SummarizedNotificationState;
138133

139-
private get supportsThreadNotifications(): boolean {
140-
const client = MatrixClientPeg.get();
141-
return client.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported;
142-
}
143-
144134
public constructor(props: IProps) {
145135
super(props, HeaderKind.Room);
146-
147-
this.threadNotificationState =
148-
!this.supportsThreadNotifications && this.props.room
149-
? RoomNotificationStateStore.instance.getThreadsRoomState(this.props.room)
150-
: null;
151136
this.globalNotificationState = RoomNotificationStateStore.instance.globalState;
152137
}
153138

154139
public componentDidMount(): void {
155140
super.componentDidMount();
156-
if (!this.supportsThreadNotifications) {
157-
this.threadNotificationState?.on(NotificationStateEvents.Update, this.onNotificationUpdate);
158-
} else {
159-
// Notification badge may change if the notification counts from the
160-
// server change, if a new thread is created or updated, or if a
161-
// receipt is sent in the thread.
162-
this.props.room?.on(RoomEvent.UnreadNotifications, this.onNotificationUpdate);
163-
this.props.room?.on(RoomEvent.Receipt, this.onNotificationUpdate);
164-
this.props.room?.on(RoomEvent.Timeline, this.onNotificationUpdate);
165-
this.props.room?.on(RoomEvent.Redaction, this.onNotificationUpdate);
166-
this.props.room?.on(RoomEvent.LocalEchoUpdated, this.onNotificationUpdate);
167-
this.props.room?.on(RoomEvent.MyMembership, this.onNotificationUpdate);
168-
this.props.room?.on(ThreadEvent.New, this.onNotificationUpdate);
169-
this.props.room?.on(ThreadEvent.Update, this.onNotificationUpdate);
170-
}
141+
// Notification badge may change if the notification counts from the
142+
// server change, if a new thread is created or updated, or if a
143+
// receipt is sent in the thread.
144+
this.props.room?.on(RoomEvent.UnreadNotifications, this.onNotificationUpdate);
145+
this.props.room?.on(RoomEvent.Receipt, this.onNotificationUpdate);
146+
this.props.room?.on(RoomEvent.Timeline, this.onNotificationUpdate);
147+
this.props.room?.on(RoomEvent.Redaction, this.onNotificationUpdate);
148+
this.props.room?.on(RoomEvent.LocalEchoUpdated, this.onNotificationUpdate);
149+
this.props.room?.on(RoomEvent.MyMembership, this.onNotificationUpdate);
150+
this.props.room?.on(ThreadEvent.New, this.onNotificationUpdate);
151+
this.props.room?.on(ThreadEvent.Update, this.onNotificationUpdate);
171152
this.onNotificationUpdate();
172153
RoomNotificationStateStore.instance.on(UPDATE_STATUS_INDICATOR, this.onUpdateStatus);
173154
}
174155

175156
public componentWillUnmount(): void {
176157
super.componentWillUnmount();
177-
if (!this.supportsThreadNotifications) {
178-
this.threadNotificationState?.off(NotificationStateEvents.Update, this.onNotificationUpdate);
179-
} else {
180-
this.props.room?.off(RoomEvent.UnreadNotifications, this.onNotificationUpdate);
181-
this.props.room?.off(RoomEvent.Receipt, this.onNotificationUpdate);
182-
this.props.room?.off(RoomEvent.Timeline, this.onNotificationUpdate);
183-
this.props.room?.off(RoomEvent.Redaction, this.onNotificationUpdate);
184-
this.props.room?.off(RoomEvent.LocalEchoUpdated, this.onNotificationUpdate);
185-
this.props.room?.off(RoomEvent.MyMembership, this.onNotificationUpdate);
186-
this.props.room?.off(ThreadEvent.New, this.onNotificationUpdate);
187-
this.props.room?.off(ThreadEvent.Update, this.onNotificationUpdate);
188-
}
158+
this.props.room?.off(RoomEvent.UnreadNotifications, this.onNotificationUpdate);
159+
this.props.room?.off(RoomEvent.Receipt, this.onNotificationUpdate);
160+
this.props.room?.off(RoomEvent.Timeline, this.onNotificationUpdate);
161+
this.props.room?.off(RoomEvent.Redaction, this.onNotificationUpdate);
162+
this.props.room?.off(RoomEvent.LocalEchoUpdated, this.onNotificationUpdate);
163+
this.props.room?.off(RoomEvent.MyMembership, this.onNotificationUpdate);
164+
this.props.room?.off(ThreadEvent.New, this.onNotificationUpdate);
165+
this.props.room?.off(ThreadEvent.Update, this.onNotificationUpdate);
189166
RoomNotificationStateStore.instance.off(UPDATE_STATUS_INDICATOR, this.onUpdateStatus);
190167
}
191168

192169
private onNotificationUpdate = (): void => {
193-
let threadNotificationColor: NotificationColor;
194-
if (!this.supportsThreadNotifications) {
195-
threadNotificationColor = this.threadNotificationState?.color ?? NotificationColor.None;
196-
} else {
197-
threadNotificationColor = this.notificationColor;
198-
}
199-
200170
// console.log
201171
// XXX: why don't we read from this.state.threadNotificationColor in the render methods?
202172
this.setState({
203-
threadNotificationColor,
173+
threadNotificationColor: this.notificationColor,
204174
});
205175
};
206176

src/components/views/rooms/EventTile.tsx

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models
2727
import { CallErrorCode } from "matrix-js-sdk/src/webrtc/call";
2828
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
2929
import { UserTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning";
30-
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
3130

3231
import ReplyChain from "../elements/ReplyChain";
3332
import { _t } from "../../../languageHandler";
@@ -62,10 +61,6 @@ import SettingsStore from "../../../settings/SettingsStore";
6261
import { MessagePreviewStore } from "../../../stores/room-list/MessagePreviewStore";
6362
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
6463
import { MediaEventHelper } from "../../../utils/MediaEventHelper";
65-
import { ThreadNotificationState } from "../../../stores/notifications/ThreadNotificationState";
66-
import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore";
67-
import { NotificationStateEvents } from "../../../stores/notifications/NotificationState";
68-
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
6964
import { ButtonEvent } from "../elements/AccessibleButton";
7065
import { copyPlaintext, getSelectedText } from "../../../utils/strings";
7166
import { DecryptionFailureTracker } from "../../../DecryptionFailureTracker";
@@ -254,7 +249,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
254249
private isListeningForReceipts: boolean;
255250
private tile = React.createRef<IEventTileType>();
256251
private replyChain = React.createRef<ReplyChain>();
257-
private threadState: ThreadNotificationState;
258252

259253
public readonly ref = createRef<HTMLElement>();
260254

@@ -389,10 +383,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
389383

390384
if (SettingsStore.getValue("feature_threadenabled")) {
391385
this.props.mxEvent.on(ThreadEvent.Update, this.updateThread);
392-
393-
if (this.thread && !this.supportsThreadNotifications) {
394-
this.setupNotificationListener(this.thread);
395-
}
396386
}
397387

398388
client.decryptEventIfNeeded(this.props.mxEvent);
@@ -403,47 +393,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
403393
this.verifyEvent();
404394
}
405395

406-
private get supportsThreadNotifications(): boolean {
407-
const client = MatrixClientPeg.get();
408-
return client.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported;
409-
}
410-
411-
private setupNotificationListener(thread: Thread): void {
412-
if (!this.supportsThreadNotifications) {
413-
const notifications = RoomNotificationStateStore.instance.getThreadsRoomState(thread.room);
414-
this.threadState = notifications.getThreadRoomState(thread);
415-
this.threadState.on(NotificationStateEvents.Update, this.onThreadStateUpdate);
416-
this.onThreadStateUpdate();
417-
}
418-
}
419-
420-
private onThreadStateUpdate = (): void => {
421-
if (!this.supportsThreadNotifications) {
422-
let threadNotification = null;
423-
switch (this.threadState?.color) {
424-
case NotificationColor.Grey:
425-
threadNotification = NotificationCountType.Total;
426-
break;
427-
case NotificationColor.Red:
428-
threadNotification = NotificationCountType.Highlight;
429-
break;
430-
}
431-
432-
this.setState({
433-
threadNotification,
434-
});
435-
}
436-
};
437-
438396
private updateThread = (thread: Thread): void => {
439-
if (thread !== this.state.thread && !this.supportsThreadNotifications) {
440-
if (this.threadState) {
441-
this.threadState.off(NotificationStateEvents.Update, this.onThreadStateUpdate);
442-
}
443-
444-
this.setupNotificationListener(thread);
445-
}
446-
447397
this.setState({ thread });
448398
};
449399

@@ -473,7 +423,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
473423
if (SettingsStore.getValue("feature_threadenabled")) {
474424
this.props.mxEvent.off(ThreadEvent.Update, this.updateThread);
475425
}
476-
this.threadState?.off(NotificationStateEvents.Update, this.onThreadStateUpdate);
477426
}
478427

479428
public componentDidUpdate(prevProps: Readonly<EventTileProps>, prevState: Readonly<IState>): void {
@@ -1280,9 +1229,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
12801229
"data-shape": this.context.timelineRenderingType,
12811230
"data-self": isOwnEvent,
12821231
"data-has-reply": !!replyChain,
1283-
"data-notification": !this.supportsThreadNotifications
1284-
? this.state.threadNotification
1285-
: undefined,
12861232
"onMouseEnter": () => this.setState({ hover: true }),
12871233
"onMouseLeave": () => this.setState({ hover: false }),
12881234
"onClick": (ev: MouseEvent) => {

src/stores/notifications/RoomNotificationState.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ import { EffectiveMembership, getEffectiveMembership } from "../../utils/members
2626
import { readReceiptChangeIsFor } from "../../utils/read-receipts";
2727
import * as RoomNotifs from "../../RoomNotifs";
2828
import * as Unread from "../../Unread";
29-
import { NotificationState, NotificationStateEvents } from "./NotificationState";
29+
import { NotificationState } from "./NotificationState";
3030
import { getUnsentMessages } from "../../components/structures/RoomStatusBar";
31-
import { ThreadsRoomNotificationState } from "./ThreadsRoomNotificationState";
3231

3332
export class RoomNotificationState extends NotificationState implements IDestroyable {
34-
public constructor(public readonly room: Room, private readonly threadsState?: ThreadsRoomNotificationState) {
33+
public constructor(public readonly room: Room) {
3534
super();
3635
const cli = this.room.client;
3736
this.room.on(RoomEvent.Receipt, this.handleReadReceipt);
@@ -41,9 +40,6 @@ export class RoomNotificationState extends NotificationState implements IDestroy
4140
this.room.on(RoomEvent.Redaction, this.handleRoomEventUpdate);
4241

4342
this.room.on(RoomEvent.UnreadNotifications, this.handleNotificationCountUpdate); // for server-sent counts
44-
if (cli.canSupport.get(Feature.ThreadUnreadNotifications) === ServerSupport.Unsupported) {
45-
this.threadsState?.on(NotificationStateEvents.Update, this.handleThreadsUpdate);
46-
}
4743
cli.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
4844
cli.on(ClientEvent.AccountData, this.handleAccountDataUpdate);
4945
this.updateNotificationState();
@@ -61,19 +57,10 @@ export class RoomNotificationState extends NotificationState implements IDestroy
6157
this.room.removeListener(RoomEvent.LocalEchoUpdated, this.handleLocalEchoUpdated);
6258
this.room.removeListener(RoomEvent.Timeline, this.handleRoomEventUpdate);
6359
this.room.removeListener(RoomEvent.Redaction, this.handleRoomEventUpdate);
64-
if (cli.canSupport.get(Feature.ThreadUnreadNotifications) === ServerSupport.Unsupported) {
65-
this.room.removeListener(RoomEvent.UnreadNotifications, this.handleNotificationCountUpdate);
66-
} else if (this.threadsState) {
67-
this.threadsState.removeListener(NotificationStateEvents.Update, this.handleThreadsUpdate);
68-
}
6960
cli.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
7061
cli.removeListener(ClientEvent.AccountData, this.handleAccountDataUpdate);
7162
}
7263

73-
private handleThreadsUpdate = (): void => {
74-
this.updateNotificationState();
75-
};
76-
7764
private handleLocalEchoUpdated = (): void => {
7865
this.updateNotificationState();
7966
};

src/stores/notifications/RoomNotificationStateStore.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
import { Room } from "matrix-js-sdk/src/models/room";
1818
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
1919
import { ClientEvent } from "matrix-js-sdk/src/client";
20-
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
2120

2221
import { ActionPayload } from "../../dispatcher/payloads";
2322
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
@@ -26,7 +25,6 @@ import { DefaultTagID, TagID } from "../room-list/models";
2625
import { FetchRoomFn, ListNotificationState } from "./ListNotificationState";
2726
import { RoomNotificationState } from "./RoomNotificationState";
2827
import { SummarizedNotificationState } from "./SummarizedNotificationState";
29-
import { ThreadsRoomNotificationState } from "./ThreadsRoomNotificationState";
3028
import { VisibilityProvider } from "../room-list/filters/VisibilityProvider";
3129
import { PosthogAnalytics } from "../../PosthogAnalytics";
3230

@@ -42,7 +40,6 @@ export class RoomNotificationStateStore extends AsyncStoreWithClient<IState> {
4240
})();
4341
private roomMap = new Map<Room, RoomNotificationState>();
4442

45-
private roomThreadsMap: Map<Room, ThreadsRoomNotificationState> = new Map<Room, ThreadsRoomNotificationState>();
4643
private listMap = new Map<TagID, ListNotificationState>();
4744
private _globalState = new SummarizedNotificationState();
4845

@@ -87,31 +84,11 @@ export class RoomNotificationStateStore extends AsyncStoreWithClient<IState> {
8784
*/
8885
public getRoomState(room: Room): RoomNotificationState {
8986
if (!this.roomMap.has(room)) {
90-
let threadState;
91-
if (room.client.canSupport.get(Feature.ThreadUnreadNotifications) === ServerSupport.Unsupported) {
92-
// Not very elegant, but that way we ensure that we start tracking
93-
// threads notification at the same time at rooms.
94-
// There are multiple entry points, and it's unclear which one gets
95-
// called first
96-
const threadState = new ThreadsRoomNotificationState(room);
97-
this.roomThreadsMap.set(room, threadState);
98-
}
99-
this.roomMap.set(room, new RoomNotificationState(room, threadState));
87+
this.roomMap.set(room, new RoomNotificationState(room));
10088
}
10189
return this.roomMap.get(room);
10290
}
10391

104-
public getThreadsRoomState(room: Room): ThreadsRoomNotificationState | null {
105-
if (room.client.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported) {
106-
return null;
107-
}
108-
109-
if (!this.roomThreadsMap.has(room)) {
110-
this.roomThreadsMap.set(room, new ThreadsRoomNotificationState(room));
111-
}
112-
return this.roomThreadsMap.get(room);
113-
}
114-
11592
public static get instance(): RoomNotificationStateStore {
11693
return RoomNotificationStateStore.internalInstance;
11794
}

src/stores/notifications/ThreadNotificationState.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)