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

Function deliverPushNotifsInEncryptionOrder

keyserver/src/push/send.js:532–584  ·  view source on GitHub ↗
(
  preparedPushNotifs: $ReadOnlyArray<PreparePushResult>,
)

Source from the content-addressed store, hash-verified

530}
531
532async function deliverPushNotifsInEncryptionOrder(
533 preparedPushNotifs: $ReadOnlyArray<PreparePushResult>,
534): Promise<$ReadOnlyArray<PushResult>> {
535 const deliveryPromises: Array<Promise<$ReadOnlyArray<PushResult>>> = [];
536
537 const groupedByDevice = _groupBy(
538 preparedPushNotif => preparedPushNotif.deviceToken,
539 )(preparedPushNotifs);
540
541 for (const preparedPushNotifsForDevice of values(groupedByDevice)) {
542 const orderedPushNotifsForDevice = preparedPushNotifsForDevice.sort(
543 compareEncryptionOrder,
544 );
545
546 const deviceDeliveryPromise = (async () => {
547 const deliveries = [];
548 for (const preparedPushNotif of orderedPushNotifsForDevice) {
549 const { platform, notification, notificationInfo } = preparedPushNotif;
550 let delivery: PushResult;
551 if (platform === 'ios' || platform === 'macos') {
552 delivery = await sendAPNsNotification(
553 platform,
554 [notification],
555 notificationInfo,
556 );
557 } else if (platform === 'android') {
558 delivery = await sendAndroidNotification(
559 [notification],
560 notificationInfo,
561 );
562 } else if (platform === 'web') {
563 delivery = await sendWebNotifications(
564 [notification],
565 notificationInfo,
566 );
567 } else if (platform === 'windows') {
568 delivery = await sendWNSNotification(
569 [notification],
570 notificationInfo,
571 );
572 }
573 if (delivery) {
574 deliveries.push(delivery);
575 }
576 }
577 return deliveries;
578 })();
579 deliveryPromises.push(deviceDeliveryPromise);
580 }
581
582 const deliveryResults = await Promise.all(deliveryPromises);
583 return deliveryResults.flat();
584}
585
586async function sendRescindNotifs(rescindInfo: PushInfo) {
587 if (Object.keys(rescindInfo).length === 0) {

Callers 2

sendPushNotifsFunction · 0.85
updateBadgeCountFunction · 0.85

Calls 6

valuesFunction · 0.90
sendAPNsNotificationFunction · 0.85
sendAndroidNotificationFunction · 0.85
sendWebNotificationsFunction · 0.85
sendWNSNotificationFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected