Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 1,044 Lines • ▼ Show 20 Lines | ): Promise<$ReadOnlyArray<TargetedAPNsNotification>> { | ||||
const notifsWithMessageInfos = await prepareEncryptedAPNsNotifications( | const notifsWithMessageInfos = await prepareEncryptedAPNsNotifications( | ||||
devices, | devices, | ||||
copyWithMessageInfos, | copyWithMessageInfos, | ||||
platformDetails.codeVersion, | platformDetails.codeVersion, | ||||
notificationSizeValidator, | notificationSizeValidator, | ||||
); | ); | ||||
const devicesWithExcessiveSize = notifsWithMessageInfos | const devicesWithExcessiveSizeNoHolders = notifsWithMessageInfos | ||||
.filter(({ payloadSizeExceeded }) => payloadSizeExceeded) | .filter(({ payloadSizeExceeded }) => payloadSizeExceeded) | ||||
.map(({ deviceToken, cookieID }) => ({ deviceToken, cookieID })); | .map(({ deviceToken, cookieID }) => ({ deviceToken, cookieID })); | ||||
if (devicesWithExcessiveSize.length === 0) { | if (devicesWithExcessiveSizeNoHolders.length === 0) { | ||||
return notifsWithMessageInfos.map( | return notifsWithMessageInfos.map( | ||||
({ | ({ | ||||
notification: notif, | notification: notif, | ||||
deviceToken, | deviceToken, | ||||
encryptedPayloadHash, | encryptedPayloadHash, | ||||
encryptionOrder, | encryptionOrder, | ||||
}) => ({ | }) => ({ | ||||
notification: notif, | notification: notif, | ||||
deviceToken, | deviceToken, | ||||
encryptedPayloadHash, | encryptedPayloadHash, | ||||
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( | |||||
copyWithMessageInfos.compile(), | copyWithMessageInfos.compile(), | ||||
devicesWithExcessiveSizeNoHolders.length, | |||||
)); | )); | ||||
} | } | ||||
if (blobUploadError) { | if (blobUploadError) { | ||||
console.warn( | console.warn( | ||||
`Failed to upload payload of notification: ${uniqueID} ` + | `Failed to upload payload of notification: ${uniqueID} ` + | ||||
`due to error: ${blobUploadError}`, | `due to error: ${blobUploadError}`, | ||||
); | ); | ||||
} | } | ||||
if (blobHash && encryptionKey) { | let devicesWithExcessiveSize = devicesWithExcessiveSizeNoHolders; | ||||
if ( | |||||
blobHash && | |||||
encryptionKey && | |||||
blobHolders && | |||||
blobHolders.length === devicesWithExcessiveSize.length | |||||
) { | |||||
notification.payload = { | notification.payload = { | ||||
...notification.payload, | ...notification.payload, | ||||
blobHash, | blobHash, | ||||
encryptionKey, | encryptionKey, | ||||
}; | }; | ||||
devicesWithExcessiveSize = blobHolders.map((holder, idx) => ({ | |||||
...devicesWithExcessiveSize[idx], | |||||
blobHolder: holder, | |||||
})); | |||||
} | } | ||||
const notifsWithoutMessageInfos = await prepareEncryptedAPNsNotifications( | const notifsWithoutMessageInfos = await prepareEncryptedAPNsNotifications( | ||||
devicesWithExcessiveSize, | devicesWithExcessiveSize, | ||||
notification, | notification, | ||||
platformDetails.codeVersion, | platformDetails.codeVersion, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 783 Lines • Show Last 20 Lines |