aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/TopManager.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/TopManager.java
parenta6824b011325df07caf284352f09c2b9f76155c7 (diff)
TopEvent: Announce in Fediverse, like in XMPP/Telegram
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/TopManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/TopManager.java28
1 files changed, 4 insertions, 24 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TopManager.java b/juick-server/src/main/java/com/juick/server/TopManager.java
index e6c22533..a9157841 100644
--- a/juick-server/src/main/java/com/juick/server/TopManager.java
+++ b/juick-server/src/main/java/com/juick/server/TopManager.java
@@ -22,11 +22,13 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
+import com.juick.service.component.TopEvent;
import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -43,21 +45,9 @@ public class TopManager {
@Inject
private MessagesService messagesService;
@Inject
- private FacebookPageManager facebookPageManager;
+ private ApplicationEventPublisher applicationEventPublisher;
@Inject
private TwitterManager twitterManager;
- @Inject
- private UserService userService;
-
- @Value("${service_user:juick}")
- private String serviceUsername;
-
- private User serviceUser;
-
- @PostConstruct
- public void init() {
- serviceUser = userService.getUserByName(serviceUsername);
- }
@Scheduled(fixedRate = 3600000)
public void updateTop() {
@@ -67,17 +57,7 @@ public class TopManager {
messagesService.setMessagePopular(m, 1);
List<String> tags = jmsg.getTags().stream().map(Tag::getName).map(String::toLowerCase).collect(Collectors.toList());
if (!tags.contains("juick")) {
- 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);
- }
- jmsg.setUser(serviceUser);
- twitterManager.twitterPost(jmsg);
+ applicationEventPublisher.publishEvent(new TopEvent(this, jmsg));
}
});
}