From e24f7a7ce9eb765aa2f581defbe20433a647700d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Apr 2018 12:16:47 +0300 Subject: www: badge for unread thread --- .../com/juick/www/controllers/MessagesWWW.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www') 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 80be605f..3c3c5d43 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 @@ -67,7 +67,6 @@ public class MessagesWWW { private CrosspostService crosspostService; void fillUserModel(ModelMap model, com.juick.User user, com.juick.User visitor) { - user.setUnreadCount(messagesService.getUnread(visitor).size()); model.addAttribute("user", user); model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid())); model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid())); @@ -156,9 +155,14 @@ public class MessagesWWW { if (visitor.getUid() != 0) { fillUserModel(model, visitor, visitor); + List unread = messagesService.getUnread(visitor); + visitor.setUnreadCount(unread.size()); List blUIDs = userService.checkBL(visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())); - msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); + msgs.forEach(m -> { + m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); + m.setUnread(unread.contains(m.getMid())); + }); } model.addAttribute("msgs", msgs); model.addAttribute("tags", tagService.getPopularTags()); @@ -266,9 +270,14 @@ public class MessagesWWW { List msgs = messagesService.getMessages(mids); if (visitor.getUid() != 0) { + List unread = messagesService.getUnread(visitor); + visitor.setUnreadCount(unread.size()); List blUIDs = userService.checkBL(visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())); - msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); + msgs.forEach(m -> { + m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); + m.setUnread(unread.contains(m.getMid())); + }); } model.addAttribute("msgs", msgs); model.addAttribute("headers", head); @@ -396,11 +405,16 @@ public class MessagesWWW { List mids = messagesService.getTag(paramTag.TID, visitor_uid, before, (visitor_uid == 0) ? 40 : 20); List msgs = messagesService.getMessages(mids); if (visitor.getUid() != 0) { + List unread = messagesService.getUnread(visitor); + visitor.setUnreadCount(unread.size()); List blUIDs = userService.checkBL( visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()) ); - msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); + msgs.forEach(m -> { + m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); + m.setUnread(unread.contains(m.getMid())); + }); fillUserModel(model, visitor, visitor); } @@ -494,6 +508,8 @@ public class MessagesWWW { } msg.VisitorCanComment = visitor.getUid() > 0; if (visitor.getUid() > 0) { + List unread = messagesService.getUnread(visitor); + visitor.setUnreadCount(unread.size()); boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid()); msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL); -- cgit v1.2.3