diff options
author | Vitaly Takmazov | 2018-05-10 15:04:57 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-05-10 15:04:57 +0300 |
commit | b642c55f053583533e23b1fc7fc5ac318fcbd7f0 (patch) | |
tree | 3255d68fe48ee38aeba6de4359c631f9b9ddf70f /juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java | |
parent | 78bc4cd5b9383320e989183942ba9ca11252a917 (diff) |
using User::isAnonymous where possible
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java | 46 |
1 files changed, 21 insertions, 25 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 01efd6c9..033404b6 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 @@ -112,7 +112,7 @@ public class MessagesWWW { title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch); mids = messagesService.getSearch(Utils.encodeSphinx(paramSearch), paramBefore); } else if (paramShow == null) { - if (visitor.getUid() > 0) { + if (!visitor.isAnonymous()) { title = "Популярные"; mids = messagesService.getPopular(visitor.getUid(), paramBefore); model.addAttribute("discover", true); @@ -157,7 +157,7 @@ public class MessagesWWW { model.addAttribute("noindex", !(paramShow == null && paramBefore == 0)); List<com.juick.Message> msgs = messagesService.getMessages(mids); - if (visitor.getUid() != 0) { + if (!visitor.isAnonymous()) { fillUserModel(model, visitor, visitor); List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); @@ -172,7 +172,7 @@ public class MessagesWWW { model.addAttribute("tags", tagService.getPopularTags()); model.addAttribute("headers", head); model.addAttribute("showAdv", - paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0); + paramShow == null && paramBefore == 0 && paramSearch == null && visitor.isAnonymous()); if (mids.size() >= 20) { String nextpage = (paramShow != null && paramShow.equals("discuss")) ? "?to=" + msgs.get(msgs.size() - 1).getUpdated().toEpochMilli() : "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -186,7 +186,7 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.getUid() == 0 && queryString == null) { + if (sape != null && visitor.isAnonymous() && queryString == null) { String links = sape.getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } @@ -227,7 +227,7 @@ public class MessagesWWW { } int privacy = 0; - if (visitor.getUid() > 0) { + if (!visitor.isAnonymous()) { if (user.getUid() == visitor.getUid() || visitor.getUid() == 1) { privacy = -3; } else if (userService.isInWL(user.getUid(), visitor.getUid())) { @@ -273,7 +273,7 @@ public class MessagesWWW { model.addAttribute("paramTag", paramTag); List<com.juick.Message> msgs = messagesService.getMessages(mids); - if (visitor.getUid() != 0) { + if (!visitor.isAnonymous()) { List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); List<Integer> blUIDs = userService.checkBL(visitor.getUid(), @@ -303,7 +303,7 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.getUid() == 0 && queryString == null) { + if (sape != null && visitor.isAnonymous() && queryString == null) { String links = sape.getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } @@ -402,13 +402,11 @@ public class MessagesWWW { return "redirect:" + url; } - int visitor_uid = visitor.getUid(); - String title = "*" + StringEscapeUtils.escapeHtml4(paramTag.getName()); model.addAttribute("title", title); - List<Integer> mids = messagesService.getTag(paramTag.TID, visitor_uid, before, (visitor_uid == 0) ? 40 : 20); + List<Integer> mids = messagesService.getTag(paramTag.TID, visitor.getUid(), before, (visitor.isAnonymous()) ? 40 : 20); List<com.juick.Message> msgs = messagesService.getMessages(mids); - if (visitor.getUid() != 0) { + if (!visitor.isAnonymous()) { List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); List<Integer> blUIDs = userService.checkBL( @@ -435,7 +433,7 @@ public class MessagesWWW { model.addAttribute("msgs", msgs); model.addAttribute("tags", tagService.getPopularTags()); model.addAttribute("noindex", before > 0); - model.addAttribute("showAdv", before == 0 && visitor.getUid() == 0); + model.addAttribute("showAdv", before == 0 && visitor.isAnonymous()); model.addAttribute("isSubscribed", tagService.isSubscribed(visitor, paramTag)); model.addAttribute("isInBL", tagService.isInBL(visitor, paramTag)); if (mids.size() >= 20) { @@ -445,7 +443,7 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.getUid() == 0 && queryString == null) { + if (sape != null && visitor.isAnonymous() && queryString == null) { String links = sape.getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } @@ -454,7 +452,7 @@ public class MessagesWWW { @GetMapping("/pm/inbox") protected String doGetInbox(ModelMap model) { com.juick.User visitor = UserUtils.getCurrentUser(); - if (visitor.getUid() == 0) { + if (visitor.isAnonymous()) { return "redirect:/login"; } String title = "PM: Inbox"; @@ -471,7 +469,7 @@ public class MessagesWWW { protected String doGetSent(@RequestParam(required = false) String uname, ModelMap model) { com.juick.User visitor = UserUtils.getCurrentUser(); - if (visitor.getUid() == 0) { + if (visitor.isAnonymous()) { return "redirect:/login"; } String title = "PM: Sent"; @@ -507,19 +505,17 @@ public class MessagesWWW { } com.juick.User user = userService.getUserByName(uname); - if (user.getUid() == 0 || !msg.getUser().equals(user)) { + if (user.isAnonymous() || !msg.getUser().equals(user)) { return String.format("redirect:/%s/%d", msg.getUser().getName(), mid); } - msg.VisitorCanComment = visitor.getUid() > 0; + msg.VisitorCanComment = !visitor.isAnonymous(); List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid()); - if (!visitor.isAnonymous()) { - applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg)); - } // this should be after getReplies to mark thread as read fillUserModel(model, user, visitor); - if (visitor.getUid() > 0) { + if (!visitor.isAnonymous()) { List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); + applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg)); boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid()); msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL); @@ -572,8 +568,8 @@ public class MessagesWWW { && !blUIDs.contains(reply.getUser().getUid())) { blUIDs.add(reply.getUser().getUid()); } - reply.VisitorCanComment = visitor.getUid() > 0; - if (visitor.getUid() > 0) { + reply.VisitorCanComment = !visitor.isAnonymous(); + if (!visitor.isAnonymous()) { boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid(); reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly @@ -581,11 +577,11 @@ public class MessagesWWW { } } model.addAttribute("replies", replies); - model.addAttribute("showAdv", visitor.getUid() == 0); + model.addAttribute("showAdv", visitor.isAnonymous()); UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.getUid() == 0 && queryString == null) { + if (sape != null && visitor.isAnonymous() && queryString == null) { String links = sape.getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } |