@@ -77,6 +77,52 @@ let platform = null;
7777let hasOngoingCall = false ;
7878let lastUserSettingSyncDate = new Date ( ) ;
7979
80+ // Helper function to determine if a call should be auto-logged based on direction and result
81+ function shouldAutoLogCall ( call , userSettings ) {
82+ let shouldAutoLog = false ;
83+
84+ if ( call . direction === 'Inbound' ) {
85+ if ( call . result === 'Answered' ) {
86+ shouldAutoLog = userSettings ?. autoLogAnsweredIncoming ?. value ?? false ;
87+ } else if ( call . result === 'Missed' ) {
88+ shouldAutoLog = userSettings ?. autoLogMissedIncoming ?. value ?? false ;
89+ }
90+ } else if ( call . direction === 'Outbound' ) {
91+ shouldAutoLog = userSettings ?. autoLogOutgoing ?. value ?? false ;
92+ }
93+
94+ // Fallback to legacy setting for backward compatibility
95+ if ( ! shouldAutoLog ) {
96+ shouldAutoLog = userSettings ?. autoLogCall ?. value ?? false ;
97+ }
98+
99+ return shouldAutoLog ;
100+ }
101+
102+ // Helper function for presence update auto-logging (maps presence results to call results)
103+ function shouldAutoLogCallFromPresence ( call , userSettings ) {
104+ let shouldAutoLog = false ;
105+
106+ if ( call . direction === 'Inbound' ) {
107+ // For inbound calls: CallConnected = answered, Disconnected = missed
108+ if ( call . result === 'CallConnected' ) {
109+ shouldAutoLog = userSettings ?. autoLogAnsweredIncoming ?. value ?? false ;
110+ } else if ( call . result === 'Disconnected' ) {
111+ shouldAutoLog = userSettings ?. autoLogMissedIncoming ?. value ?? false ;
112+ }
113+ } else if ( call . direction === 'Outbound' ) {
114+ // For outbound calls: both CallConnected and Disconnected mean call was made
115+ shouldAutoLog = userSettings ?. autoLogOutgoing ?. value ?? false ;
116+ }
117+
118+ // Fallback to legacy setting for backward compatibility
119+ if ( ! shouldAutoLog ) {
120+ shouldAutoLog = userSettings ?. autoLogCall ?. value ?? false ;
121+ }
122+
123+ return shouldAutoLog ;
124+ }
125+
80126async function restartSyncInterval ( ) {
81127 // Clear existing interval
82128 const { retroAutoCallLogIntervalId } = await chrome . storage . local . get ( { retroAutoCallLogIntervalId : null } ) ;
@@ -1273,16 +1319,23 @@ window.addEventListener('message', async (e) => {
12731319 } ) ;
12741320
12751321 // Translate: If no existing call log, create condition here to navigate to auto log
1276- if ( userCore . getAutoLogCallSetting ( userSettings ) . value && data . body . triggerType === 'callLogSync' && ! ( existingCalls ?. length > 0 && existingCalls [ 0 ] ?. matched ) ) {
1277- data . body . triggerType = 'createLog' ;
1278- isAutoLog = true ;
1322+ if ( data . body . triggerType === 'callLogSync' && ! ( existingCalls ?. length > 0 && existingCalls [ 0 ] ?. matched ) ) {
1323+ if ( shouldAutoLogCall ( data . body . call , userSettings ) ) {
1324+ data . body . triggerType = 'createLog' ;
1325+ isAutoLog = true ;
1326+ }
12791327 }
12801328
12811329 // Translate: Right after call, once presence update to Disconnect, auto log the call
12821330 if ( data . body . triggerType === 'presenceUpdate' ) {
12831331 if ( data . body . call . result === 'Disconnected' || data . body . call . result === 'CallConnected' ) {
1284- data . body . triggerType = 'createLog' ;
1285- isAutoLog = true ;
1332+ if ( shouldAutoLogCallFromPresence ( data . body . call , userSettings ) ) {
1333+ data . body . triggerType = 'createLog' ;
1334+ isAutoLog = true ;
1335+ } else {
1336+ responseMessage ( data . requestId , { data : 'ok' } ) ;
1337+ break ;
1338+ }
12861339 }
12871340 else {
12881341 responseMessage ( data . requestId , { data : 'ok' } ) ;
0 commit comments