From 593b0bff6ddd6ff3756d7ee46d44defb12b0e982 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Jul 2018 12:46:42 +0300 Subject: do not show banned users in thread --- .../main/java/com/juick/service/MessagesServiceImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'juick-server/src/main/java/com/juick/service') 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 35e48383..d68ef8dd 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -837,7 +837,13 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Override public List getReplies(final User user, final int mid) { List replies = getNamedParameterJdbcTemplate().query( - "SELECT replies.message_id as mid, replies.reply_id, replies.replyto, " + + "WITH RECURSIVE banned(reply_id, user_id) AS (" + + "SELECT reply_id, user_id FROM replies " + + "WHERE replies.message_id = :mid " + + "AND EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :uid AND b.bl_user_id = replies.user_id) " + + "UNION ALL SELECT replies.reply_id, replies.user_id FROM replies " + + "INNER JOIN banned ON banned.reply_id = replies.replyto ) " + + "SELECT replies.message_id as mid, replies.reply_id, replies.replyto, " + "replies.user_id, users.nick, users.banned, " + "replies.ts, " + "0 as readonly, 0 as privacy, 0 as replies, " + @@ -853,8 +859,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ "LEFT JOIN messages m on replies.message_id = m.message_id " + "LEFT JOIN users qu ON qw.user_id=qu.id " + "LEFT JOIN users mu ON m.user_id=mu.id " + - "WHERE replies.message_id = :mid ORDER BY replies.reply_id ASC", - new MapSqlParameterSource("mid", mid), + "WHERE replies.message_id = :mid " + + "AND NOT EXISTS (SELECT 1 FROM banned WHERE banned.reply_id = replies.reply_id) " + + "ORDER BY replies.reply_id ASC", + new MapSqlParameterSource("mid", mid).addValue("uid", user.getUid()), new MessageMapper()); if (replies.size() > 0) { setLastReadComment(user, mid, replies.stream().map(Message::getRid).max(Comparator.naturalOrder()).get()); -- cgit v1.2.3