@@ -6,8 +6,6 @@ import { Outlet, useLocation } from "@tanstack/react-router";
66import {
77 deriveShellRoute ,
88 isWindowDragHandleEvent ,
9- shouldBounceForChannelNotification ,
10- toSearchHit ,
119} from "@/app/AppShell.helpers" ;
1210import { AppShellProvider } from "@/app/AppShellContext" ;
1311import {
@@ -20,6 +18,7 @@ import { useBackForwardControls } from "@/app/navigation/useBackForwardControls"
2018import { useLiveHomeFeedActions } from "@/app/useLiveHomeFeedActions" ;
2119import { useMarkAsReadShortcuts } from "@/app/useMarkAsReadShortcuts" ;
2220import { useSettingsShortcuts } from "@/app/useSettingsShortcuts" ;
21+ import { useAppShellDesktopNotifications } from "@/app/useAppShellDesktopNotifications" ;
2322import { useThreadActivityFeedItems } from "@/app/useThreadActivityFeedItems" ;
2423import { useWebviewZoomShortcuts } from "@/app/useWebviewZoomShortcuts" ;
2524import {
@@ -33,25 +32,12 @@ import { useUnreadChannels } from "@/features/channels/useUnreadChannels";
3332import { msgContextKey } from "@/features/channels/readState/readStateFormat" ;
3433import { useMembershipNotifications } from "@/features/channels/useMembershipNotifications" ;
3534import { useFeedItemState } from "@/features/home/useFeedItemState" ;
36- import { getThreadReference } from "@/features/messages/lib/threading" ;
37- import { hasMentionForEvent } from "@/features/notifications/lib/shouldNotify" ;
3835import { useThreadFollows } from "@/features/messages/lib/useThreadFollows" ;
3936import {
4037 useHomeFeedNotifications ,
4138 useHomeFeedNotificationState ,
4239} from "@/features/notifications/hooks" ;
43- import {
44- listenForDesktopNotificationActions ,
45- requestDockBounce ,
46- revealDesktopAppWindow ,
47- sendDesktopNotification ,
48- setDesktopAppBadge ,
49- type DesktopNotificationTarget ,
50- } from "@/features/notifications/lib/desktop" ;
51- import {
52- playNotificationSound ,
53- resolveSlotSound ,
54- } from "@/features/notifications/lib/sound" ;
40+ import { setDesktopAppBadge } from "@/features/notifications/lib/desktop" ;
5541import { PreventSleepProvider } from "@/features/agents/usePreventSleep" ;
5642import { requestOpenCreateAgent } from "@/features/agents/openCreateAgentEvent" ;
5743import {
@@ -84,7 +70,7 @@ import { useIdentityQuery } from "@/shared/api/hooks";
8470import { useRelayAutoHeal } from "@/shared/api/useRelayAutoHeal" ;
8571import { useDeferredStartup } from "@/shared/hooks/useDeferredStartup" ;
8672import { joinChannel } from "@/shared/api/tauri" ;
87- import type { Channel , RelayEvent , SearchHit } from "@/shared/api/types" ;
73+ import type { SearchHit } from "@/shared/api/types" ;
8874import { ChannelNavigationProvider } from "@/shared/context/ChannelNavigationContext" ;
8975import { MainInsetProvider } from "@/shared/layout/MainInsetContext" ;
9076import { chromeCssVarDefaults } from "@/shared/layout/chromeLayout" ;
@@ -177,57 +163,6 @@ export function AppShell() {
177163 identityQuery . data ?. pubkey ,
178164 refetchHomeFeedFromLiveSignal ,
179165 ) ;
180- const handleChannelNotification = React . useEffectEvent (
181- ( _channelId : string , event : RelayEvent ) => {
182- if ( ! shouldBounceForChannelNotification ( event . tags ) ) return ;
183- if ( ! notificationSettings . settings . desktopEnabled ) return ;
184- void requestDockBounce ( ) ;
185- } ,
186- ) ;
187-
188- const handleDmNotification = React . useEffectEvent (
189- ( event : RelayEvent , channel : Channel ) => {
190- if (
191- ! notificationSettings . settings . desktopEnabled ||
192- ! notificationSettings . settings . slotAlertsEnabled . dm
193- ) {
194- return ;
195- }
196-
197- const channelName = channel . name ?. trim ( ) || "Direct message" ;
198- const content = event . content . trim ( ) ;
199- const body =
200- content . length > 0
201- ? content . length > 140
202- ? `${ content . slice ( 0 , 137 ) . trimEnd ( ) } ...`
203- : content
204- : "New message" ;
205-
206- const threadRootId = getThreadReference ( event . tags ) . rootId ?? null ;
207-
208- void sendDesktopNotification ( {
209- title : channelName ,
210- body,
211- target : {
212- channelId : channel . id ,
213- channelName,
214- content : event . content ,
215- createdAt : event . created_at ,
216- eventId : event . id ,
217- kind : event . kind ,
218- pubkey : event . pubkey ,
219- threadRootId,
220- } ,
221- } ) . then ( ( didSend ) => {
222- if ( ! didSend ) return ;
223- playNotificationSound (
224- resolveSlotSound ( notificationSettings . settings , "dm" ) ,
225- ) ;
226- void requestDockBounce ( ) ;
227- } ) ;
228- } ,
229- ) ;
230-
231166 const channelsQuery = useChannelsQuery ( ) ;
232167 const { refetch : refetchChannels } = channelsQuery ;
233168 const channels = channelsQuery . data ?? [ ] ;
@@ -251,56 +186,18 @@ export function AppShell() {
251186 [ channels , selectedChannelId ] ,
252187 ) ;
253188
254- const handleThreadReplyDesktopNotification = React . useEffectEvent (
255- ( channelId : string , event : RelayEvent ) => {
256- if (
257- ! notificationSettings . settings . desktopEnabled ||
258- ! notificationSettings . settings . slotAlertsEnabled . thread_reply
259- ) {
260- return ;
261- }
262-
263- // Replies that @-mention the user are owned by the home-feed mention
264- // path — skip them here so they don't notify (and sound) twice.
265- const pubkey = identityQuery . data ?. pubkey ?. trim ( ) . toLowerCase ( ) ?? "" ;
266- if ( hasMentionForEvent ( event , pubkey ) ) {
267- return ;
268- }
269-
270- const channel = channels . find ( ( entry ) => entry . id === channelId ) ;
271- const channelName = channel ?. name ?. trim ( ) || "Thread" ;
272- const content = event . content . trim ( ) ;
273- const body =
274- content . length > 0
275- ? content . length > 140
276- ? `${ content . slice ( 0 , 137 ) . trimEnd ( ) } ...`
277- : content
278- : "New reply" ;
279-
280- const threadRootId = getThreadReference ( event . tags ) . rootId ?? null ;
281-
282- void sendDesktopNotification ( {
283- title : `Reply in ${ channelName } ` ,
284- body,
285- target : {
286- channelId,
287- channelName,
288- content : event . content ,
289- createdAt : event . created_at ,
290- eventId : event . id ,
291- kind : event . kind ,
292- pubkey : event . pubkey ,
293- threadRootId,
294- } ,
295- } ) . then ( ( didSend ) => {
296- if ( ! didSend ) return ;
297- playNotificationSound (
298- resolveSlotSound ( notificationSettings . settings , "thread_reply" ) ,
299- ) ;
300- void requestDockBounce ( ) ;
301- } ) ;
302- } ,
303- ) ;
189+ const {
190+ handleChannelNotification,
191+ handleDmNotification,
192+ handleThreadReplyDesktopNotification,
193+ } = useAppShellDesktopNotifications ( {
194+ channels,
195+ goChannel,
196+ goHome,
197+ notificationSettings : notificationSettings . settings ,
198+ openSearchHit,
199+ pubkey : identityQuery . data ?. pubkey ,
200+ } ) ;
304201
305202 const {
306203 followedRootIds,
@@ -517,25 +414,6 @@ export function AppShell() {
517414 [ openSearchHit ] ,
518415 ) ;
519416
520- const handleDesktopNotificationAction = React . useEffectEvent (
521- async ( target : DesktopNotificationTarget ) => {
522- await revealDesktopAppWindow ( ) ;
523-
524- if ( ! target . channelId ) {
525- void goHome ( ) ;
526- return ;
527- }
528-
529- const anchor = toSearchHit ( target ) ;
530- if ( ! anchor ) {
531- await goChannel ( target . channelId ) ;
532- return ;
533- }
534-
535- await openSearchHit ( anchor ) ;
536- } ,
537- ) ;
538-
539417 // Prevent webview file:/// navigation on file drop outside the composer.
540418 // Scoped to file drags only (text drag-and-drop into inputs still works).
541419 // Composer's onDrop fires first (React synthetic before window bubble).
@@ -602,31 +480,6 @@ export function AppShell() {
602480 // Dispatch `buzz://message` deep links into the router.
603481 useMessageDeepLinks ( ) ;
604482
605- React . useEffect ( ( ) => {
606- let isCancelled = false ;
607- let cleanup = ( ) => { } ;
608-
609- void listenForDesktopNotificationActions ( ( target ) => {
610- if ( isCancelled ) {
611- return ;
612- }
613-
614- void handleDesktopNotificationAction ( target ) ;
615- } ) . then ( ( dispose ) => {
616- if ( isCancelled ) {
617- dispose ( ) ;
618- return ;
619- }
620-
621- cleanup = dispose ;
622- } ) ;
623-
624- return ( ) => {
625- isCancelled = true ;
626- cleanup ( ) ;
627- } ;
628- } , [ ] ) ;
629-
630483 const handleOpenNewDm = React . useCallback ( ( ) => setIsNewDmOpen ( true ) , [ ] ) ;
631484 const handleOpenCreateChannel = React . useCallback (
632485 ( ) => setIsCreateChannelOpen ( true ) ,
0 commit comments