From 3bbaae4589de56da9ab09360aa28a3cd12198471 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 9 Oct 2018 14:29:47 +0300 Subject: MessageReadEvent refactoring --- .../java/com/juick/components/APNSManager.java | 28 ++++++++++------------ .../com/juick/components/NotificationsManager.java | 4 +++- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'juick-notifications/src/main/java') 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 3eaf3c93..2c7cfce4 100644 --- a/juick-notifications/src/main/java/com/juick/components/APNSManager.java +++ b/juick-notifications/src/main/java/com/juick/components/APNSManager.java @@ -95,22 +95,20 @@ public class APNSManager implements NotificationListener { @Override public void processMessageReadEvent(MessageReadEvent messageReadEvent) { - List users = messageReadEvent.getUsers(); + User user = messageReadEvent.getUser(); ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder(); - users.forEach(user -> { - apnsPayloadBuilder.setBadgeNumber(user.getUnreadCount()); - String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength(); - user.getTokens().stream().filter(t -> t.getType().equals("apns")) - .map(ExternalToken::getToken).forEach(token -> { - Future> notification = apns.sendNotification( - new SimpleApnsPushNotification(token, topic, payload)); - notification.addListener((PushNotificationResponseListener) future -> { - if (future.isSuccess()) { - processAPNSResponse(token, future.getNow()); - } else { - logger.warn("APNS error ", future.cause()); - } - }); + apnsPayloadBuilder.setBadgeNumber(user.getUnreadCount()); + String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength(); + user.getTokens().stream().filter(t -> t.getType().equals("apns")) + .map(ExternalToken::getToken).forEach(token -> { + Future> notification = apns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)); + notification.addListener((PushNotificationResponseListener) future -> { + if (future.isSuccess()) { + processAPNSResponse(token, future.getNow()); + } else { + logger.warn("APNS error ", future.cause()); + } }); }); } diff --git a/juick-notifications/src/main/java/com/juick/components/NotificationsManager.java b/juick-notifications/src/main/java/com/juick/components/NotificationsManager.java index be97ea40..fce0bed7 100644 --- a/juick-notifications/src/main/java/com/juick/components/NotificationsManager.java +++ b/juick-notifications/src/main/java/com/juick/components/NotificationsManager.java @@ -103,7 +103,9 @@ public class NotificationsManager extends TextWebSocketHandler { jmsg.getUser().getUid()), HttpMethod.GET, null, new ParameterizedTypeReference>() { }).getBody(); - applicationEventPublisher.publishEvent(new MessageReadEvent(this, users, jmsg)); + users.forEach(user -> { + applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, jmsg)); + }); } public void addInvalidGCMToken(String token) { -- cgit v1.2.3