Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 994 Lines • ▼ Show 20 Lines | ) { | ||||
})); | })); | ||||
const byPlatform = getDevicesByPlatform(devices); | const byPlatform = getDevicesByPlatform(devices); | ||||
const deliveryPromises = []; | const deliveryPromises = []; | ||||
const iosVersionsToTokens = byPlatform.get('ios'); | const iosVersionsToTokens = byPlatform.get('ios'); | ||||
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 | ||||
ashoat: Can we delete this? | |||||
const notification = new apn.Notification(); | const notification = new apn.Notification(); | ||||
notification.topic = getAPNsNotificationTopic({ | notification.topic = getAPNsNotificationTopic({ | ||||
platform: 'ios', | platform: 'ios', | ||||
codeVersion, | codeVersion, | ||||
}); | }); | ||||
notification.badge = unreadCount; | notification.badge = unreadCount; | ||||
notification.pushType = 'alert'; | notification.pushType = 'alert'; | ||||
deliveryPromises.push( | deliveryPromises.push( | ||||
sendAPNsNotification('ios', notification, [...deviceTokens], { | sendAPNsNotification('ios', notification, [...deviceTokens], { | ||||
source, | source, | ||||
dbID, | dbID, | ||||
userID, | userID, | ||||
codeVersion, | codeVersion, | ||||
}), | }), | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
const androidVersionsToTokens = byPlatform.get('android'); | const androidVersionsToTokens = byPlatform.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 | ||||
ashoatUnsubmitted Not Done Inline ActionsCan we delete this? ashoat: Can we delete this? | |||||
const notificationData = | const notificationData = | ||||
codeVersion < 69 | codeVersion < 69 | ||||
? { badge: unreadCount.toString() } | ? { badge: unreadCount.toString() } | ||||
: { badge: unreadCount.toString(), badgeOnly: '1' }; | : { badge: unreadCount.toString(), badgeOnly: '1' }; | ||||
const notification = { data: notificationData }; | const notification = { data: notificationData }; | ||||
deliveryPromises.push( | deliveryPromises.push( | ||||
sendAndroidNotification(notification, [...deviceTokens], { | sendAndroidNotification(notification, [...deviceTokens], { | ||||
source, | source, | ||||
dbID, | dbID, | ||||
userID, | userID, | ||||
codeVersion, | codeVersion, | ||||
}), | }), | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
const macosVersionsToTokens = byPlatform.get('macos'); | |||||
if (macosVersionsToTokens) { | |||||
for (const [codeVersion, deviceTokens] of macosVersionsToTokens) { | |||||
const notification = new apn.Notification(); | |||||
notification.topic = getAPNsNotificationTopic({ | |||||
platform: 'macos', | |||||
codeVersion, | |||||
}); | |||||
notification.badge = unreadCount; | |||||
notification.pushType = 'alert'; | |||||
deliveryPromises.push( | |||||
sendAPNsNotification('macos', notification, [...deviceTokens], { | |||||
source, | |||||
dbID, | |||||
userID, | |||||
codeVersion, | |||||
}), | |||||
); | |||||
} | |||||
} | |||||
const deliveryResults = await Promise.all(deliveryPromises); | const deliveryResults = await Promise.all(deliveryPromises); | ||||
await saveNotifResults(deliveryResults, new Map(), false); | await saveNotifResults(deliveryResults, new Map(), false); | ||||
} | } | ||||
export { sendPushNotifs, sendRescindNotifs, updateBadgeCount }; | export { sendPushNotifs, sendRescindNotifs, updateBadgeCount }; |
Can we delete this?