aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-07-04 15:12:45 +0300
committerGravatar Vitaly Takmazov2018-07-04 15:12:45 +0300
commite6356edd22ad8962a0dca7a0ca819f6b4de73f3b (patch)
tree9a7f6c0571df2ea29a8310e6ca11d90b4dcddac6
parent593b0bff6ddd6ff3756d7ee46d44defb12b0e982 (diff)
do not show replies to banned users as unread
-rw-r--r--juick-common/src/main/java/com/juick/service/UserService.java3
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/UserServiceImpl.java20
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java8
4 files changed, 32 insertions, 1 deletions
diff --git a/juick-common/src/main/java/com/juick/service/UserService.java b/juick-common/src/main/java/com/juick/service/UserService.java
index 115c7dfc..858a47be 100644
--- a/juick-common/src/main/java/com/juick/service/UserService.java
+++ b/juick-common/src/main/java/com/juick/service/UserService.java
@@ -17,6 +17,7 @@
package com.juick.service;
+import com.juick.Message;
import com.juick.User;
import com.juick.server.helpers.Auth;
import com.juick.server.helpers.UserInfo;
@@ -90,6 +91,8 @@ public interface UserService {
boolean isInBLAny(int uid, int uid2);
+ boolean isReplyToBL(final User user, final Message reply);
+
List<Integer> checkBL(int visitor, Collection<Integer> uids);
boolean isSubscribed(int uid, int check);
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;
@@ -451,6 +452,25 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@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<Integer> checkBL(final int visitor, final Collection<Integer> uids) {
if (CollectionUtils.isEmpty(uids))
return Collections.emptyList();
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 af5b20ec..3fc56af7 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
@@ -903,6 +903,7 @@ public class ServerTests {
@Test
public void lastReadTests() throws Exception {
+ assertThat(userService.isInBLAny(ugnich.getUid(), freefd.getUid()), is(false));
int mid = messagesService.createMessage(ugnich.getUid(), "to be watched", null, null);
subscriptionService.subscribeMessage(messagesService.getMessage(mid), ugnich);
messagesService.createReply(mid, 0, freefd, "new reply", null);
@@ -928,6 +929,7 @@ public class ServerTests {
int newfreefdrid = messagesService.createReply(mid, 0, freefd, "from ban", null);
serverManager.processMessageEvent(new MessageEvent(this, messagesService.getReply(mid, newfreefdrid),
Collections.emptyList()));
+ assertThat(userService.isReplyToBL(ugnich, messagesService.getReply(mid, newfreefdrid)), is(true));
assertThat(lastRead.apply(ugnich, mid), is(newfreefdrid));
privacyQueriesService.blacklistUser(ugnich, freefd);
newfreefdrid = messagesService.createReply(mid, 0, freefd, "after ban", null);
@@ -1055,6 +1057,8 @@ public class ServerTests {
commandsManager.processCommand(juick, String.format("#%d/1 ban for a hour!", mid), emptyUri);
commandsManager.processCommand(juick, String.format("#%d freefd is here but it is hidden from you", mid), emptyUri);
assertThat(messagesService.getMessage(mid).getReplies(), is(3));
+ Message reply = messagesService.getReply(mid, 3);
+ assertThat(userService.isReplyToBL(ugnich, reply), is(false));
List<Message> replies = messagesService.getReplies(ugnich, mid);
assertThat(replies.size(), is(1));
commandsManager.processCommand(freefd, String.format("#%d/3 hahaha!", mid), emptyUri);
@@ -1064,6 +1068,10 @@ public class ServerTests {
commandsManager.processCommand(juick, String.format("#%d/4 mmm?!", mid), emptyUri);
assertThat(messagesService.getMessage(mid).getReplies(), is(5));
replies = messagesService.getReplies(ugnich, mid);
+ reply = messagesService.getReply(mid, 5);
+ assertThat(userService.isReplyToBL(ugnich, reply), is(true));
assertThat(replies.size(), is(1));
+ commandsManager.processCommand(ugnich, "BL @freefd", emptyUri);
+ messagesService.setLastReadComment(ugnich, mid, 5);
}
}