From 90d77f71c53a6349c1fb3bcf81d6f9a2a630b3e6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 16 Apr 2018 17:17:03 +0300 Subject: server: mark comments from blacklisted users as read --- .../src/main/java/com/juick/service/SubscriptionService.java | 2 ++ .../main/java/com/juick/service/SubscriptionServiceImpl.java | 9 +++++++-- .../src/main/java/com/juick/server/ServerManager.java | 10 ++++++++++ .../src/test/java/com/juick/server/tests/ServerTests.java | 12 ++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/juick-common/src/main/java/com/juick/service/SubscriptionService.java b/juick-common/src/main/java/com/juick/service/SubscriptionService.java index d5b9f28d..c726e68d 100644 --- a/juick-common/src/main/java/com/juick/service/SubscriptionService.java +++ b/juick-common/src/main/java/com/juick/service/SubscriptionService.java @@ -34,6 +34,8 @@ public interface SubscriptionService { List getUsersSubscribedToComments(Message msg, Message reply); + List getUsersSubscribedToComments(Message msg, Message reply, boolean blacklisted); + List getUsersSubscribedToUserRecommendations(int uid, int mid, int muid); boolean subscribeMessage(Message message, User user); diff --git a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java index 64143c32..7626651a 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -91,10 +91,15 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip } return userService.getUsersByID(set); } + @Override + public List getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply) { + return getUsersSubscribedToComments(msg, reply, false); + } @Transactional(readOnly = true) @Override - public List getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply) { + public List getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply, + boolean blacklisted) { List userids = getJdbcTemplate().queryForList( "SELECT suser_id FROM subscr_messages WHERE message_id=? AND suser_id!=?", Integer.class, @@ -102,7 +107,7 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip if (!userids.isEmpty()) { return userService.getUsersByID(userids.stream() - .filter(u -> !userService.isInBLAny(u, reply.getUser().getUid())) + .filter(u -> blacklisted || !userService.isInBLAny(u, reply.getUser().getUid())) .collect(Collectors.toList())); } return Collections.emptyList(); diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java index f209d934..3db6ec90 100644 --- a/juick-server/src/main/java/com/juick/server/ServerManager.java +++ b/juick-server/src/main/java/com/juick/server/ServerManager.java @@ -18,10 +18,12 @@ package com.juick.server; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.juick.Message; import com.juick.User; import com.juick.server.component.MessageEvent; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; +import com.juick.service.UserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -48,6 +50,10 @@ public class ServerManager implements ApplicationListener { private MessagesService messagesService; @Inject private WebsocketManager wsHandler; + @Inject + private SubscriptionService subscriptionService; + @Inject + private UserService userService; @Value("${service_user:juick}") private String serviceUser; @Inject @@ -157,7 +163,11 @@ public class ServerManager implements ApplicationListener { onJuickMessagePost(messagesService.getMessage(jmsg.getMid()), subscribedUsers); } else { // to get quote and attachment + Message op = messagesService.getMessage(jmsg.getMid()); com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); + subscriptionService.getUsersSubscribedToComments(op, reply, true).stream() + .filter(u -> userService.isInBLAny(reply.getUser().getUid(), u.getUid())) + .forEach(b -> messagesService.setLastReadComment(b, reply.getMid(), reply.getRid())); onJuickMessageReply(reply, subscribedUsers); } } diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 71c42b6c..db932dc9 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -24,6 +24,7 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.server.*; +import com.juick.server.component.MessageEvent; import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.CommandResult; import com.juick.server.helpers.TagStats; @@ -123,6 +124,8 @@ public class ServerTests { private CrosspostService crosspostService; @Inject private ImagesService imagesService; + @Inject + private ServerManager serverManager; @Value("${hostname:localhost}") private Jid jid; @Value("${xmppbot_jid:juick@localhost}") @@ -627,6 +630,10 @@ public class ServerTests { subscriptionService.getUsersSubscribedToComments( messagesService.getMessage(mid), messagesService.getReply(mid, rid)).size()); + assertEquals("number of subscribed users should match", 1, + subscriptionService.getUsersSubscribedToComments( + messagesService.getMessage(mid), + messagesService.getReply(mid, rid), true).size()); assertEquals("should be subscribed", "Subscribed to @" + user.getName(), commandsManager.processCommand(readerUser, "S @" + user.getName(), emptyUri) .getText()); @@ -777,5 +784,10 @@ public class ServerTests { .andExpect(content().bytes(IOUtils.toByteArray( Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif"))))); assertThat(lastRead.apply(ugnich, mid), is(freefdrid)); + privacyQueriesService.blacklistUser(ugnich, freefd); + int newfreefdrid = messagesService.createReply(mid, 0, freefd, "from ban", null); + serverManager.onApplicationEvent(new MessageEvent(this, messagesService.getReply(mid, newfreefdrid), + Collections.emptyList())); + assertThat(lastRead.apply(ugnich, mid), is(newfreefdrid)); } } -- cgit v1.2.3