From fe021e7185c5f55a6fe69004cfd5c0374548ec85 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 24 Oct 2018 19:32:10 +0300 Subject: notifications: development notifications for me --- .../main/java/com/juick/components/APNSManager.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'juick-notifications/src/main/java/com') 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> notification = apns.sendNotification( + Future> notification = + user.getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener) 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> notification = apns.sendNotification( + Future> notification = + user.getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener) future -> { if (future.isSuccess()) { @@ -126,7 +138,9 @@ public class APNSManager implements NotificationListener { .addCustomProperty("mid", message.getMid()) .addCustomProperty("uname", message.getUser().getName()) .buildWithDefaultMaximumLength(); - Future> notification = apns.sendNotification( + Future> notification = + message.getUser().getUid() == 3694 ? sandboxApns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification( new SimpleApnsPushNotification(token, topic, payload)); notification.addListener((PushNotificationResponseListener) future -> { if (future.isSuccess()) { -- cgit v1.2.3