Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. marcinwasowicz created this gist May 11, 2023.
    43 changes: 43 additions & 0 deletions gistfile1.txt
    Original 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;
    +}
    +