aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/MessengerManager.java
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-server/src/main/java/com/juick/server/MessengerManager.java
parenta6824b011325df07caf284352f09c2b9f76155c7 (diff)
TopEvent: Announce in Fediverse, like in XMPP/Telegram
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/MessengerManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/MessengerManager.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/MessengerManager.java b/juick-server/src/main/java/com/juick/server/MessengerManager.java
index 90c58f03..96320b3b 100644
--- a/juick-server/src/main/java/com/juick/server/MessengerManager.java
+++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java
@@ -27,7 +27,9 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
@@ -54,6 +56,8 @@ public class MessengerManager implements NotificationListener {
private MessengerService messengerService;
@Inject
private CommandsManager commandsManager;
+ @Inject
+ private FacebookPageManager facebookPageManager;
@Value("${fb_page_access_token:12345678}")
private String facebookPageAccessToken;
@@ -145,6 +149,20 @@ public class MessengerManager implements NotificationListener {
}
+ @Override
+ public void processTopEvent(TopEvent topEvent) {
+ Message jmsg = topEvent.getMessage();
+ String status = MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText());
+ String link = "https://juick.com/m/" + jmsg.getMid();
+ try {
+ facebookPageManager.post(status, link);
+ } catch (HttpClientErrorException ex) {
+ HttpStatus statusCode = ex.getStatusCode();
+ String responseString = ex.getResponseBodyAsString();
+ logger.warn("facebook error {}: {}", statusCode.value(), responseString);
+ }
+ }
+
private void messengerNotify(String messengerUser, String text, String url) {
try {
if (!StringUtils.isEmpty(url)) {