Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3495511
D6829.id22911.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D6829.id22911.diff
View Options
diff --git a/keyserver/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js
--- a/keyserver/src/creators/message-creator.js
+++ b/keyserver/src/creators/message-creator.js
@@ -10,6 +10,7 @@
stripLocalIDs,
} from 'lib/shared/message-utils.js';
import { pushTypes } from 'lib/shared/messages/message-spec.js';
+import type { PushType } from 'lib/shared/messages/message-spec.js';
import { messageSpecs } from 'lib/shared/messages/message-specs.js';
import {
messageTypes,
@@ -23,8 +24,8 @@
import { promiseAll } from 'lib/utils/promises.js';
import createIDs from './id-creator.js';
-import type { UpdatesForCurrentSession } from './update-creator.js';
import { createUpdates } from './update-creator.js';
+import type { UpdatesForCurrentSession } from './update-creator.js';
import {
dbQuery,
SQL,
@@ -392,6 +393,7 @@
const messageInfosPerUser = {};
const latestMessagesPerUser: LatestMessagesPerUser = new Map();
const userPushInfoPromises = {};
+
for (const pair of perUserInfo) {
const [userID, preUserPushInfo] = pair;
@@ -424,49 +426,57 @@
continue;
}
- const userPushInfoMessageInfoPromises = [];
- for (const threadID of preUserPushInfo.notFocusedThreadIDs) {
- const messageIndices = threadsToMessageIndices.get(threadID);
- invariant(messageIndices, `indices should exist for thread ${threadID}`);
- userPushInfoMessageInfoPromises.push(
- ...messageIndices.map(async messageIndex => {
- const messageInfo = messageInfos[messageIndex];
- const { type } = messageInfo;
- if (messageInfo.creatorID === userID) {
- // We never send a user notifs about their own activity
- return undefined;
- }
- const { generatesNotifs } = messageSpecs[type];
- const messageData = messageDatas[messageIndex];
- const doesGenerateNotif = await generatesNotifs(
- messageInfo,
- messageData,
- {
- notifTargetUserID: userID,
- userNotMemberOfSubthreads,
- fetchMessageInfoByID: (messageID: string) =>
- fetchMessageInfoByID(viewer, messageID),
- },
- );
- return doesGenerateNotif === pushTypes.NOTIF
- ? messageInfo
- : undefined;
- }),
- );
- }
- const userPushInfoPromise = (async () => {
- const pushMessageInfos = await Promise.all(
- userPushInfoMessageInfoPromises,
- );
- const filteredMessageInfos = pushMessageInfos.filter(Boolean);
- if (filteredMessageInfos.length === 0) {
- return undefined;
+ const generateNotifUserInfoPromise = (pushType: PushType) => {
+ const promises = [];
+
+ for (const threadID of preUserPushInfo.notFocusedThreadIDs) {
+ const messageIndices = threadsToMessageIndices.get(threadID);
+ invariant(
+ messageIndices,
+ `indices should exist for thread ${threadID}`,
+ );
+ promises.push(
+ ...messageIndices.map(async messageIndex => {
+ const messageInfo = messageInfos[messageIndex];
+ const { type } = messageInfo;
+ if (messageInfo.creatorID === userID) {
+ // We never send a user notifs about their own activity
+ return undefined;
+ }
+ const { generatesNotifs } = messageSpecs[type];
+ const messageData = messageDatas[messageIndex];
+ const doesGenerateNotif = await generatesNotifs(
+ messageInfo,
+ messageData,
+ {
+ notifTargetUserID: userID,
+ userNotMemberOfSubthreads,
+ fetchMessageInfoByID: (messageID: string) =>
+ fetchMessageInfoByID(viewer, messageID),
+ },
+ );
+ return doesGenerateNotif === pushType ? messageInfo : undefined;
+ }),
+ );
}
- return {
- devices: userDevices,
- messageInfos: filteredMessageInfos,
- };
- })();
+
+ return (async () => {
+ const notifMessageInfos = await Promise.all(promises);
+ const filteredNotifMessageInfos = notifMessageInfos.filter(Boolean);
+
+ if (filteredNotifMessageInfos.length === 0) {
+ return undefined;
+ }
+
+ return {
+ devices: userDevices,
+ messageInfos: filteredNotifMessageInfos,
+ };
+ })();
+ };
+
+ const userPushInfoPromise = generateNotifUserInfoPromise(pushTypes.NOTIF);
+
userPushInfoPromises[userID] = userPushInfoPromise;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 8:56 AM (18 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2681239
Default Alt Text
D6829.id22911.diff (4 KB)
Attached To
Mode
D6829: [keyserver] convert existing logic for building userPushInfoPromises to an async function called generateNotifUserInfoPromise
Attached
Detach File
Event Timeline
Log In to Comment