@@ -61,12 +61,14 @@ import {
6161 appDomain ,
6262 EmailStatus ,
6363 composerEvents ,
64- EXTERNAL_RECIPIENT_ID_SERVER
64+ EXTERNAL_RECIPIENT_ID_SERVER ,
65+ NOTIFICATION_ACTIONS
6566} from './const' ;
6667import Messages from './../data/message' ;
6768import { MessageType } from './../components/Message' ;
6869import { AttachItemStatus } from '../components/AttachItem' ;
6970import { getShowEmailPreviewStatus , getUserGuideStepStatus } from './storage' ;
71+ import { getSubjectFromPushMessage } from './StringUtils' ;
7072import {
7173 fetchAcknowledgeEvents ,
7274 fetchEvents ,
@@ -84,7 +86,6 @@ const {
8486 NOTIFICATION_SERVICE_STARTED ,
8587 TOKEN_UPDATED
8688} = remote . require ( '@criptext/electron-push-receiver/src/constants' ) ;
87- const pushActions = [ 'anti_push' , 'open_thread' , 'open_activity' ] ;
8889const senderNotificationId = '73243261136' ;
8990const emitter = new EventEmitter ( ) ;
9091let totalEmailsPending = null ;
@@ -1004,6 +1005,7 @@ ipcRenderer.on('socket-message', async (ev, message) => {
10041005 if ( eventId === 400 ) {
10051006 sendLoadEventsEvent ( { showNotification : true } ) ;
10061007 } else {
1008+ if ( isGettingEvents ) return ;
10071009 await parseAndDispatchEvent ( message ) ;
10081010 }
10091011} ) ;
@@ -1430,21 +1432,40 @@ ipcRenderer.on(TOKEN_UPDATED, async (_, token) => {
14301432} ) ;
14311433
14321434ipcRenderer . on ( NOTIFICATION_RECEIVED , async ( _ , { data } ) => {
1433- if ( pushActions . includes ( data . action ) || ! data . rowId ) return ;
1434- isGettingEvents = true ;
14351435 try {
1436- const eventData = await fetchGetSingleEvent ( { rowId : data . rowId } ) ;
1437- await parseAndStoreEventsBatch ( {
1438- events : [ eventData ] ,
1439- hasMoreEvents : false
1440- } ) ;
1441- sendNewEmailNotification ( ) ;
1442- sendLoadEventsEvent ( { showNotification : true } ) ;
1436+ switch ( data . action ) {
1437+ case NOTIFICATION_ACTIONS . NEW_EMAIL : {
1438+ if ( isGettingEvents ) return ;
1439+ isGettingEvents = true ;
1440+ const eventData = await fetchGetSingleEvent ( { rowId : data . rowId } ) ;
1441+ await parseAndDispatchEvent ( eventData ) ;
1442+ sendNewEmailNotification ( ) ;
1443+ isGettingEvents = false ;
1444+ sendLoadEventsEvent ( { showNotification : true } ) ;
1445+ break ;
1446+ }
1447+ case NOTIFICATION_ACTIONS . OPEN_EMAIL : {
1448+ const subject = getSubjectFromPushMessage (
1449+ data . body ,
1450+ string . mailbox . empty_subject
1451+ ) ;
1452+ if ( subject ) {
1453+ const title = string . notification . openEmail . title ;
1454+ const message = string . notification . openEmail . message . replace (
1455+ '<subject>' ,
1456+ subject
1457+ ) ;
1458+ showNotificationApp ( { title, message } ) ;
1459+ }
1460+ break ;
1461+ }
1462+ default :
1463+ break ;
1464+ }
14431465 } catch ( firebaseNotifErr ) {
14441466 // eslint-disable-next-line no-console
14451467 console . error ( `[Firebase Error]: ` , firebaseNotifErr ) ;
14461468 }
1447- isGettingEvents = false ;
14481469} ) ;
14491470
14501471ipcRenderer . send ( START_NOTIFICATION_SERVICE , senderNotificationId ) ;
0 commit comments