Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show All 19 Lines | import { | ||||
sortMessageInfoList, | sortMessageInfoList, | ||||
} from 'lib/shared/message-utils.js'; | } from 'lib/shared/message-utils.js'; | ||||
import { messageSpecs } from 'lib/shared/messages/message-specs.js'; | import { messageSpecs } from 'lib/shared/messages/message-specs.js'; | ||||
import { notifTextsForMessageInfo } from 'lib/shared/notif-utils.js'; | import { notifTextsForMessageInfo } from 'lib/shared/notif-utils.js'; | ||||
import { | import { | ||||
rawThreadInfoFromServerThreadInfo, | rawThreadInfoFromServerThreadInfo, | ||||
threadInfoFromRawThreadInfo, | threadInfoFromRawThreadInfo, | ||||
} from 'lib/shared/thread-utils.js'; | } from 'lib/shared/thread-utils.js'; | ||||
import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | import { | ||||
hasMinCodeVersion, | |||||
NEXT_CODE_VERSION, | |||||
} from 'lib/shared/version-utils.js'; | |||||
import type { Platform, PlatformDetails } from 'lib/types/device-types.js'; | import type { Platform, PlatformDetails } from 'lib/types/device-types.js'; | ||||
import { messageTypes } from 'lib/types/message-types-enum.js'; | import { messageTypes } from 'lib/types/message-types-enum.js'; | ||||
import { | import { | ||||
type MessageData, | type MessageData, | ||||
type RawMessageInfo, | type RawMessageInfo, | ||||
rawMessageInfoValidator, | rawMessageInfoValidator, | ||||
} from 'lib/types/message-types.js'; | } from 'lib/types/message-types.js'; | ||||
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; | import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; | ||||
Show All 27 Lines | import { | ||||
fcmMaxNotificationPayloadByteSize, | fcmMaxNotificationPayloadByteSize, | ||||
fcmPush, | fcmPush, | ||||
getUnreadCounts, | getUnreadCounts, | ||||
webPush, | webPush, | ||||
type WebPushError, | type WebPushError, | ||||
wnsMaxNotificationPayloadByteSize, | wnsMaxNotificationPayloadByteSize, | ||||
wnsPush, | wnsPush, | ||||
type WNSPushError, | type WNSPushError, | ||||
blobServiceUpload, | |||||
} from './utils.js'; | } from './utils.js'; | ||||
import createIDs from '../creators/id-creator.js'; | import createIDs from '../creators/id-creator.js'; | ||||
import { createUpdates } from '../creators/update-creator.js'; | import { createUpdates } from '../creators/update-creator.js'; | ||||
import { dbQuery, mergeOrConditions, SQL } from '../database/database.js'; | import { dbQuery, mergeOrConditions, SQL } from '../database/database.js'; | ||||
import type { CollapsableNotifInfo } from '../fetchers/message-fetchers.js'; | import type { CollapsableNotifInfo } from '../fetchers/message-fetchers.js'; | ||||
import { fetchCollapsableNotifs } from '../fetchers/message-fetchers.js'; | import { fetchCollapsableNotifs } from '../fetchers/message-fetchers.js'; | ||||
import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | ||||
import { fetchUserInfos } from '../fetchers/user-fetchers.js'; | import { fetchUserInfos } from '../fetchers/user-fetchers.js'; | ||||
▲ Show 20 Lines • Show All 937 Lines • ▼ Show 20 Lines | ) | ||||
? copyWithMessageInfos | ? copyWithMessageInfos | ||||
: notification; | : notification; | ||||
return devices.map(({ deviceToken }) => ({ | return devices.map(({ deviceToken }) => ({ | ||||
notification: notificationToSend, | notification: notificationToSend, | ||||
deviceToken, | deviceToken, | ||||
})); | })); | ||||
} | } | ||||
// The `messageInfos` field in notification payload is | |||||
// not used on MacOS so we can return early. | |||||
if (platformDetails.platform === 'macos') { | |||||
const macOSNotifsWithoutMessageInfos = | |||||
await prepareEncryptedAPNsNotifications( | |||||
devices, | |||||
notification, | |||||
platformDetails.codeVersion, | |||||
); | |||||
return macOSNotifsWithoutMessageInfos.map( | |||||
({ notification: notif, deviceToken }) => ({ | |||||
notification: notif, | |||||
deviceToken, | |||||
}), | |||||
); | |||||
} | |||||
const notifsWithMessageInfos = await prepareEncryptedAPNsNotifications( | const notifsWithMessageInfos = await prepareEncryptedAPNsNotifications( | ||||
devices, | devices, | ||||
copyWithMessageInfos, | copyWithMessageInfos, | ||||
platformDetails.codeVersion, | platformDetails.codeVersion, | ||||
notificationSizeValidator, | notificationSizeValidator, | ||||
); | ); | ||||
const devicesWithExcessiveSize = notifsWithMessageInfos | const devicesWithExcessiveSize = notifsWithMessageInfos | ||||
Show All 11 Lines | return notifsWithMessageInfos.map( | ||||
notification: notif, | notification: notif, | ||||
deviceToken, | deviceToken, | ||||
encryptedPayloadHash, | encryptedPayloadHash, | ||||
encryptionOrder, | encryptionOrder, | ||||
}), | }), | ||||
); | ); | ||||
} | } | ||||
const canQueryBlobService = hasMinCodeVersion(platformDetails, { | |||||
native: NEXT_CODE_VERSION, | |||||
}); | |||||
let blobHash, encryptionKey, blobUploadError; | |||||
if (canQueryBlobService) { | |||||
({ blobHash, encryptionKey, blobUploadError } = await blobServiceUpload( | |||||
copyWithMessageInfos.compile(), | |||||
)); | |||||
} | |||||
if (blobUploadError) { | |||||
console.warn( | |||||
`Failed to upload payload of notification: ${uniqueID} ` + | |||||
`due to error: ${blobUploadError}`, | |||||
); | |||||
} | |||||
if (blobHash && encryptionKey) { | |||||
notification.payload = { | |||||
...notification.payload, | |||||
blobHash, | |||||
encryptionKey, | |||||
}; | |||||
} | |||||
const notifsWithoutMessageInfos = await prepareEncryptedAPNsNotifications( | const notifsWithoutMessageInfos = await prepareEncryptedAPNsNotifications( | ||||
devicesWithExcessiveSize, | devicesWithExcessiveSize, | ||||
notification, | notification, | ||||
platformDetails.codeVersion, | platformDetails.codeVersion, | ||||
); | ); | ||||
const targetedNotifsWithMessageInfos = notifsWithMessageInfos | const targetedNotifsWithMessageInfos = notifsWithMessageInfos | ||||
.filter(({ payloadSizeExceeded }) => !payloadSizeExceeded) | .filter(({ payloadSizeExceeded }) => !payloadSizeExceeded) | ||||
▲ Show 20 Lines • Show All 781 Lines • Show Last 20 Lines |