aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-21 10:20:55 +0300
committerGravatar Vitaly Takmazov2018-09-21 10:20:55 +0300
commit6640c45912306b485069f023d34444ba4ff12d09 (patch)
tree25854167945d94264cde25d9190e89a5b3ab4488
parentf64b1586b1c146129077e238c03ad4549b5b6f54 (diff)
hide banned from discussions
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java8
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java2
2 files changed, 8 insertions, 2 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 fbf22d59..0abe9309 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -575,9 +575,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
.addValue("to", new Timestamp(to));
if (uid == 0) {
- return getNamedParameterJdbcTemplate().query("SELECT message_id FROM messages" +
+ return getNamedParameterJdbcTemplate().query("SELECT message_id FROM messages WHERE " +
(to != 0 ?
- " WHERE updated < :to " : StringUtils.EMPTY) +
+ " updated < :to AND" : StringUtils.EMPTY) +
+ " NOT EXISTS (SELECT 1 from users u WHERE u.banned = 1" +
+ " AND u.id = messages.user_id and u.id <> :uid) " +
" ORDER BY updated DESC, message_id DESC LIMIT 20",
sqlParameterSource,
(rs, rowNum) -> rs.getInt(1));
@@ -588,6 +590,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"WHERE suser_id = :uid " +
(to != 0 ?
"AND updated < :to " : StringUtils.EMPTY) +
+ " AND NOT EXISTS (SELECT 1 from users u WHERE u.banned = 1" +
+ " AND u.id = messages.user_id and u.id <> :uid) " +
"ORDER BY updated DESC, message_id DESC LIMIT 20",
sqlParameterSource,
(rs, rowNum) -> rs.getInt(1));
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 c3816fad..75024029 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
@@ -1372,6 +1372,8 @@ public class ServerTests {
jdbcTemplate.update("UPDATE users SET banned=1 WHERE id=?", bannedUserId);
messagesService.createMessage(bannedUserId, "KURWA", null, Collections.emptyList());
assertThat(messagesService.getAll(casualUserId, 0).size(), is(0));
+ assertThat(messagesService.getDiscussions(casualUserId, 0L).size(), is(0));
+ assertThat(messagesService.getDiscussions(0, 0L).size(), is(0));
assertThat(messagesService.getAll(bannedUserId, 0).size(), is(1));
int mid = messagesService.createMessage(casualUserId, "PEACE", null, Collections.emptyList());
User banned = userService.getUserByName("banned");