Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcinwasowicz/9bc13a92310a9b91a59d73a2557b62a9 to your computer and use it in GitHub Desktop.
Save marcinwasowicz/9bc13a92310a9b91a59d73a2557b62a9 to your computer and use it in GitHub Desktop.
Keyserver encrypt
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;
+}
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment