aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-02-09 11:51:09 +0300
committerGravatar Vitaly Takmazov2018-02-09 11:51:09 +0300
commitd85787b7aa2b8f41fe1579ea553a3ca86f0b3c98 (patch)
tree31555904880f07e27401dddc86354d9e36a9e7b7 /juick-server/src/main/java/com
parentc9a59c945b1a9f0f36bf397d88ea0de0ea22f1fe (diff)
server: post top to twitter from service user
Diffstat (limited to 'juick-server/src/main/java/com')
-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);
});
}
}