@@ -12,6 +12,11 @@ import {
1212 sendDesktopNotification ,
1313} from "@/features/notifications/lib/desktop" ;
1414import type { NotificationSettings } from "@/features/notifications/hooks" ;
15+ import {
16+ formatNotificationTitle ,
17+ resolveNotificationChannelLabel ,
18+ truncateNotificationBody ,
19+ } from "@/features/notifications/lib/notificationFormat" ;
1520import {
1621 playNotificationSound ,
1722 resolveSlotSound ,
@@ -53,13 +58,16 @@ function readWatermark(pubkey: string): number {
5358export function useReminderNotifications (
5459 pubkey : string | undefined ,
5560 settings : NotificationSettings ,
61+ channels : ReadonlyArray < { id : string ; name ?: string | null } > ,
5662) : void {
5763 const reminders = useRemindersQuery ( pubkey ) . data ;
5864 const queryClient = useQueryClient ( ) ;
5965 const remindersRef = React . useRef < Reminder [ ] > ( [ ] ) ;
6066 remindersRef . current = reminders ?? [ ] ;
6167 const settingsRef = React . useRef ( settings ) ;
6268 settingsRef . current = settings ;
69+ const channelsRef = React . useRef ( channels ) ;
70+ channelsRef . current = channels ;
6371
6472 // Track whether the query has resolved at least once. On mount,
6573 // useRemindersQuery is still loading (data === undefined), so
@@ -78,15 +86,27 @@ export function useReminderNotifications(
7886 return ;
7987 }
8088
89+ // For a single reminder, try to resolve the channel name from its target.
90+ // Multiple reminders may span different channels, so we omit channel context
91+ // in that case and let the body count speak for itself.
92+ const channelLabel =
93+ due . length === 1
94+ ? resolveNotificationChannelLabel (
95+ due [ 0 ] . content . target ?. channelId ?? null ,
96+ channelsRef . current ,
97+ )
98+ : null ;
99+
81100 const body =
82101 due . length === 1
83- ? ( due [ 0 ] . content . target ?. preview ??
84- due [ 0 ] . content . note ??
85- "A reminder is waiting" )
102+ ? truncateNotificationBody (
103+ due [ 0 ] . content . target ?. preview ?? due [ 0 ] . content . note ?? "" ,
104+ "A reminder is waiting" ,
105+ )
86106 : `${ due . length } reminders are due` ;
87107
88108 void sendDesktopNotification ( {
89- title : "Reminder due" ,
109+ title : formatNotificationTitle ( { prefix : "Reminder due" , channelLabel } ) ,
90110 body,
91111 } ) . then ( ( didSend ) => {
92112 if ( ! didSend ) return ;
0 commit comments