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,9 +304,13 @@ } }; - const handleEncryptedNotification = (encryptedPayload: string) => { + const handleEncryptedNotification = ( + keyserverID: string, + encryptedPayload: string, + ) => { if (mainWindow) { mainWindow.webContents.send('on-encrypted-notification', { + keyserverID, encryptedPayload, }); } 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,12 +129,22 @@ function listenForNotifications( handleClick: (threadID?: string) => void, - handleEncryptedNotification: (encryptedPayload: string) => void, + handleEncryptedNotification: ( + keyserverID: string, + encryptedPayload: string, + ) => void, ) { if (process.platform === 'darwin') { pushNotifications.on('received-apns-notification', (event, userInfo) => { + const { keyserverID, encryptedPayload } = userInfo; + if ( + typeof keyserverID !== 'string' || + typeof encryptedPayload !== 'string' + ) { + return; + } if (userInfo.encryptedPayload) { - handleEncryptedNotification(userInfo.encryptedPayload); + handleEncryptedNotification(keyserverID, encryptedPayload); } else { showNewNotification(userInfo, handleClick); } @@ -142,7 +152,10 @@ } else if (process.platform === 'win32') { windowsPushNotifEventEmitter.on('received-wns-notification', payload => { if (payload.encryptedPayload) { - handleEncryptedNotification(payload.encryptedPayload); + handleEncryptedNotification( + payload.keyserverID, + payload.encryptedPayload, + ); } else { 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 @@ -12,6 +12,7 @@ type OnNotificationClickedListener = (data: { threadID: string }) => void; type OnEncryptedNotificationListener = (data: { + keyserverID: string, encryptedPayload: string, }) => mixed; 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 @@ -105,6 +105,7 @@ } async function decryptDesktopNotification( + keyserverID: string, encryptedPayload: string, staffCanSee: boolean, ): Promise<{ +[string]: mixed }> { @@ -342,7 +343,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,8 +54,15 @@ React.useEffect( () => electron?.onEncryptedNotification?.( - async ({ encryptedPayload }: { encryptedPayload: string }) => { + async ({ + keyserverID, + encryptedPayload, + }: { + keyserverID: string, + encryptedPayload: string, + }) => { const decryptedPayload = await decryptDesktopNotification( + keyserverID, encryptedPayload, staffCanSee, );