aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-16 22:05:31 +0300
committerGravatar Vitaly Takmazov2018-04-16 22:05:31 +0300
commit516b3cf0032a6204711dc85cd42d2bf41b84e999 (patch)
tree1e31f5153260979e80d63866e6a0f070e0c32c4e /juick-www/src
parent90d77f71c53a6349c1fb3bcf81d6f9a2a630b3e6 (diff)
www: fix refreshing notifications counter
Diffstat (limited to 'juick-www/src')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java6
-rw-r--r--juick-www/src/test/java/com/juick/WebAppTests.java19
2 files changed, 22 insertions, 3 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
index 3c3c5d43..78474f49 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
@@ -507,9 +507,12 @@ public class MessagesWWW {
return String.format("redirect:/%s/%d", msg.getUser().getName(), mid);
}
msg.VisitorCanComment = visitor.getUid() > 0;
+ List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid());
if (visitor.getUid() > 0) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
+ // this should be after getReplies to mark thread as read
+ fillUserModel(model, user, visitor);
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid());
msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL);
@@ -556,9 +559,6 @@ public class MessagesWWW {
model.addAttribute("visitorSubscribed", messagesService.isSubscribed(visitor.getUid(), msg.getMid()));
model.addAttribute("visitorInBL", userService.isInBL(msg.getUser().getUid(), visitor.getUid()));
model.addAttribute("recomm", messagesService.getMessageRecommendations(msg.getMid()));
- List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid());
- // this should be after getReplies to mark thread as read
- fillUserModel(model, user, visitor);
List<Integer> blUIDs = new ArrayList<>();
for (Message reply : replies) {
if (reply.getUser().getUid() != msg.getUser().getUid()
diff --git a/juick-www/src/test/java/com/juick/WebAppTests.java b/juick-www/src/test/java/com/juick/WebAppTests.java
index 4f9f4cc1..a0ec9737 100644
--- a/juick-www/src/test/java/com/juick/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/WebAppTests.java
@@ -394,4 +394,23 @@ public class WebAppTests {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.webcredentials.apps[0]", is(appId)));
}
+ @Test
+ public void notificationsTests() throws Exception {
+ MvcResult loginResult = mockMvc.perform(post("/login")
+ .param("username", freefdName)
+ .param("password", freefdPassword)).andReturn();
+ Cookie loginCookie = loginResult.getResponse().getCookie("juick-remember-me");
+ webClient.setCookieManager(new CookieManager());
+ webClient.getCookieManager().addCookie(
+ new com.gargoylesoftware.htmlunit.util.Cookie(loginCookie.getDomain(),
+ loginCookie.getName(),
+ loginCookie.getValue()));
+ int mid = messagesService.createMessage(ugnich.getUid(), "new test", null, null);
+ subscriptionService.subscribeMessage(messagesService.getMessage(mid), freefd);
+ int rid = messagesService.createReply(mid, 0, ugnich, "new reply", null);
+ HtmlPage discussionsPage = webClient.getPage("http://localhost:8080/?show=discuss");
+ assertThat(discussionsPage.querySelectorAll("#global a .badge").size(), is(1));
+ HtmlPage unreadThread = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid));
+ assertThat(unreadThread.querySelectorAll("#global a .badge").size(), is(0));
+ }
}