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/APNSManager.java24
-rw-r--r--juick-notifications/src/main/java/com/juick/components/FirebaseManager.java5
-rw-r--r--juick-notifications/src/main/java/com/juick/components/MPNSManager.java5
3 files changed, 34 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();
diff --git a/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java b/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java
index 54e7c97a..24bb43d1 100644
--- a/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java
+++ b/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java
@@ -87,4 +87,9 @@ public class FirebaseManager implements NotificationListener {
public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
}
+
+ @Override
+ public void processTopEvent(TopEvent topEvent) {
+
+ }
}
diff --git a/juick-notifications/src/main/java/com/juick/components/MPNSManager.java b/juick-notifications/src/main/java/com/juick/components/MPNSManager.java
index 56c2df8d..d6c99b0b 100644
--- a/juick-notifications/src/main/java/com/juick/components/MPNSManager.java
+++ b/juick-notifications/src/main/java/com/juick/components/MPNSManager.java
@@ -160,4 +160,9 @@ public class MPNSManager implements NotificationListener {
public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
}
+
+ @Override
+ public void processTopEvent(TopEvent topEvent) {
+
+ }
}