Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 1,261 Lines • ▼ Show 20 Lines | ): Promise<$ReadOnlyArray<TargetedAndroidNotification>> { | ||||
}; | }; | ||||
const notifsWithMessageInfos = await prepareEncryptedAndroidNotifications( | const notifsWithMessageInfos = await prepareEncryptedAndroidNotifications( | ||||
devices, | devices, | ||||
copyWithMessageInfos, | copyWithMessageInfos, | ||||
notificationsSizeValidator, | notificationsSizeValidator, | ||||
); | ); | ||||
const devicesWithExcessiveSize = notifsWithMessageInfos | const devicesWithExcessiveSizeNoHolders = notifsWithMessageInfos | ||||
.filter(({ payloadSizeExceeded }) => payloadSizeExceeded) | .filter(({ payloadSizeExceeded }) => payloadSizeExceeded) | ||||
.map(({ cookieID, deviceToken }) => ({ cookieID, deviceToken })); | .map(({ cookieID, deviceToken }) => ({ cookieID, deviceToken })); | ||||
if (devicesWithExcessiveSize.length === 0) { | if (devicesWithExcessiveSizeNoHolders.length === 0) { | ||||
return notifsWithMessageInfos.map( | return notifsWithMessageInfos.map( | ||||
({ notification: notif, deviceToken, encryptionOrder }) => ({ | ({ notification: notif, deviceToken, encryptionOrder }) => ({ | ||||
notification: notif, | notification: notif, | ||||
deviceToken, | deviceToken, | ||||
encryptionOrder, | encryptionOrder, | ||||
}), | }), | ||||
); | ); | ||||
} | } | ||||
const canQueryBlobService = hasMinCodeVersion(platformDetails, { | const canQueryBlobService = hasMinCodeVersion(platformDetails, { | ||||
native: NEXT_CODE_VERSION, | native: NEXT_CODE_VERSION, | ||||
}); | }); | ||||
let blobHash, encryptionKey, blobUploadError; | let blobHash, blobHolders, encryptionKey, blobUploadError; | ||||
if (canQueryBlobService) { | if (canQueryBlobService) { | ||||
({ blobHash, encryptionKey, blobUploadError } = await blobServiceUpload( | ({ blobHash, blobHolders, encryptionKey, blobUploadError } = | ||||
await blobServiceUpload( | |||||
JSON.stringify(copyWithMessageInfos.data), | JSON.stringify(copyWithMessageInfos.data), | ||||
1, | devicesWithExcessiveSizeNoHolders.length, | ||||
)); | )); | ||||
} | } | ||||
if (blobUploadError) { | if (blobUploadError) { | ||||
console.warn( | console.warn( | ||||
`Failed to upload payload of notification: ${notifID} ` + | `Failed to upload payload of notification: ${notifID} ` + | ||||
`due to error: ${blobUploadError}`, | `due to error: ${blobUploadError}`, | ||||
); | ); | ||||
} | } | ||||
if (blobHash && encryptionKey) { | let devicesWithExcessiveSize = devicesWithExcessiveSizeNoHolders; | ||||
if ( | |||||
blobHash && | |||||
encryptionKey && | |||||
blobHolders && | |||||
blobHolders.length === devicesWithExcessiveSizeNoHolders.length | |||||
) { | |||||
notification.data = { | notification.data = { | ||||
...notification.data, | ...notification.data, | ||||
blobHash, | blobHash, | ||||
encryptionKey, | encryptionKey, | ||||
}; | }; | ||||
devicesWithExcessiveSize = blobHolders.map((holder, idx) => ({ | |||||
...devicesWithExcessiveSize[idx], | |||||
blobHolder: holder, | |||||
})); | |||||
} | } | ||||
const notifsWithoutMessageInfos = await prepareEncryptedAndroidNotifications( | const notifsWithoutMessageInfos = await prepareEncryptedAndroidNotifications( | ||||
devicesWithExcessiveSize, | devicesWithExcessiveSize, | ||||
notification, | notification, | ||||
); | ); | ||||
const targetedNotifsWithMessageInfos = notifsWithMessageInfos | const targetedNotifsWithMessageInfos = notifsWithMessageInfos | ||||
▲ Show 20 Lines • Show All 616 Lines • Show Last 20 Lines |