aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-05 01:38:04 +0300
committerGravatar Vitaly Takmazov2018-10-05 01:38:04 +0300
commitfe761771ce3cb65b00dc3a826c51b9f20ff6c72d (patch)
tree7671e1bd31dfc10f10d1110048efc313762c6dfe /juick-notifications
parenta6824b011325df07caf284352f09c2b9f76155c7 (diff)
TopEvent: Announce in Fediverse, like in XMPP/Telegram
Diffstat (limited to 'juick-notifications')
-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) {
+
+ }
}