MCPcopy Create free account
hub / github.com/CommE2E/comm / encryptAndroidVisualNotification

Function encryptAndroidVisualNotification

lib/push/crypto.js:273–331  ·  view source on GitHub ↗
(
  encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI,
  senderDeviceDescriptor: SenderDeviceDescriptor,
  cryptoID: string,
  notification: AndroidVisualNotification,
  isNotificationSizeValid?: AndroidVisualNotification => boolean,
  blobHolder?: ?string,
)

Source from the content-addressed store, hash-verified

271}
272
273async function encryptAndroidVisualNotification(
274 encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI,
275 senderDeviceDescriptor: SenderDeviceDescriptor,
276 cryptoID: string,
277 notification: AndroidVisualNotification,
278 isNotificationSizeValid?: AndroidVisualNotification => boolean,
279 blobHolder?: ?string,
280): Promise<{
281 +notification: AndroidVisualNotification,
282 +payloadSizeExceeded: boolean,
283 +encryptionOrder?: number,
284}> {
285 const { id, ...rest } = notification.data;
286
287 let unencryptedData = {};
288 if (id) {
289 unencryptedData = { id };
290 }
291
292 let unencryptedPayload = rest;
293 if (blobHolder) {
294 unencryptedPayload = { ...unencryptedPayload, blobHolder };
295 }
296
297 let isPayloadSizeValid;
298 if (isNotificationSizeValid) {
299 isPayloadSizeValid = (
300 payload:
301 | AndroidVisualNotificationPayload
302 | $ReadOnly<{
303 ...SenderDeviceDescriptor,
304 +encryptedPayload: string,
305 +type: '0' | '1',
306 }>,
307 ) => {
308 return isNotificationSizeValid({
309 data: { ...unencryptedData, ...payload },
310 });
311 };
312 }
313 const { resultPayload, payloadSizeExceeded, encryptionOrder } =
314 await encryptAndroidNotificationPayload(
315 encryptedNotifUtilsAPI,
316 cryptoID,
317 senderDeviceDescriptor,
318 unencryptedPayload,
319 isPayloadSizeValid,
320 );
321 return {
322 notification: {
323 data: {
324 ...unencryptedData,
325 ...resultPayload,
326 },
327 },
328 payloadSizeExceeded,
329 encryptionOrder,
330 };

Calls 2

isNotificationSizeValidFunction · 0.85

Tested by

no test coverage detected