Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | for (const notifInfo of usersToCollapsableNotifInfo[userID]) { | ||||
if (iosVersionsToTokens) { | if (iosVersionsToTokens) { | ||||
for (const [codeVer, deviceTokens] of iosVersionsToTokens) { | for (const [codeVer, deviceTokens] of iosVersionsToTokens) { | ||||
const codeVersion = parseInt(codeVer, 10); // only for Flow | const codeVersion = parseInt(codeVer, 10); // only for Flow | ||||
const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( | const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( | ||||
newRawMessageInfos, | newRawMessageInfos, | ||||
{ platform: 'ios', codeVersion }, | { platform: 'ios', codeVersion }, | ||||
); | ); | ||||
const deliveryPromise = (async () => { | const deliveryPromise = (async () => { | ||||
const notification = await prepareIOSNotification( | const notification = await prepareIOSNotification({ | ||||
allMessageInfos, | allMessageInfos, | ||||
shimmedNewRawMessageInfos, | newRawMessageInfos: shimmedNewRawMessageInfos, | ||||
threadInfo, | threadInfo, | ||||
notifInfo.collapseKey, | collapseKey: notifInfo.collapseKey, | ||||
badgeOnly, | badgeOnly, | ||||
unreadCounts[userID], | unreadCount: unreadCounts[userID], | ||||
codeVersion, | codeVersion, | ||||
); | }); | ||||
return await sendIOSNotification(notification, [...deviceTokens], { | return await sendIOSNotification(notification, [...deviceTokens], { | ||||
...notificationInfo, | ...notificationInfo, | ||||
codeVersion, | codeVersion, | ||||
}); | }); | ||||
})(); | })(); | ||||
deliveryPromises.push(deliveryPromise); | deliveryPromises.push(deliveryPromise); | ||||
} | } | ||||
} | } | ||||
const androidVersionsToTokens = byDeviceType.get('android'); | const androidVersionsToTokens = byDeviceType.get('android'); | ||||
if (androidVersionsToTokens) { | if (androidVersionsToTokens) { | ||||
for (const [codeVer, deviceTokens] of androidVersionsToTokens) { | for (const [codeVer, deviceTokens] of androidVersionsToTokens) { | ||||
const codeVersion = parseInt(codeVer, 10); // only for Flow | const codeVersion = parseInt(codeVer, 10); // only for Flow | ||||
const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( | const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( | ||||
newRawMessageInfos, | newRawMessageInfos, | ||||
{ platform: 'android', codeVersion }, | { platform: 'android', codeVersion }, | ||||
); | ); | ||||
const deliveryPromise = (async () => { | const deliveryPromise = (async () => { | ||||
const notification = await prepareAndroidNotification( | const notification = await prepareAndroidNotification({ | ||||
allMessageInfos, | allMessageInfos, | ||||
shimmedNewRawMessageInfos, | newRawMessageInfos: shimmedNewRawMessageInfos, | ||||
threadInfo, | threadInfo, | ||||
notifInfo.collapseKey, | collapseKey: notifInfo.collapseKey, | ||||
badgeOnly, | badgeOnly, | ||||
unreadCounts[userID], | unreadCount: unreadCounts[userID], | ||||
dbID, | |||||
codeVersion, | codeVersion, | ||||
); | dbID, | ||||
}); | |||||
return await sendAndroidNotification( | return await sendAndroidNotification( | ||||
notification, | notification, | ||||
[...deviceTokens], | [...deviceTokens], | ||||
{ | { | ||||
...notificationInfo, | ...notificationInfo, | ||||
codeVersion, | codeVersion, | ||||
}, | }, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | if (!innerMostSet) { | ||||
innerMostSet = new Set(); | innerMostSet = new Set(); | ||||
innerMap.set(codeVersion, innerMostSet); | innerMap.set(codeVersion, innerMostSet); | ||||
} | } | ||||
innerMostSet.add(device.deviceToken); | innerMostSet.add(device.deviceToken); | ||||
} | } | ||||
return byDeviceType; | return byDeviceType; | ||||
} | } | ||||
type IOSNotifInputData = { | |||||
+allMessageInfos: MessageInfo[], | |||||
+newRawMessageInfos: RawMessageInfo[], | |||||
+threadInfo: ThreadInfo, | |||||
+collapseKey: ?string, | |||||
+badgeOnly: boolean, | |||||
+unreadCount: number, | |||||
+codeVersion: number, | |||||
}; | |||||
async function prepareIOSNotification( | async function prepareIOSNotification( | ||||
allMessageInfos: MessageInfo[], | inputData: IOSNotifInputData, | ||||
newRawMessageInfos: RawMessageInfo[], | |||||
threadInfo: ThreadInfo, | |||||
collapseKey: ?string, | |||||
badgeOnly: boolean, | |||||
unreadCount: number, | |||||
codeVersion: number, | |||||
): Promise<apn.Notification> { | ): Promise<apn.Notification> { | ||||
const { | |||||
allMessageInfos, | |||||
newRawMessageInfos, | |||||
threadInfo, | |||||
collapseKey, | |||||
badgeOnly, | |||||
unreadCount, | |||||
codeVersion, | |||||
} = inputData; | |||||
const uniqueID = uuidv4(); | const uniqueID = uuidv4(); | ||||
const notification = new apn.Notification(); | const notification = new apn.Notification(); | ||||
notification.topic = getAPNsNotificationTopic(codeVersion); | notification.topic = getAPNsNotificationTopic(codeVersion); | ||||
const { merged, ...rest } = await notifTextsForMessageInfo( | const { merged, ...rest } = await notifTextsForMessageInfo( | ||||
allMessageInfos, | allMessageInfos, | ||||
threadInfo, | threadInfo, | ||||
getENSNames, | getENSNames, | ||||
Show All 37 Lines | ): Promise<apn.Notification> { | ||||
if (notificationCopy.length() > apnMaxNotificationPayloadByteSize) { | if (notificationCopy.length() > apnMaxNotificationPayloadByteSize) { | ||||
console.warn( | console.warn( | ||||
`iOS notification ${uniqueID} exceeds size limit, even with messageInfos omitted`, | `iOS notification ${uniqueID} exceeds size limit, even with messageInfos omitted`, | ||||
); | ); | ||||
} | } | ||||
return notification; | return notification; | ||||
} | } | ||||
type AndroidNotifInputData = { | |||||
...IOSNotifInputData, | |||||
+dbID: string, | |||||
}; | |||||
async function prepareAndroidNotification( | async function prepareAndroidNotification( | ||||
allMessageInfos: MessageInfo[], | inputData: AndroidNotifInputData, | ||||
newRawMessageInfos: RawMessageInfo[], | |||||
threadInfo: ThreadInfo, | |||||
collapseKey: ?string, | |||||
badgeOnly: boolean, | |||||
unreadCount: number, | |||||
dbID: string, | |||||
codeVersion: number, | |||||
): Promise<Object> { | ): Promise<Object> { | ||||
const { | |||||
allMessageInfos, | |||||
newRawMessageInfos, | |||||
threadInfo, | |||||
collapseKey, | |||||
badgeOnly, | |||||
unreadCount, | |||||
codeVersion, | |||||
dbID, | |||||
} = inputData; | |||||
const notifID = collapseKey ? collapseKey : dbID; | const notifID = collapseKey ? collapseKey : dbID; | ||||
const { merged, ...rest } = await notifTextsForMessageInfo( | const { merged, ...rest } = await notifTextsForMessageInfo( | ||||
allMessageInfos, | allMessageInfos, | ||||
threadInfo, | threadInfo, | ||||
getENSNames, | getENSNames, | ||||
); | ); | ||||
const notification = { | const notification = { | ||||
data: { | data: { | ||||
▲ Show 20 Lines • Show All 289 Lines • Show Last 20 Lines |