@@ -64,6 +64,7 @@ export const usePhoneIslandEventListener = () => {
6464 const [ connected , setConnected ] = useSharedState ( 'connection' )
6565 const [ availableRingtones , setAvailableRingtones ] = useSharedState ( 'availableRingtones' )
6666 const notifiedSummaryIdsRef = useRef < Set < string > > ( new Set ( ) )
67+ const watchedSummaryIdsRef = useRef < Set < string > > ( new Set ( ) )
6768
6869 const [ phoneIslandData , setPhoneIslandData ] = useState < PhoneIslandData > ( {
6970 activeAlerts : { } ,
@@ -79,6 +80,7 @@ export const usePhoneIslandEventListener = () => {
7980
8081 useEffect ( ( ) => {
8182 notifiedSummaryIdsRef . current . clear ( )
83+ watchedSummaryIdsRef . current . clear ( )
8284 } , [ account ?. username ] )
8385
8486
@@ -339,7 +341,37 @@ export const usePhoneIslandEventListener = () => {
339341 ...eventHandler ( PHONE_ISLAND_EVENTS [ "phone-island-ringing-tone-output-changed" ] , ( data ) => {
340342 Log . info ( 'Phone-island confirmed output device changed:' , data ?. deviceId )
341343 } ) ,
342- ...eventHandler ( PHONE_ISLAND_EVENTS [ "phone-island-summary-not-ready" ] ) ,
344+ ...eventHandler ( PHONE_ISLAND_EVENTS [ "phone-island-summary-not-ready" ] , ( data ) => {
345+ const linkedid = data ?. linkedid
346+ const isSummaryEnabled = account ?. data ?. call_summary_enabled === true
347+ const isSummaryNotificationEnabled =
348+ account ?. data ?. settings ?. call_summary_notifications !== false
349+
350+ if ( ! linkedid ) {
351+ return
352+ }
353+
354+ if ( ! account ) {
355+ return
356+ }
357+
358+ if ( ! isSummaryEnabled ) {
359+ return
360+ }
361+
362+ if ( ! isSummaryNotificationEnabled ) {
363+ return
364+ }
365+
366+ if ( watchedSummaryIdsRef . current . has ( linkedid ) ) {
367+ return
368+ }
369+
370+ watchedSummaryIdsRef . current . add ( linkedid )
371+ window . dispatchEvent ( new CustomEvent ( 'phone-island-call-summary-notify' , {
372+ detail : { linkedid }
373+ } ) )
374+ } ) ,
343375 ...eventHandler ( PHONE_ISLAND_EVENTS [ "phone-island-summary-ready" ] , ( data ) => {
344376 const linkedid = data ?. linkedid
345377 const displayName = data ?. display_name ?. trim ?.( ) || ''
@@ -348,7 +380,19 @@ export const usePhoneIslandEventListener = () => {
348380 const isSummaryNotificationEnabled =
349381 account ?. data ?. settings ?. call_summary_notifications !== false
350382
351- if ( ! linkedid || ! account || ! isSummaryEnabled || ! isSummaryNotificationEnabled ) {
383+ if ( ! linkedid ) {
384+ return
385+ }
386+
387+ if ( ! account ) {
388+ return
389+ }
390+
391+ if ( ! isSummaryEnabled ) {
392+ return
393+ }
394+
395+ if ( ! isSummaryNotificationEnabled ) {
352396 return
353397 }
354398
@@ -357,6 +401,7 @@ export const usePhoneIslandEventListener = () => {
357401 }
358402
359403 notifiedSummaryIdsRef . current . add ( linkedid )
404+ watchedSummaryIdsRef . current . delete ( linkedid )
360405
361406 const contact = displayName || displayNumber
362407
0 commit comments