Page MenuHomePhabricator

D7872.id27186.diff
No OneTemporary

D7872.id27186.diff

diff --git a/keyserver/src/push/crypto.js b/keyserver/src/push/crypto.js
--- a/keyserver/src/push/crypto.js
+++ b/keyserver/src/push/crypto.js
@@ -3,6 +3,7 @@
import apn from '@parse/node-apn';
import invariant from 'invariant';
+import type { AndroidNotification } from './types.js';
import { encryptAndUpdateOlmSession } from '../updaters/olm-session-updater.js';
async function encryptIOSNotification(
@@ -65,6 +66,42 @@
return encryptedNotification;
}
+async function encryptAndroidNotification(
+ cookieID: string,
+ notification: AndroidNotification,
+): Promise<AndroidNotification> {
+ const { id, badgeOnly, ...unencryptedPayload } = notification.data;
+ const encryptedNotification = { data: { id, badgeOnly } };
+
+ let encryptedSerializedPayload;
+ try {
+ const unencryptedSerializedPayload = JSON.stringify(unencryptedPayload);
+ const { serializedPayload } = await encryptAndUpdateOlmSession(
+ cookieID,
+ 'notifications',
+ {
+ serializedPayload: unencryptedSerializedPayload,
+ },
+ );
+ encryptedSerializedPayload = serializedPayload;
+ } catch (e) {
+ console.log('Notification encryption failed: ' + e);
+
+ encryptedNotification.data = {
+ ...unencryptedPayload,
+ ...encryptedNotification.data,
+ encryptionFailed: '1',
+ };
+ return encryptedNotification;
+ }
+
+ encryptedNotification.data = {
+ ...encryptedNotification.data,
+ encryptedPayload: encryptedSerializedPayload.body,
+ };
+ return encryptedNotification;
+}
+
function prepareEncryptedIOSNotifications(
cookieIDs: $ReadOnlyArray<string>,
notification: apn.Notification,
@@ -75,4 +112,17 @@
return Promise.all(notificationPromises);
}
-export { prepareEncryptedIOSNotifications };
+function prepareEncryptedAndroidNotifications(
+ cookieIDs: $ReadOnlyArray<string>,
+ notification: AndroidNotification,
+): Promise<Array<AndroidNotification>> {
+ const notificationPromises = cookieIDs.map(cookieID =>
+ encryptAndroidNotification(cookieID, notification),
+ );
+ return Promise.all(notificationPromises);
+}
+
+export {
+ prepareEncryptedIOSNotifications,
+ prepareEncryptedAndroidNotifications,
+};
diff --git a/keyserver/src/push/types.js b/keyserver/src/push/types.js
--- a/keyserver/src/push/types.js
+++ b/keyserver/src/push/types.js
@@ -6,3 +6,11 @@
+notification: apn.Notification,
+deviceToken: string,
};
+
+export type AndroidNotification = {
+ +data: {
+ +id?: string,
+ +badgeOnly?: string,
+ +[string]: string,
+ },
+};

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 7:47 PM (21 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601713
Default Alt Text
D7872.id27186.diff (2 KB)

Event Timeline