aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-02 09:35:55 +0300
committerGravatar Vitaly Takmazov2018-04-02 09:36:59 +0300
commit0a44ec2654875f6a25e37009cd3f16dd1b6815df (patch)
tree4e93d42129bc74b70291fe239ce4179e2a50ddc1 /juick-server/src/main/java/com/juick/server
parent1fd2c324857eb6a6c4780873972179fcfb698ae1 (diff)
top: do not forward *juick messages to twitter/facebook
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/TopManager.java29
1 files changed, 17 insertions, 12 deletions
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<String> 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);
-
});
}
}