diff options
author | 2018-10-05 01:38:04 +0300 | |
---|---|---|
committer | 2018-10-05 01:38:04 +0300 | |
commit | fe761771ce3cb65b00dc3a826c51b9f20ff6c72d (patch) | |
tree | 7671e1bd31dfc10f10d1110048efc313762c6dfe /juick-notifications/src/main/java/com/juick/components/APNSManager.java | |
parent | a6824b011325df07caf284352f09c2b9f76155c7 (diff) |
TopEvent: Announce in Fediverse, like in XMPP/Telegram
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/APNSManager.java')
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/APNSManager.java | 24 |
1 files changed, 24 insertions, 0 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 c0380847..3eaf3c93 100644 --- a/juick-notifications/src/main/java/com/juick/components/APNSManager.java +++ b/juick-notifications/src/main/java/com/juick/components/APNSManager.java @@ -1,6 +1,7 @@ package com.juick.components; import com.juick.ExternalToken; +import com.juick.Message; import com.juick.User; import com.juick.formatters.PlainTextFormatter; import com.juick.service.component.*; @@ -113,6 +114,29 @@ public class APNSManager implements NotificationListener { }); }); } + + @Override + public void processTopEvent(TopEvent topEvent) { + Message message = topEvent.getMessage(); + ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder(); + message.getUser().getTokens().stream().filter(t -> t.getType().equals("apns")) + .map(ExternalToken::getToken).forEach( token -> { + String payload = apnsPayloadBuilder.setAlertTitle("Top").setAlertBody("Your message became popular!") + .addCustomProperty("mid", message.getMid()) + .addCustomProperty("uname", message.getUser().getName()) + .buildWithDefaultMaximumLength(); + Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)); + notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> { + if (future.isSuccess()) { + processAPNSResponse(token, future.getNow()); + } else { + logger.warn("APNS error ", future.cause()); + } + }); + }); + } + @PreDestroy public void close() { apns.close(); |