aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main')
-rw-r--r--juick-server/src/main/java/com/juick/server/CrosspostManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/TopManager.java20
2 files changed, 21 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/CrosspostManager.java b/juick-server/src/main/java/com/juick/server/CrosspostManager.java
index edffaf71..1752e1ca 100644
--- a/juick-server/src/main/java/com/juick/server/CrosspostManager.java
+++ b/juick-server/src/main/java/com/juick/server/CrosspostManager.java
@@ -151,7 +151,7 @@ public class CrosspostManager implements ApplicationListener<MessageEvent> {
return ret;
}
- private void twitterPost(final com.juick.Message jmsg) {
+ void twitterPost(final com.juick.Message jmsg) {
crosspostService.getTwitterToken(jmsg.getUser().getUid()).ifPresent(t -> {
String status = MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText());
if (status.length() > 255) {
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 77518d37..894dfda7 100644
--- a/juick-server/src/main/java/com/juick/server/TopManager.java
+++ b/juick-server/src/main/java/com/juick/server/TopManager.java
@@ -18,16 +18,20 @@
package com.juick.server;
import com.juick.Message;
+import com.juick.User;
import com.juick.service.MessagesService;
+import com.juick.service.UserService;
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.http.HttpStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
@Component
@@ -37,6 +41,20 @@ public class TopManager {
private MessagesService messagesService;
@Inject
private FacebookPageManager facebookPageManager;
+ @Inject
+ private CrosspostManager crosspostManager;
+ @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() {
@@ -52,6 +70,8 @@ public class TopManager {
String responseString = ex.getResponseBodyAsString();
logger.warn("facebook error {}: {}", statusCode.value(), responseString);
}
+ jmsg.setUser(serviceUser);
+ crosspostManager.twitterPost(jmsg);
});
}
}