From 4a2b56a850f5bd4802c1001f0249f5ab34c6bb1e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Nov 2020 02:46:28 +0300 Subject: Do not receive mentions from blacklisted users in original posts --- .../java/com/juick/service/SubscriptionServiceImpl.java | 5 ++++- src/test/java/com/juick/server/tests/ServerTests.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java index 634b0188..c14b258a 100644 --- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -58,7 +58,10 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip List subscribers = userService.getUserReaders(uid); List mentionedUsers = userService.getUsersByName(MessageUtils.getMentions(msg).stream() - .map(u -> u.substring(1)).collect(Collectors.toList())); + .map(u -> u.substring(1)) + .collect(Collectors.toList())).stream() + .filter(u -> !userService.isInBL(u.getUid(), msg.getUser().getUid())) + .collect(Collectors.toList()); List users = ListUtils.union(subscribers, mentionedUsers); List tags = tagService.getMessageTagsIDs(mid); List tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList()); diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 925d42f6..aea9447f 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -352,6 +352,7 @@ public class ServerTests { subscriptionService.unSubscribeUser(freefd, ugnich); assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), msg).size(), equalTo(0)); Message mentionMessage = new Message(); + mentionMessage.setUser(ugnich); mentionMessage.setText("@freefd - dick"); assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), mentionMessage).size(), equalTo(1)); subscriptionService.subscribeUser(freefd, ugnich); @@ -1408,6 +1409,19 @@ public class ServerTests { privacyQueriesService.blacklistUser(mentioner, commenter); assertThat(subscriptionService.getUsersSubscribedToComments(msg, reply).size(), is(0)); } + @Test + public void mentionsInPosts() { + jdbcTemplate.execute("DELETE FROM bl_users"); + int mid = messagesService.createMessage(ugnich.getUid(), "@freefd is dick", null, null); + Message msg = messagesService.getMessage(mid).get(); + assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), msg).get(0), is(freefd)); + privacyQueriesService.blacklistUser(freefd, ugnich); + assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), msg).size(), is(0)); + int mid2 = messagesService.createMessage(freefd.getUid(), "@ugnich is dick", null, null); + Message msg2 = messagesService.getMessage(mid2).get(); + assertThat(subscriptionService.getSubscribedUsers(freefd.getUid(), msg2).get(0), is(ugnich)); + jdbcTemplate.execute("DELETE FROM bl_users"); + } @Test public void credentialsShouldNeverBeSerialized() throws Exception { -- cgit v1.2.3