Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 499 Lines • ▼ Show 20 Lines | ): apn.Notification { | ||||
notification.payload.threadID = threadInfo.id; | notification.payload.threadID = threadInfo.id; | ||||
if (codeVersion > 1000) { | if (codeVersion > 1000) { | ||||
notification.mutableContent = true; | notification.mutableContent = true; | ||||
} | } | ||||
if (collapseKey) { | if (collapseKey) { | ||||
notification.collapseId = collapseKey; | notification.collapseId = collapseKey; | ||||
} | } | ||||
const messageInfos = JSON.stringify(newRawMessageInfos); | const messageInfos = JSON.stringify(newRawMessageInfos); | ||||
// We make a copy before checking notification's length, because calling | |||||
// length compiles the notification and makes it immutable. Further | |||||
// changes to its properties won't be reflected in the final plaintext | |||||
// data that is sent. | |||||
const copyWithMessageInfos = _cloneDeep(notification); | const copyWithMessageInfos = _cloneDeep(notification); | ||||
copyWithMessageInfos.payload = { | copyWithMessageInfos.payload = { | ||||
...copyWithMessageInfos.payload, | ...copyWithMessageInfos.payload, | ||||
messageInfos, | messageInfos, | ||||
}; | }; | ||||
if (copyWithMessageInfos.length() <= apnMaxNotificationPayloadByteSize) { | if (copyWithMessageInfos.length() <= apnMaxNotificationPayloadByteSize) { | ||||
notification.payload.messageInfos = messageInfos; | notification.payload.messageInfos = messageInfos; | ||||
return notification; | |||||
} | |||||
const notificationCopy = _cloneDeep(notification); | |||||
if (notificationCopy.length() > apnMaxNotificationPayloadByteSize) { | |||||
console.warn( | |||||
`iOS notification ${uniqueID} exceeds size limit, even with messageInfos omitted`, | |||||
); | |||||
} | } | ||||
return notification; | return notification; | ||||
} | } | ||||
function prepareAndroidNotification( | function prepareAndroidNotification( | ||||
allMessageInfos: MessageInfo[], | allMessageInfos: MessageInfo[], | ||||
newRawMessageInfos: RawMessageInfo[], | newRawMessageInfos: RawMessageInfo[], | ||||
threadInfo: ThreadInfo, | threadInfo: ThreadInfo, | ||||
Show All 37 Lines | ): Object { | ||||
}; | }; | ||||
if ( | if ( | ||||
Buffer.byteLength(JSON.stringify(copyWithMessageInfos)) <= | Buffer.byteLength(JSON.stringify(copyWithMessageInfos)) <= | ||||
fcmMaxNotificationPayloadByteSize | fcmMaxNotificationPayloadByteSize | ||||
) { | ) { | ||||
return copyWithMessageInfos; | return copyWithMessageInfos; | ||||
} | } | ||||
if ( | |||||
Buffer.byteLength(JSON.stringify(notification)) > | |||||
fcmMaxNotificationPayloadByteSize | |||||
) { | |||||
console.warn( | |||||
`Android notification ${notifID} exceeds size limit, even with messageInfos omitted`, | |||||
); | |||||
} | |||||
return notification; | return notification; | ||||
} | } | ||||
type NotificationInfo = | type NotificationInfo = | ||||
| { | | { | ||||
+source: 'new_message', | +source: 'new_message', | ||||
+dbID: string, | +dbID: string, | ||||
+userID: string, | +userID: string, | ||||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |