diff options
author | Vitaly Takmazov | 2018-07-26 22:55:51 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-07-26 22:55:51 +0300 |
commit | c1e6e9dd484beb02dbd22f1b5ee3f86e8ca4aa0a (patch) | |
tree | defd6758ee7209e85d4d7bf249a0b22514c498bc | |
parent | 264bd16c937c48b2af77473944217496fae0aa3d (diff) |
mark threads read when banned replies exists
3 files changed, 12 insertions, 2 deletions
diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java index 30719cc6..8e69872a 100644 --- a/juick-common/src/main/java/com/juick/service/MessagesService.java +++ b/juick-common/src/main/java/com/juick/service/MessagesService.java @@ -123,5 +123,7 @@ public interface MessagesService { void setLastReadComment(User user, Integer mid, Integer rid); + void setRead(User user, Integer mid); + List<Integer> getUnread(User user); } 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 a78c9203..75493377 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -851,7 +851,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ 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()); + setRead(user, mid); } return replies; } @@ -987,6 +987,13 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ jdbcTemplate.update("UPDATE subscr_messages SET last_read_rid=GREATEST(?, last_read_rid) WHERE message_id=? AND suser_id=?", rid, mid, user.getUid()); } + @Transactional + @Override + public void setRead(User user, Integer mid) { + jdbcTemplate.update("UPDATE subscr_messages SET last_read_rid=(select replies from messages " + + "where messages.message_id=subscr_messages.message_id) WHERE message_id=? AND suser_id=?", + mid, user.getUid()); + } @Override public List<Integer> getUnread(User user) { 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 61c51b44..2362cd0f 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 @@ -1070,7 +1070,8 @@ public class ServerTests { assertThat(userService.isReplyToBL(ugnich, reply), is(true)); assertThat(replies.size(), is(1)); commandsManager.processCommand(ugnich, "BL @freefd", emptyUri); - messagesService.setLastReadComment(ugnich, mid, 5); + messagesService.setRead(ugnich, mid); + assertThat(messagesService.getReplies(ugnich, mid).size(), is(5)); } @Test public void cmykJpegShouldBeProcessedCorrectly() throws Exception { |