diff --git a/desktop/flow-typed/npm/electron_v22.0.0.js b/desktop/flow-typed/npm/electron_v22.0.0.js --- a/desktop/flow-typed/npm/electron_v22.0.0.js +++ b/desktop/flow-typed/npm/electron_v22.0.0.js @@ -336,7 +336,7 @@ declare type PushNotificationsEvents = { 'received-apns-notification': ( event: Event, - userInfo: { +[string]: mixed, +encryptedPayload?: string }, + userInfo: {+[string]: mixed}, ) => void, }; diff --git a/desktop/src/main.js b/desktop/src/main.js --- a/desktop/src/main.js +++ b/desktop/src/main.js @@ -304,10 +304,14 @@ } }; - const handleEncryptedNotification = (encryptedPayload: string) => { + const handleEncryptedNotification = ( + encryptedPayload: string, + keyserverID: string, + ) => { if (mainWindow) { mainWindow.webContents.send('on-encrypted-notification', { encryptedPayload, + keyserverID, }); } }; diff --git a/desktop/src/push-notifications.js b/desktop/src/push-notifications.js --- a/desktop/src/push-notifications.js +++ b/desktop/src/push-notifications.js @@ -129,23 +129,34 @@ function listenForNotifications( handleClick: (threadID?: string) => void, - handleEncryptedNotification: (encryptedPayload: string) => void, + handleEncryptedNotification: ( + encryptedPayload: string, + keyserverID: string, + ) => void, ) { if (process.platform === 'darwin') { pushNotifications.on('received-apns-notification', (event, userInfo) => { - if (userInfo.encryptedPayload) { - handleEncryptedNotification(userInfo.encryptedPayload); - } else { - showNewNotification(userInfo, handleClick); + const { keyserverID, encryptedPayload } = userInfo; + if ( + typeof keyserverID === 'string' && + typeof encryptedPayload === 'string' + ) { + handleEncryptedNotification(encryptedPayload, keyserverID); + return; } + showNewNotification(userInfo, handleClick); }); } else if (process.platform === 'win32') { windowsPushNotifEventEmitter.on('received-wns-notification', payload => { - if (payload.encryptedPayload) { - handleEncryptedNotification(payload.encryptedPayload); - } else { - showNewNotification(payload, handleClick); + const { keyserverID, encryptedPayload } = payload; + if ( + typeof keyserverID === 'string' && + typeof encryptedPayload === 'string' + ) { + handleEncryptedNotification(encryptedPayload, keyserverID); + return; } + showNewNotification(payload, handleClick); }); } } diff --git a/lib/types/electron-types.js b/lib/types/electron-types.js --- a/lib/types/electron-types.js +++ b/lib/types/electron-types.js @@ -13,6 +13,7 @@ type OnEncryptedNotificationListener = (data: { encryptedPayload: string, + keyserverID?: string, }) => mixed; export type ElectronBridge = { diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js --- a/web/account/account-hooks.js +++ b/web/account/account-hooks.js @@ -288,7 +288,7 @@ ); const notifsOlmDataEncryptionKeyDBLabel = - getOlmEncryptionKeyDBLabelForCookie(cookie); + getOlmEncryptionKeyDBLabelForCookie(cookie, keyserverID); const notifsOlmDataContentKey = getOlmDataContentKeyForCookie( cookie, keyserverID, diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js --- a/web/push-notif/notif-crypto-utils.js +++ b/web/push-notif/notif-crypto-utils.js @@ -107,6 +107,8 @@ async function decryptDesktopNotification( encryptedPayload: string, staffCanSee: boolean, + // eslint-disable-next-line no-unused-vars + keyserverID?: string, ): Promise<{ +[string]: mixed }> { let encryptedOlmData, encryptionKey, olmDataContentKey; try { @@ -342,7 +344,11 @@ return `${NOTIFICATIONS_OLM_DATA_CONTENT}:${cookieID}`; } -function getOlmEncryptionKeyDBLabelForCookie(cookie: ?string): string { +function getOlmEncryptionKeyDBLabelForCookie( + cookie: ?string, + // eslint-disable-next-line no-unused-vars + keyserverID: string, +): string { if (!cookie) { return NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY; } diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js --- a/web/push-notif/push-notifs-handler.js +++ b/web/push-notif/push-notifs-handler.js @@ -54,10 +54,17 @@ React.useEffect( () => electron?.onEncryptedNotification?.( - async ({ encryptedPayload }: { encryptedPayload: string }) => { + async ({ + encryptedPayload, + keyserverID, + }: { + encryptedPayload: string, + keyserverID?: string, + }) => { const decryptedPayload = await decryptDesktopNotification( encryptedPayload, staffCanSee, + keyserverID, ); electron?.showDecryptedNotification(decryptedPayload); },