diff options
author | Vitaly Takmazov | 2020-02-05 10:19:26 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2020-02-05 10:19:26 +0300 |
commit | 6fbe53de47e0301e563a83f775ca6a78eed78fc4 (patch) | |
tree | b4511daeecc09171a9155602e0ef91504b61e1e7 | |
parent | 23aba1cc93d1ee28a52560b2205a992494d04a33 (diff) |
Do not count unread messages in threads from blacklisted users
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 6 | ||||
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 14 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index c405fde4..8f1387cf 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -1156,9 +1156,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ return jdbcTemplate.queryForList( "select subscr_messages.message_id " + "from subscr_messages inner join messages on subscr_messages.message_id=messages.message_id " + - "where subscr_messages.suser_id=? and " + + "where subscr_messages.suser_id=? " + + "AND NOT EXISTS (SELECT 1 FROM bl_users WHERE " + + "user_id = ? AND bl_user_id = messages.user_id) AND " + "messages.replies>subscr_messages.last_read_rid", - Integer.class, user.getUid()); + Integer.class, user.getUid(), user.getUid()); } @Transactional diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index a16d920b..f540fd01 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -1749,6 +1749,7 @@ public class ServerTests { jdbcTemplate.execute("DELETE FROM messages"); jdbcTemplate.execute("DELETE FROM replies"); jdbcTemplate.execute("DELETE FROM subscr_messages"); + jdbcTemplate.execute("DELETE FROM bl_users"); MvcResult loginResult = mockMvc.perform(post("/login") .param("username", freefdName) .param("password", freefdPassword)) @@ -1761,11 +1762,22 @@ public class ServerTests { loginCookie.getValue())); int mid = messagesService.createMessage(ugnich.getUid(), "new test", null, null); subscriptionService.subscribeMessage(messagesService.getMessage(mid).get(), freefd); - int rid = messagesService.createReply(mid, 0, ugnich, "new reply", null); + messagesService.createReply(mid, 0, ugnich, "new reply", null); HtmlPage discussionsPage = webClient.getPage("http://localhost:8080/?show=discuss"); assertThat(discussionsPage.querySelectorAll("#global a .badge").size(), is(1)); HtmlPage unreadThread = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); assertThat(unreadThread.querySelectorAll("#global a .badge").size(), is(0)); + messagesService.createReply(mid, 0, ugnich, "reply to ban", null); + discussionsPage.refresh(); + assertThat(discussionsPage.querySelectorAll("#global a .badge").size(), is(1)); + privacyQueriesService.blacklistUser(freefd, ugnich); + assertThat(messagesService.getUnread(freefd).size(), is(0)); + /* TODO: fix + discussionsPage.refresh(); + var unreads = discussionsPage.querySelectorAll("#global a .badge"); + assertThat(unreads.size(), is(0)); + */ + privacyQueriesService.blacklistUser(freefd, ugnich); } @Test |