aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java12
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java16
2 files changed, 22 insertions, 6 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 054503c1..ba721eea 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -517,18 +517,24 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
(before > 0 ?
" message_id < :before AND " : StringUtils.EMPTY) +
" (privacy >= 0 OR (privacy >= -2 AND privacy <= -1" +
- " AND EXISTS (SELECT 1 FROM wl_users w WHERE w.wl_user_id = :uid and w.user_id = messages.user_id)))) " +
+ " AND EXISTS (SELECT 1 FROM wl_users w WHERE w.wl_user_id = :uid and w.user_id = messages.user_id))) " +
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " +
+ "(SELECT tag_id FROM messages_tags WHERE message_id = messages.message_id) and :uid = bt.user_id))" +
" UNION " +
" (SELECT message_id FROM messages WHERE user_id=:uid " +
(before > 0 ?
" AND message_id < :before " : StringUtils.EMPTY) +
(recommended ?
") UNION " +
- " (SELECT f.message_id as message_id FROM favorites f WHERE " +
+ " (SELECT f.message_id as message_id FROM favorites f INNER JOIN messages ON " +
+ "f.message_id=messages.message_id WHERE " +
"EXISTS (SELECT 1 FROM subscr_users s WHERE s.suser_id = :uid and f.user_id = s.user_id)" +
(before > 0 ?
" AND f.message_id < :before " : StringUtils.EMPTY) : StringUtils.EMPTY) +
- ") ORDER BY message_id DESC LIMIT 20",
+ " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :uid and b.bl_user_id = messages.user_id)" +
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " +
+ "(SELECT tag_id FROM messages_tags WHERE message_id = messages.message_id) and :uid = bt.user_id)) " +
+ "ORDER BY message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
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 b4d91b79..1aff9ca3 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
@@ -176,6 +176,7 @@ public class ServerTests {
freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new);
int juickId = userService.createUser(juickName, juickPassword);
juick = userService.getUserByUID(juickId).orElseThrow(IllegalStateException::new);
+ subscriptionService.subscribeUser(freefd, ugnich);
isSetUp = true;
}
}
@@ -190,8 +191,6 @@ public class ServerTests {
public void getMyFeed() {
int mid0 = messagesService.createMessage(ugnich.getUid(), "test", null, null);
int mid2 = messagesService.createMessage(ugnich.getUid(), "test2", null, null);
- subscriptionService.subscribeUser(userService.getUserByUID(freefd.getUid()).orElse(AnonymousUser.INSTANCE),
- userService.getUserByUID(ugnich.getUid()).orElse(AnonymousUser.INSTANCE));
List<Integer> freefdFeed = messagesService.getMyFeed(freefd.getUid(), 0, false);
assertThat(freefdFeed.get(0), equalTo(mid2));
int tonyaid = userService.createUser("Tonya", "secret");
@@ -942,7 +941,18 @@ public class ServerTests {
.stream().noneMatch(m -> m.getTags().contains(banned)));
assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPopular(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
-
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getMyFeed(freefd.getUid(), 0, true))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ int newUid = userService.createUser("newUser", "12345");
+ int newMid = messagesService.createMessage(newUid, "people", null, Collections.singletonList(banned));
+ messagesService.recommendMessage(newMid, ugnich.getUid());
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getMyFeed(freefd.getUid(), 0, true))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ tagService.updateTags(newMid, Collections.singletonList(banned));
+ assertThat(messagesService.getMessage(newMid).getTags().size(), is(0));
+ privacyQueriesService.blacklistUser(freefd, userService.getUserByUID(newUid).orElse(AnonymousUser.INSTANCE));
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getMyFeed(freefd.getUid(), 0, true))
+ .stream().noneMatch(m -> m.getMid() == newMid));
}
@Test
public void tagsShouldBeDeserializedFromXml() throws JAXBException {