From d85787b7aa2b8f41fe1579ea553a3ca86f0b3c98 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 9 Feb 2018 11:51:09 +0300 Subject: server: post top to twitter from service user --- .../main/java/com/juick/server/CrosspostManager.java | 2 +- .../src/main/java/com/juick/server/TopManager.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'juick-server/src/main') 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 { 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); }); } } -- cgit v1.2.3