From e6356edd22ad8962a0dca7a0ca819f6b4de73f3b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Jul 2018 15:12:45 +0300 Subject: do not show replies to banned users as unread --- .../main/java/com/juick/server/ServerManager.java | 2 +- .../main/java/com/juick/service/UserServiceImpl.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'juick-server/src/main') diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java index c3df33cb..f5ca82f1 100644 --- a/juick-server/src/main/java/com/juick/server/ServerManager.java +++ b/juick-server/src/main/java/com/juick/server/ServerManager.java @@ -168,7 +168,7 @@ public class ServerManager implements NotificationListener { Message op = messagesService.getMessage(jmsg.getMid()); com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); subscriptionService.getUsersSubscribedToComments(op, reply, true).stream() - .filter(u -> userService.isInBLAny(reply.getUser().getUid(), u.getUid())) + .filter(u -> userService.isReplyToBL(u, reply)) .forEach(b -> messagesService.setLastReadComment(b, reply.getMid(), reply.getRid())); onJuickMessageReply(reply, subscribedUsers); } diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java index a0a07fb3..eca0c264 100644 --- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java @@ -17,6 +17,7 @@ package com.juick.service; +import com.juick.Message; import com.juick.User; import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.Auth; @@ -449,6 +450,25 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return !list.isEmpty() && list.get(0) == 1; } + @Transactional(readOnly = true) + @Override + public boolean isReplyToBL(final User user, final Message reply) { + return getNamedParameterJdbcTemplate().queryForObject("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 COUNT(reply_id) from replies " + + "WHERE replies.message_id = :mid " + + "AND replies.reply_id = :rid " + + "AND EXISTS (SELECT 1 FROM banned WHERE banned.reply_id = replies.reply_id) ", + new MapSqlParameterSource("uid", user.getUid()) + .addValue("mid", reply.getMid()) + .addValue("rid", reply.getRid()), + Integer.class) > 0; + } + @Transactional(readOnly = true) @Override public List checkBL(final int visitor, final Collection uids) { -- cgit v1.2.3