aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/MessengerManager.java
diff options
context:
space:
mode:
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)) {