Hook threads notification state to UI (#7298)

This commit is contained in:
Germain 2021-12-13 14:05:42 +00:00 committed by GitHub
parent 55eda7314b
commit ce570ab827
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 139 additions and 28 deletions

View file

@ -40,20 +40,26 @@ export class ThreadNotificationState extends NotificationState implements IDestr
this.thread.off(ThreadEvent.ViewThread, this.resetThreadNotification);
}
private handleNewThreadReply(thread: Thread, event: MatrixEvent) {
private handleNewThreadReply = (thread: Thread, event: MatrixEvent) => {
const client = MatrixClientPeg.get();
const isOwn = client.getUserId() === event.getSender();
if (!isOwn) {
const myUserId = client.getUserId();
const isOwn = myUserId === event.getSender();
const readReceipt = this.room.getReadReceiptForUserId(myUserId);
if (!isOwn && !readReceipt || event.getTs() >= readReceipt.data.ts) {
const actions = client.getPushActionsForEvent(event, true);
const color = !!actions.tweaks.highlight
? NotificationColor.Red
: NotificationColor.Grey;
if (actions?.tweaks) {
const color = !!actions.tweaks.highlight
? NotificationColor.Red
: NotificationColor.Grey;
this.updateNotificationState(color);
this.updateNotificationState(color);
}
}
}
};
private resetThreadNotification = (): void => {
this.updateNotificationState(NotificationColor.None);

View file

@ -23,7 +23,7 @@ import { ThreadNotificationState } from "./ThreadNotificationState";
import { NotificationColor } from "./NotificationColor";
export class ThreadsRoomNotificationState extends NotificationState implements IDestroyable {
private threadsState = new Map<Thread, ThreadNotificationState>();
public readonly threadsState = new Map<Thread, ThreadNotificationState>();
protected _symbol = null;
protected _count = 0;
@ -31,6 +31,11 @@ export class ThreadsRoomNotificationState extends NotificationState implements I
constructor(public readonly room: Room) {
super();
if (this.room?.threads) {
for (const [, thread] of this.room.threads) {
this.onNewThread(thread);
}
}
this.room.on(ThreadEvent.New, this.onNewThread);
}