aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/TwitterManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/TwitterManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/TwitterManager.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TwitterManager.java b/juick-server/src/main/java/com/juick/server/TwitterManager.java
index eeef2b91..613594e6 100644
--- a/juick-server/src/main/java/com/juick/server/TwitterManager.java
+++ b/juick-server/src/main/java/com/juick/server/TwitterManager.java
@@ -17,6 +17,8 @@
package com.juick.server;
import com.juick.Message;
+import com.juick.User;
+import com.juick.service.UserService;
import com.juick.service.component.*;
import com.juick.service.CrosspostService;
import com.juick.util.MessageUtils;
@@ -28,6 +30,7 @@ import org.springframework.stereotype.Component;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
/**
@@ -45,6 +48,18 @@ public class TwitterManager implements NotificationListener {
private String twitter_consumer_key;
@Value("${twitter_consumer_secret:secret}")
private String twitter_consumer_secret;
+ @Inject
+ private UserService userService;
+
+ @Value("${service_user:juick}")
+ private String serviceUsername;
+
+ private User serviceUser;
+
+ @PostConstruct
+ public void init() {
+ serviceUser = userService.getUserByName(serviceUsername);
+ }
void twitterPost(final com.juick.Message jmsg) {
crosspostService.getTwitterToken(jmsg.getUser().getUid()).ifPresent(t -> {
@@ -100,4 +115,11 @@ public class TwitterManager implements NotificationListener {
public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
}
+
+ @Override
+ public void processTopEvent(TopEvent topEvent) {
+ Message jmsg = topEvent.getMessage();
+ jmsg.setUser(serviceUser);
+ twitterPost(jmsg);
+ }
}