aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-05-08 23:49:08 +0300
committerGravatar Vitaly Takmazov2018-05-08 23:49:08 +0300
commit6df778ed5299edc18bd65e2af8a5e0ae60b8191c (patch)
treef427971157683e1c534a7b2da7e144e81825890f /juick-notifications/src/main/java/com/juick
parentf9f4115b7baeb9a73b63ecda3397994961071373 (diff)
notifications: add badge counter to APNS payload
Diffstat (limited to 'juick-notifications/src/main/java/com/juick')
-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) {