diff options
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick/service/Crosspost.java')
-rw-r--r-- | juick-crosspost/src/main/java/com/juick/service/Crosspost.java | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java index a8458439..6bcf7c81 100644 --- a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java +++ b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java @@ -16,8 +16,8 @@ */ package com.juick.service; -import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.Message; +import com.juick.server.component.MessageEvent; import com.juick.util.MessageUtils; import org.apache.commons.codec.CharEncoding; import org.apache.commons.io.IOUtils; @@ -26,11 +26,9 @@ import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationListener; import org.springframework.social.twitter.api.Twitter; import org.springframework.social.twitter.api.impl.TwitterTemplate; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; import javax.inject.Inject; import javax.net.ssl.HttpsURLConnection; @@ -42,7 +40,7 @@ import java.nio.charset.StandardCharsets; /** * @author Ugnich Anton */ -public class Crosspost extends TextWebSocketHandler { +public class Crosspost implements ApplicationListener<MessageEvent> { final static String FBURL = "https://graph.facebook.com/me/feed"; final static String VKURL = "https://api.vk.com/method/wall.post"; @@ -55,12 +53,10 @@ public class Crosspost extends TextWebSocketHandler { private String twitter_consumer_key; @Value("${twitter_consumer_secret:}") private String twitter_consumer_secret; - @Inject - private ObjectMapper jsonMapper; @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - Message msg = jsonMapper.readValue(message.asBytes(), Message.class); + public void onApplicationEvent(MessageEvent event) { + Message msg = event.getMessage(); if (msg.getMid() > 0 && msg.getRid() == 0) { if (StringUtils.isNotEmpty(crosspostService.getTwitterName(msg.getUser().getUid()))) { if (msg.getTags().stream().noneMatch(t -> t.getName().equals("notwitter"))) { |