From 0a44ec2654875f6a25e37009cd3f16dd1b6815df Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 2 Apr 2018 09:35:55 +0300 Subject: top: do not forward *juick messages to twitter/facebook --- .../src/main/java/com/juick/server/TopManager.java | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'juick-server/src/main/java') 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 0f2373b4..918e5ace 100644 --- a/juick-server/src/main/java/com/juick/server/TopManager.java +++ b/juick-server/src/main/java/com/juick/server/TopManager.java @@ -18,6 +18,7 @@ package com.juick.server; import com.juick.Message; +import com.juick.Tag; import com.juick.User; import com.juick.service.MessagesService; import com.juick.service.UserService; @@ -33,6 +34,8 @@ import org.springframework.web.client.HttpClientErrorException; import javax.annotation.PostConstruct; import javax.inject.Inject; +import java.util.List; +import java.util.stream.Collectors; @Component public class TopManager { @@ -59,21 +62,23 @@ public class TopManager { @Scheduled(fixedRate = 3600000) public void updateTop() { messagesService.getPopularCandidates().forEach(m -> { + Message jmsg = messagesService.getMessage(m); logger.info("added {} to popular", m); messagesService.setMessagePopular(m, 1); - Message jmsg = messagesService.getMessage(m); - String status = MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText()); - String link = "https://juick.com/" + 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); + List 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/" + 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); + crosspostManager.twitterPost(jmsg); } - jmsg.setUser(serviceUser); - crosspostManager.twitterPost(jmsg); - }); } } -- cgit v1.2.3