(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
})
| 199 | }; |
| 200 | |
| 201 | async 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: { |
no test coverage detected