MCPcopy Create free account
hub / github.com/CommE2E/comm / preparePushNotif

Function preparePushNotif

keyserver/src/push/send.js:201–519  ·  view source on GitHub ↗
(input: {
  keyserverID: string,
  notifInfo: CollapsableNotifInfo,
  userID: string,
  pushUserInfo: PushUserInfo,
  unreadCount: number,
  threadInfos: {
    +[threadID: string]: ThreadInfo,
  },
  userInfos: { +[userID: string]: GlobalUserInfo },
  dbIDs: string[], // mutable
  rowsToSave: Map<string, NotificationRow>, // mutable
})

Source from the content-addressed store, hash-verified

199};
200
201async function preparePushNotif(input: {
202 keyserverID: string,
203 notifInfo: CollapsableNotifInfo,
204 userID: string,
205 pushUserInfo: PushUserInfo,
206 unreadCount: number,
207 threadInfos: {
208 +[threadID: string]: ThreadInfo,
209 },
210 userInfos: { +[userID: string]: GlobalUserInfo },
211 dbIDs: string[], // mutable
212 rowsToSave: Map<string, NotificationRow>, // mutable
213}): Promise<?$ReadOnlyArray<PreparePushResult>> {
214 const {
215 keyserverID,
216 notifInfo,
217 userID,
218 pushUserInfo,
219 unreadCount,
220 threadInfos,
221 userInfos,
222 dbIDs,
223 rowsToSave,
224 } = input;
225
226 const hydrateMessageInfo = (rawMessageInfo: RawMessageInfo) =>
227 createMessageInfo(rawMessageInfo, userID, userInfos, threadInfos);
228 const newMessageInfos = [];
229 const newRawMessageInfos = [];
230 for (const newRawMessageInfo of notifInfo.newMessageInfos) {
231 const newMessageInfo = hydrateMessageInfo(newRawMessageInfo);
232 if (newMessageInfo) {
233 newMessageInfos.push(newMessageInfo);
234 newRawMessageInfos.push(newRawMessageInfo);
235 }
236 }
237 if (newMessageInfos.length === 0) {
238 return null;
239 }
240 const existingMessageInfos = notifInfo.existingMessageInfos
241 .map(hydrateMessageInfo)
242 .filter(Boolean);
243 const allMessageInfos = sortMessageInfoList([
244 ...newMessageInfos,
245 ...existingMessageInfos,
246 ]);
247 const [firstNewMessageInfo, ...remainingNewMessageInfos] = newMessageInfos;
248 const { threadID } = firstNewMessageInfo;
249
250 const threadInfo = threadInfos[threadID];
251 const parentThreadInfo = threadInfo.parentThreadID
252 ? threadInfos[threadInfo.parentThreadID]
253 : null;
254
255 const username = userInfos[userID] && userInfos[userID].username;
256
257 const { notifAllowed, badgeOnly } = await userAllowsNotif({
258 subscription: {

Callers 1

sendPushNotifsFunction · 0.85

Calls 14

sortMessageInfoListFunction · 0.90
userAllowsNotifFunction · 0.90
notifTextsForMessageInfoFunction · 0.90
getDevicesByPlatformFunction · 0.90
stringToVersionKeyFunction · 0.90
prepareAPNsNotificationFunction · 0.85
prepareWebNotificationFunction · 0.85
prepareWNSNotificationFunction · 0.85
pushMethod · 0.80
hydrateMessageInfoFunction · 0.70

Tested by

no test coverage detected