aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/APNSManager.java
diff options
context:
space:
mode:
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.java24
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();