Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3389004
D7872.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7872.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 5:04 PM (21 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601713
Default Alt Text
D7872.diff (2 KB)
Attached To
Mode
D7872: Implement function to encrypt android notification
Attached
Detach File
Event Timeline
Log In to Comment