From 162262eb58c4642b7ffb9ed41bc760e0f009d6a6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 3 Aug 2018 12:38:18 +0300 Subject: replies counter in feeds reflect banned comments --- .../java/com/juick/service/MessagesServiceImpl.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java') 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 75493377..f79e4142 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -754,14 +754,20 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List getMessages(final List mids) { + public List getMessages(final User visitor, final List mids) { if (CollectionUtils.isNotEmpty(mids)) { List msgs = getNamedParameterJdbcTemplate().query( - "SELECT messages.message_id, 0 as rid, 0 as replyto, " + "WITH RECURSIVE banned(message_id, reply_id) " + + "AS (SELECT message_id, reply_id FROM replies WHERE replies.message_id IN (:ids) " + + "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.message_id, replies.reply_id FROM replies INNER JOIN banned " + + "ON banned.reply_id = replies.replyto AND banned.message_id=replies.message_id " + + "WHERE replies.message_id IN (:ids)) " + + "SELECT messages.message_id, 0 as rid, 0 as replyto, " + "messages.user_id,users.nick, 0 as banned, " + "messages.ts," - + "messages.readonly,messages.privacy,messages.replies," + + "messages.readonly,messages.privacy, messages.replies-COUNT(DISTINCT banned.reply_id) as replies," + "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden," + "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q, " + "messages.updated, 0 as to_uid, NULL as to_name " @@ -770,8 +776,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "INNER JOIN users ON messages.user_id=users.id " + "LEFT JOIN favorites " + "ON messages.message_id = favorites.message_id AND favorites.like_id=1 " - + "WHERE messages.message_id IN (:ids) GROUP BY messages.message_id", - new MapSqlParameterSource("ids", mids), + + "LEFT JOIN banned " + + "ON messages.message_id = banned.message_id " + + "WHERE messages.message_id IN (:ids) GROUP BY " + + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name", + new MapSqlParameterSource("ids", mids) + .addValue("uid", visitor.getUid()), new MessageMapper()); -- cgit v1.2.3