From 34a943832a3f8db7bca8deb15ff8f1547102b5e3 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 29 Nov 2023 18:05:29 -0500 Subject: [PATCH] Align push notification types and delivery priorities --- .../textsecuregcm/push/APNSender.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/APNSender.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/APNSender.java index 72f7cfa5a..457cc80a5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/APNSender.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/APNSender.java @@ -113,21 +113,28 @@ public class APNSender implements Managed, PushNotificationSender { .build(); }; - final PushType pushType; - - if (isVoip) { - pushType = PushType.VOIP; - } else { - pushType = notification.urgent() ? PushType.ALERT : PushType.BACKGROUND; - } - - final DeliveryPriority deliveryPriority = switch (notification.notificationType()) { - case NOTIFICATION -> - (notification.urgent() || isVoip) ? DeliveryPriority.IMMEDIATE : DeliveryPriority.CONSERVE_POWER; - case ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY -> DeliveryPriority.IMMEDIATE; - case CHALLENGE, RATE_LIMIT_CHALLENGE -> DeliveryPriority.CONSERVE_POWER; + final PushType pushType = switch (notification.notificationType()) { + case NOTIFICATION -> { + if (isVoip) { + yield PushType.VOIP; + } else { + yield notification.urgent() ? PushType.ALERT : PushType.BACKGROUND; + } + } + case ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY -> PushType.ALERT; + case CHALLENGE, RATE_LIMIT_CHALLENGE -> PushType.BACKGROUND; }; + final DeliveryPriority deliveryPriority; + + if (pushType == PushType.BACKGROUND) { + deliveryPriority = DeliveryPriority.CONSERVE_POWER; + } else { + deliveryPriority = (notification.urgent() || isVoip) + ? DeliveryPriority.IMMEDIATE + : DeliveryPriority.CONSERVE_POWER; + } + final String collapseId = (notification.notificationType() == PushNotification.NotificationType.NOTIFICATION && notification.urgent() && !isVoip) ? "incoming-message" : null;