feat(threads): Slack-style per-thread notifications (P4-1)
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>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import {
|
||||
MatrixEvent,
|
||||
NotificationCountType,
|
||||
@@ -8,6 +9,8 @@ import {
|
||||
ThreadEvent,
|
||||
} from 'matrix-js-sdk';
|
||||
import { getThreadSummary, ThreadSummaryData } from '../features/room/thread/threadSummary';
|
||||
import { threadNotificationsAtom } from '../state/threadNotifications';
|
||||
import { getThreadNotificationMode, ThreadNotificationMode } from '../utils/threadNotifications';
|
||||
|
||||
/**
|
||||
* Reactive thread summary + unread count for a root event's "N replies" chip.
|
||||
@@ -18,9 +21,14 @@ import { getThreadSummary, ThreadSummaryData } from '../features/room/thread/thr
|
||||
export const useThreadSummary = (
|
||||
rootEvent: MatrixEvent,
|
||||
room: Room,
|
||||
): { summary: ThreadSummaryData | undefined; unread: number } => {
|
||||
): { summary: ThreadSummaryData | undefined; unread: number; mode: ThreadNotificationMode } => {
|
||||
const threadId = rootEvent.getId();
|
||||
|
||||
const threadNotifications = useAtomValue(threadNotificationsAtom);
|
||||
const mode = threadId
|
||||
? getThreadNotificationMode(threadNotifications, room.roomId, threadId)
|
||||
: ThreadNotificationMode.Default;
|
||||
|
||||
const [summary, setSummary] = useState<ThreadSummaryData | undefined>(() =>
|
||||
getThreadSummary(rootEvent),
|
||||
);
|
||||
@@ -53,5 +61,7 @@ export const useThreadSummary = (
|
||||
};
|
||||
}, [rootEvent, room, threadId]);
|
||||
|
||||
return { summary, unread };
|
||||
const muted = mode === ThreadNotificationMode.Mute;
|
||||
|
||||
return { summary, unread: muted ? 0 : unread, mode };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user