Created
May 11, 2023 14:29
Revisions
-
marcinwasowicz created this gist
May 11, 2023 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js index 82dec8325..602b15d95 100644 --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -59,6 +59,7 @@ import { fetchCollapsableNotifs } from '../fetchers/message-fetchers.js'; import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; import { fetchUserInfos } from '../fetchers/user-fetchers.js'; import type { Viewer } from '../session/viewer.js'; +import { encryptAndUpdateOlmSession } from '../updaters/olm-session-updater.js'; import { getENSNames } from '../utils/ens-cache.js'; type Device = { @@ -206,9 +207,10 @@ async function sendPushNotifs(pushInfo: PushInfo) { unreadCount: unreadCounts[userID], platformDetails, }); + const newNotf = await encryptAPNsNotification(notification); return await sendAPNsNotification( 'ios', - notification, + newNotf, [...deviceTokens], { ...notificationInfo, @@ -676,6 +678,21 @@ async function prepareAPNsNotification( return notification; } +async function encryptAPNsNotification( + notification: apn.Notification, +): Promise<apn.Notification> { + const [encryptedBody, encryptedThreadID, encryptedMessageInfos] = + await encryptAndUpdateOlmSession('your cookie id', 'notifications', [ + notification.body, + notification.payload.threadID, + notification.payload.messageInfos, + ]); + notification.body = encryptedBody.body; + notification.threadId = encryptedThreadID.body; + notification.payload.messageInfos = encryptedMessageInfos.body; + return notification; +} +