From ad99117a15062a3819dad1f52a072e9694a954df Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 11 Apr 2018 21:34:14 +0300 Subject: server: last read marker for threads --- .../main/java/com/juick/server/api/Messages.java | 2 +- .../java/com/juick/server/tests/ServerTests.java | 24 ++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'juick-server/src') diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java index 86426bf6..45b8f69c 100644 --- a/juick-server/src/main/java/com/juick/server/api/Messages.java +++ b/juick-server/src/main/java/com/juick/server/api/Messages.java @@ -145,7 +145,7 @@ public class Messages { if (!messagesService.canViewThread(mid, vuid)) { return FORBIDDEN; } else { - List replies = messagesService.getReplies(mid); + List replies = messagesService.getReplies(visitor, mid); replies.add(0, msg); return ResponseEntity.ok(replies); } 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 2c335cb2..095566ec 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 @@ -54,22 +54,18 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.stanza.model.Stanza; import rocks.xmpp.core.stanza.model.StanzaError; import rocks.xmpp.core.stanza.model.client.ClientMessage; import rocks.xmpp.core.stanza.model.errors.Condition; -import rocks.xmpp.core.stanza.model.server.ServerMessage; import javax.inject.Inject; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Timestamp; import java.time.Instant; import java.util.*; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.IntStream; @@ -246,18 +242,18 @@ public class ServerTests { assertEquals("we already have ugnich", -1, userService.createUser("ugnich", "x")); int ugnich_id = userService.createUser("hugnich", "x"); User ugnich = userService.getUserByUID(ugnich_id).orElse(new User()); - int rid = messagesService.createReply(msg2.getMid(), 0, ugnich.getUid(), "bla-bla", null); + int rid = messagesService.createReply(msg2.getMid(), 0, ugnich, "bla-bla", null); assertEquals(1, rid); assertThat(msg2.getTo(), equalTo(null)); Message reply = messagesService.getReply(msg2.getMid(), rid); assertThat(reply.getTo().getName(), equalTo(user.getName())); - List replies = messagesService.getReplies(msg2.getMid()); + List replies = messagesService.getReplies(user, msg2.getMid()); assertThat(replies.size(), equalTo(1)); assertThat(replies.get(0), equalTo(reply)); - int ridToReply = messagesService.createReply(msg2.getMid(), 1, ugnich_id, "blax2", null); + int ridToReply = messagesService.createReply(msg2.getMid(), 1, ugnich, "blax2", null); Message reply2 = messagesService.getReply(msg2.getMid(), ridToReply); assertThat(reply.getTo().getName(), equalTo(user.getName())); - List replies2 = messagesService.getReplies(msg2.getMid()); + List replies2 = messagesService.getReplies(user, msg2.getMid()); assertThat(replies2.size(), equalTo(2)); assertThat(replies2.get(1), equalTo(reply2)); Message msg3 = messagesService.getMessage(mid2); @@ -267,7 +263,7 @@ public class ServerTests { assertEquals(-1, userService.checkPassword(ugnich.getName(), "xy")); subscriptionService.subscribeMessage(msg.getMid(), user.getUid()); subscriptionService.subscribeMessage(msg.getMid(), ugnich.getUid()); - int reply_id = messagesService.createReply(msg.getMid(), 0, ugnich_id, "comment", null); + int reply_id = messagesService.createReply(msg.getMid(), 0, ugnich, "comment", null); assertEquals(1, subscriptionService.getUsersSubscribedToComments(msg, messagesService.getReply(msg.getMid(), reply_id)).size()); assertThat(messagesService.getDiscussions(ugnich.getUid(), 0L).get(0), @@ -308,7 +304,7 @@ public class ServerTests { Instant ts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?", Timestamp.class, mid).toInstant(); Thread.sleep(1000); - int rid = messagesService.createReply(mid, 0, ugnich_id, "people", null); + int rid = messagesService.createReply(mid, 0, ugnich, "people", null); Instant rts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?", Timestamp.class, mid).toInstant(); assertThat(rts, greaterThan(ts)); @@ -498,7 +494,9 @@ public class ServerTests { public void topTest() { int topmid = messagesService.createMessage(ugnich.getUid(), "top message", null, null); IntStream.rangeClosed(6, 12).forEach(i -> { - messagesService.createReply(topmid, 0, i, "yo", null); + User next = new User(); + next.setUid(i); + messagesService.createReply(topmid, 0, next, "yo", null); }); assertThat(messagesService.getPopularCandidates().get(0), is(topmid)); @@ -615,7 +613,7 @@ public class ServerTests { commandsManager.processCommand(readerUser, "S #" + mid, emptyUri).getText()); assertEquals("should be favorited", "Message is added to your recommendations", commandsManager.processCommand(readerUser, "! #" + mid, emptyUri).getText()); - int rid = messagesService.createReply(mid, 0, uid, "comment", null); + int rid = messagesService.createReply(mid, 0, user, "comment", null); assertEquals("number of subscribed users should match", 1, subscriptionService.getUsersSubscribedToComments( messagesService.getMessage(mid), @@ -642,7 +640,7 @@ public class ServerTests { assertEquals("should be third reply", expectedThirdReply, commandsManager.processCommand(user, "#" + mid + "/2 ", URI.create("http://static.juick.com/settings/facebook.png")).getText()); - Message reply = messagesService.getReplies(mid).stream().filter(m -> m.getRid() == 3).findFirst() + Message reply = messagesService.getReplies(user, mid).stream().filter(m -> m.getRid() == 3).findFirst() .orElse(new Message()); assertEquals("should be reply to second comment", 2, reply.getReplyto()); assertEquals("tags should NOT be updated", "It is not your message", -- cgit v1.2.3