From fe761771ce3cb65b00dc3a826c51b9f20ff6c72d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 5 Oct 2018 01:38:04 +0300 Subject: TopEvent: Announce in Fediverse, like in XMPP/Telegram --- .../java/com/juick/components/APNSManager.java | 24 ++++++++++++++++++++++ .../java/com/juick/components/FirebaseManager.java | 5 +++++ .../java/com/juick/components/MPNSManager.java | 5 +++++ 3 files changed, 34 insertions(+) (limited to 'juick-notifications/src/main/java/com/juick') 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> notification = apns.sendNotification( + new SimpleApnsPushNotification(token, topic, payload)); + notification.addListener((PushNotificationResponseListener) 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) { + + } } -- cgit v1.2.3