diff options
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/APNSManager.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/APNSManager.java b/juick-notifications/src/main/java/com/juick/components/APNSManager.java index c38d1c6f..314a0bd1 100644 --- a/juick-notifications/src/main/java/com/juick/components/APNSManager.java +++ b/juick-notifications/src/main/java/com/juick/components/APNSManager.java @@ -42,6 +42,9 @@ public class APNSManager implements NotificationListener { private String keyId; @Inject private NotificationsManager notificationsManager; + + private ApnsClient sandboxApns; + @PostConstruct public void initialize() throws NoSuchAlgorithmException, InvalidKeyException, IOException { apns = new ApnsClientBuilder() @@ -49,6 +52,11 @@ public class APNSManager implements NotificationListener { .setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(p8key), teamId, keyId)) .build(); + sandboxApns = new ApnsClientBuilder() + .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST) + .setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(p8key), + teamId, keyId)) + .build(); } @Override public void processMessageEvent(MessageEvent messageEvent) { @@ -68,7 +76,9 @@ public class APNSManager implements NotificationListener { String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength(); user.getTokens().stream().filter(t -> t.getType().equals("apns")) .map(ExternalToken::getToken).forEach(token -> { - Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification( + Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = + user.getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> { if (future.isSuccess()) { @@ -104,7 +114,9 @@ public class APNSManager implements NotificationListener { String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength(); user.getTokens().stream().filter(t -> t.getType().equals("apns")) .map(ExternalToken::getToken).forEach(token -> { - Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification( + Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = + user.getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> { if (future.isSuccess()) { @@ -126,7 +138,9 @@ public class APNSManager implements NotificationListener { .addCustomProperty("mid", message.getMid()) .addCustomProperty("uname", message.getUser().getName()) .buildWithDefaultMaximumLength(); - Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification( + Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = + message.getUser().getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> { if (future.isSuccess()) { |