501d493ca4
Default = Participating: thread replies notify only when you've posted in the thread or are @mentioned; per-thread override to All / Mentions-only / Mute via a bell menu in the thread panel header. Modes sync across devices in io.lotus.thread_notifications account data (pruned on write: left rooms, >180d, cap 200/room). Muted threads: no notifications/sounds, chip badge suppressed (+BellMute glyph), and their counts are subtracted from the room's sidebar badge (client-side; clamped ≥0). Also fixes the thread notification path itself: thread replies are now owned by exactly ONE handler (room-level ThreadEvent.NewReply via a new useRoomsListener hook, with per-thread dedupe, panel-aware focus suppression, and per-thread OS tag coalescing) — the existing RoomEvent.Timeline handlers in the notifier and the unread binder are explicitly thread-guarded, eliminating the previously un-gated/double path. Room badges now also refresh live on RoomEvent.UnreadNotifications (surgical per-room PUT; fixes thread-badge lag). Pure decision core shouldNotifyThreadReply (13-case matrix) + prune + unread subtraction: +32 tests (648 total). E2EE caveat documented: mentions-only may under-notify pre-decryption (same class as the existing path). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { atom, useSetAtom } from 'jotai';
|
|
import { ClientEvent, MatrixClient, MatrixEvent } from 'matrix-js-sdk';
|
|
import { useEffect } from 'react';
|
|
import { AccountDataEvent } from '../../types/matrix/accountData';
|
|
import { ThreadNotificationsContent } from '../utils/threadNotifications';
|
|
|
|
// Holds the parsed `io.lotus.thread_notifications` account data. Seeded and
|
|
// kept in sync by `useBindThreadNotificationsAtom`.
|
|
export const threadNotificationsAtom = atom<ThreadNotificationsContent>({});
|
|
|
|
const readContent = (mx: MatrixClient): ThreadNotificationsContent =>
|
|
((mx as any).getAccountData(AccountDataEvent.LotusThreadNotifications)?.getContent() as
|
|
| ThreadNotificationsContent
|
|
| undefined) ?? {};
|
|
|
|
export const useBindThreadNotificationsAtom = (
|
|
mx: MatrixClient,
|
|
threadNotifications: typeof threadNotificationsAtom,
|
|
) => {
|
|
const setContent = useSetAtom(threadNotifications);
|
|
|
|
useEffect(() => {
|
|
setContent(readContent(mx));
|
|
|
|
const handleAccountData = (event: MatrixEvent) => {
|
|
if (event.getType() === AccountDataEvent.LotusThreadNotifications) {
|
|
setContent(event.getContent<ThreadNotificationsContent>() ?? {});
|
|
}
|
|
};
|
|
|
|
mx.on(ClientEvent.AccountData, handleAccountData);
|
|
return () => {
|
|
mx.removeListener(ClientEvent.AccountData, handleAccountData);
|
|
};
|
|
}, [mx, setContent]);
|
|
};
|