Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2847236
D6571.id22033.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
17 KB
Referenced Files
None
Subscribers
None
D6571.id22033.diff
View Options
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -164,21 +164,22 @@
newRawMessageInfos,
{ platform: 'ios', codeVersion },
);
- const notification = prepareIOSNotification(
- allMessageInfos,
- shimmedNewRawMessageInfos,
- threadInfo,
- notifInfo.collapseKey,
- badgeOnly,
- unreadCounts[userID],
- codeVersion,
- );
- deliveryPromises.push(
- sendIOSNotification(notification, [...deviceTokens], {
+ const deliveryPromise = (async () => {
+ const notification = await prepareIOSNotification(
+ allMessageInfos,
+ shimmedNewRawMessageInfos,
+ threadInfo,
+ notifInfo.collapseKey,
+ badgeOnly,
+ unreadCounts[userID],
+ codeVersion,
+ );
+ return await sendIOSNotification(notification, [...deviceTokens], {
...notificationInfo,
codeVersion,
- }),
- );
+ });
+ })();
+ deliveryPromises.push(deliveryPromise);
}
}
const androidVersionsToTokens = byDeviceType.get('android');
@@ -189,22 +190,27 @@
newRawMessageInfos,
{ platform: 'android', codeVersion },
);
- const notification = prepareAndroidNotification(
- allMessageInfos,
- shimmedNewRawMessageInfos,
- threadInfo,
- notifInfo.collapseKey,
- badgeOnly,
- unreadCounts[userID],
- dbID,
- codeVersion,
- );
- deliveryPromises.push(
- sendAndroidNotification(notification, [...deviceTokens], {
- ...notificationInfo,
+ const deliveryPromise = (async () => {
+ const notification = await prepareAndroidNotification(
+ allMessageInfos,
+ shimmedNewRawMessageInfos,
+ threadInfo,
+ notifInfo.collapseKey,
+ badgeOnly,
+ unreadCounts[userID],
+ dbID,
codeVersion,
- }),
- );
+ );
+ return await sendAndroidNotification(
+ notification,
+ [...deviceTokens],
+ {
+ ...notificationInfo,
+ codeVersion,
+ },
+ );
+ })();
+ deliveryPromises.push(deliveryPromise);
}
}
@@ -466,7 +472,7 @@
return byDeviceType;
}
-function prepareIOSNotification(
+async function prepareIOSNotification(
allMessageInfos: MessageInfo[],
newRawMessageInfos: RawMessageInfo[],
threadInfo: ThreadInfo,
@@ -474,12 +480,12 @@
badgeOnly: boolean,
unreadCount: number,
codeVersion: number,
-): apn.Notification {
+): Promise<apn.Notification> {
const uniqueID = uuidv4();
const notification = new apn.Notification();
notification.topic = getAPNsNotificationTopic(codeVersion);
- const { merged, ...rest } = notifTextsForMessageInfo(
+ const { merged, ...rest } = await notifTextsForMessageInfo(
allMessageInfos,
threadInfo,
);
@@ -527,7 +533,7 @@
return notification;
}
-function prepareAndroidNotification(
+async function prepareAndroidNotification(
allMessageInfos: MessageInfo[],
newRawMessageInfos: RawMessageInfo[],
threadInfo: ThreadInfo,
@@ -536,9 +542,9 @@
unreadCount: number,
dbID: string,
codeVersion: number,
-): Object {
+): Promise<Object> {
const notifID = collapseKey ? collapseKey : dbID;
- const { merged, ...rest } = notifTextsForMessageInfo(
+ const { merged, ...rest } = await notifTextsForMessageInfo(
allMessageInfos,
threadInfo,
);
diff --git a/lib/shared/messages/add-members-message-spec.js b/lib/shared/messages/add-members-message-spec.js
--- a/lib/shared/messages/add-members-message-spec.js
+++ b/lib/shared/messages/add-members-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} added ${addedUsers}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const addedMembersObject = {};
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/change-role-message-spec.js b/lib/shared/messages/change-role-message-spec.js
--- a/lib/shared/messages/change-role-message-spec.js
+++ b/lib/shared/messages/change-role-message-spec.js
@@ -129,11 +129,11 @@
return ET`${creator} ${verb} ${affectedUsers} as ${noun}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const membersObject = {};
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/change-settings-message-spec.js b/lib/shared/messages/change-settings-message-spec.js
--- a/lib/shared/messages/change-settings-message-spec.js
+++ b/lib/shared/messages/change-settings-message-spec.js
@@ -137,11 +137,11 @@
})} ${messageInfo.field} to "${value}"`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const mostRecentMessageInfo = messageInfos[0];
invariant(
mostRecentMessageInfo.type === messageTypes.CHANGE_SETTINGS,
diff --git a/lib/shared/messages/create-entry-message-spec.js b/lib/shared/messages/create-entry-message-spec.js
--- a/lib/shared/messages/create-entry-message-spec.js
+++ b/lib/shared/messages/create-entry-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} created an event scheduled for ${date}: "${text}"`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const hasCreateEntry = messageInfos.some(
messageInfo => messageInfo.type === messageTypes.CREATE_ENTRY,
);
diff --git a/lib/shared/messages/create-sidebar-message-spec.js b/lib/shared/messages/create-sidebar-message-spec.js
--- a/lib/shared/messages/create-sidebar-message-spec.js
+++ b/lib/shared/messages/create-sidebar-message-spec.js
@@ -177,10 +177,10 @@
return unwrapped;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.CREATE_SIDEBAR,
diff --git a/lib/shared/messages/create-sub-thread-message-spec.js b/lib/shared/messages/create-sub-thread-message-spec.js
--- a/lib/shared/messages/create-sub-thread-message-spec.js
+++ b/lib/shared/messages/create-sub-thread-message-spec.js
@@ -126,11 +126,11 @@
return ET`${creator} ${text}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.CREATE_SUB_THREAD,
diff --git a/lib/shared/messages/create-thread-message-spec.js b/lib/shared/messages/create-thread-message-spec.js
--- a/lib/shared/messages/create-thread-message-spec.js
+++ b/lib/shared/messages/create-thread-message-spec.js
@@ -139,11 +139,11 @@
return ET`${creator} ${text}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.CREATE_THREAD,
diff --git a/lib/shared/messages/delete-entry-message-spec.js b/lib/shared/messages/delete-entry-message-spec.js
--- a/lib/shared/messages/delete-entry-message-spec.js
+++ b/lib/shared/messages/delete-entry-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} deleted an event scheduled for ${date}: "${text}"`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.DELETE_ENTRY,
diff --git a/lib/shared/messages/edit-entry-message-spec.js b/lib/shared/messages/edit-entry-message-spec.js
--- a/lib/shared/messages/edit-entry-message-spec.js
+++ b/lib/shared/messages/edit-entry-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} updated the text of an event scheduled for ${date}: "${text}"`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const hasCreateEntry = messageInfos.some(
messageInfo => messageInfo.type === messageTypes.CREATE_ENTRY,
);
diff --git a/lib/shared/messages/join-thread-message-spec.js b/lib/shared/messages/join-thread-message-spec.js
--- a/lib/shared/messages/join-thread-message-spec.js
+++ b/lib/shared/messages/join-thread-message-spec.js
@@ -79,11 +79,11 @@
})}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const joinerArray = {};
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/leave-thread-message-spec.js b/lib/shared/messages/leave-thread-message-spec.js
--- a/lib/shared/messages/leave-thread-message-spec.js
+++ b/lib/shared/messages/leave-thread-message-spec.js
@@ -79,11 +79,11 @@
})}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const leaverBeavers = {};
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js
--- a/lib/shared/messages/message-spec.js
+++ b/lib/shared/messages/message-spec.js
@@ -60,7 +60,7 @@
+notificationTexts: (
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
- ) => NotifTexts,
+ ) => Promise<NotifTexts>,
};
export type GeneratesNotifsParams = {
@@ -105,7 +105,7 @@
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ) => NotifTexts,
+ ) => Promise<NotifTexts>,
+notificationCollapseKey?: (rawMessageInfo: RawInfo) => string,
+generatesNotifs: (
rawMessageInfo: RawInfo,
diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js
--- a/lib/shared/messages/multimedia-message-spec.js
+++ b/lib/shared/messages/multimedia-message-spec.js
@@ -262,11 +262,11 @@
return undefined;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const media = [];
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/reaction-message-spec.js b/lib/shared/messages/reaction-message-spec.js
--- a/lib/shared/messages/reaction-message-spec.js
+++ b/lib/shared/messages/reaction-message-spec.js
@@ -160,11 +160,11 @@
return unwrapped;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.REACTION,
diff --git a/lib/shared/messages/remove-members-message-spec.js b/lib/shared/messages/remove-members-message-spec.js
--- a/lib/shared/messages/remove-members-message-spec.js
+++ b/lib/shared/messages/remove-members-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} removed ${removedUsers}`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const removedMembersObject = {};
for (const messageInfo of messageInfos) {
invariant(
diff --git a/lib/shared/messages/restore-entry-message-spec.js b/lib/shared/messages/restore-entry-message-spec.js
--- a/lib/shared/messages/restore-entry-message-spec.js
+++ b/lib/shared/messages/restore-entry-message-spec.js
@@ -111,11 +111,11 @@
return ET`${creator} restored an event scheduled for ${date}: "${text}"`;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.RESTORE_ENTRY,
diff --git a/lib/shared/messages/sidebar-source-message-spec.js b/lib/shared/messages/sidebar-source-message-spec.js
--- a/lib/shared/messages/sidebar-source-message-spec.js
+++ b/lib/shared/messages/sidebar-source-message-spec.js
@@ -163,18 +163,18 @@
return unwrapped;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.SIDEBAR_SOURCE,
'messageInfo should be messageTypes.SIDEBAR_SOURCE!',
);
const sourceMessageInfo = messageInfo.sourceMessage;
- return params.notificationTexts([sourceMessageInfo], threadInfo);
+ return await params.notificationTexts([sourceMessageInfo], threadInfo);
},
generatesNotifs: async () => undefined,
diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js
--- a/lib/shared/messages/text-message-spec.js
+++ b/lib/shared/messages/text-message-spec.js
@@ -166,11 +166,11 @@
}
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
params: NotificationTextsParams,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
invariant(
messageInfo.type === messageTypes.TEXT,
diff --git a/lib/shared/messages/update-relationship-message-spec.js b/lib/shared/messages/update-relationship-message-spec.js
--- a/lib/shared/messages/update-relationship-message-spec.js
+++ b/lib/shared/messages/update-relationship-message-spec.js
@@ -152,10 +152,10 @@
return unwrapped;
},
- notificationTexts(
+ async notificationTexts(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
- ): NotifTexts {
+ ): Promise<NotifTexts> {
const messageInfo = assertSingleMessageInfo(messageInfos);
const prefix = stringForUser(messageInfo.creator);
const title = threadInfo.uiName;
diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js
--- a/lib/shared/notif-utils.js
+++ b/lib/shared/notif-utils.js
@@ -18,11 +18,14 @@
import { threadNoun } from './thread-utils';
import { stringForUser } from './user-utils';
-function notifTextsForMessageInfo(
+async function notifTextsForMessageInfo(
messageInfos: MessageInfo[],
threadInfo: ThreadInfo,
-): NotifTexts {
- const fullNotifTexts = fullNotifTextsForMessageInfo(messageInfos, threadInfo);
+): Promise<NotifTexts> {
+ const fullNotifTexts = await fullNotifTextsForMessageInfo(
+ messageInfos,
+ threadInfo,
+ );
const merged = trimText(fullNotifTexts.merged, 300);
const body = trimText(fullNotifTexts.body, 300);
const title = trimText(fullNotifTexts.title, 100);
@@ -74,17 +77,17 @@
return messageInfos[0].type;
}
-function fullNotifTextsForMessageInfo(
+async function fullNotifTextsForMessageInfo(
messageInfos: $ReadOnlyArray<MessageInfo>,
threadInfo: ThreadInfo,
-): NotifTexts {
+): Promise<NotifTexts> {
const mostRecentType = mostRecentMessageInfoType(messageInfos);
const messageSpec = messageSpecs[mostRecentType];
invariant(
messageSpec.notificationTexts,
`we're not aware of messageType ${mostRecentType}`,
);
- return messageSpec.notificationTexts(messageInfos, threadInfo, {
+ return await messageSpec.notificationTexts(messageInfos, threadInfo, {
notifThreadName,
notifTextForSubthreadCreation,
strippedRobotextForMessageInfo,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 1, 2:27 AM (21 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2208497
Default Alt Text
D6571.id22033.diff (17 KB)
Attached To
Mode
D6571: [lib][keyserver] Convert notificationTexts to async functions
Attached
Detach File
Event Timeline
Log In to Comment