( preparedPushNotifs: $ReadOnlyArray<PreparePushResult>, )
| 530 | } |
| 531 | |
| 532 | async 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 | |
| 586 | async function sendRescindNotifs(rescindInfo: PushInfo) { |
| 587 | if (Object.keys(rescindInfo).length === 0) { |
no test coverage detected