aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-notifications/src/main/java')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java28
1 files changed, 13 insertions, 15 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index 9f62fd4d..ea5362c1 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -182,17 +182,17 @@ public class Notifications extends TextWebSocketHandler implements NotificationC
}
/*** iOS ***/
- List<String> tokens = users.stream().flatMap(u -> u.getTokens().stream()).filter(d -> d.getType().equals("apns"))
- .map(ExternalToken::getToken).collect(Collectors.toList());
- if (!tokens.isEmpty()) {
- ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
- apnsPayloadBuilder.addCustomProperty("mid", jmsg.getMid());
- apnsPayloadBuilder.addCustomProperty("uname", jmsg.getUser().getName());
- String post = PlainTextFormatter.formatPost(jmsg);
- String[] parts = post.split("\n", 2);
- String payload = apnsPayloadBuilder.setAlertTitle(parts[0])
- .setAlertBody(parts[1]).buildWithDefaultMaximumLength();
- for (String token : tokens) {
+ ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
+ apnsPayloadBuilder.addCustomProperty("mid", jmsg.getMid());
+ apnsPayloadBuilder.addCustomProperty("uname", jmsg.getUser().getName());
+ String post = PlainTextFormatter.formatPost(jmsg);
+ String[] parts = post.split("\n", 2);
+ apnsPayloadBuilder.setAlertTitle(parts[0]).setAlertBody(parts[1]);
+ 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 -> {
final Future<PushNotificationResponse<SimpleApnsPushNotification>> notification
= apns.sendNotification(new SimpleApnsPushNotification(token, topic, payload));
try {
@@ -210,10 +210,8 @@ public class Notifications extends TextWebSocketHandler implements NotificationC
} catch (final ExecutionException | InterruptedException ex) {
logger.info("APNS exception", ex);
}
- }
- } else {
- logger.info("APNS: no recipients");
- }
+ });
+ });
}
public void addInvalidGCMToken(String token) {