From 9cd6679f3f2804bc0b22cfb816f40b47846080cf Mon Sep 17 00:00:00 2001 From: KillyMXI Date: Thu, 5 Oct 2017 06:00:24 +0300 Subject: www: don't show reply forms in readonly thread --- .../java/com/juick/www/controllers/UserThread.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'juick-www/src/main/java/com') diff --git a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java index 46ac485f..b2c3c1f5 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java +++ b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java @@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; import java.io.IOException; import java.util.ArrayList; +import java.util.function.BooleanSupplier; import java.util.List; import java.util.stream.Collectors; @@ -78,8 +79,9 @@ public class UserThread { } msg.VisitorCanComment = visitor.getUid() > 0; if (visitor.getUid() > 0) { - msg.VisitorCanComment = visitor.getUid() == msg.getUser().getUid() - || !userService.isInBL(msg.getUser().getUid(), visitor.getUid()); + boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); + boolean isInBL = userService.isInBL(msg.getUser().getUid(), visitor.getUid()); + msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL); } model.addAttribute("msg", msg); @@ -157,14 +159,13 @@ public class UserThread { reply.setReplyto(0); } } - if (visitor.getUid() > 0 && msg.getUser().getUid() == visitor.getUid()) { - reply.VisitorCanComment = true; - } else if (visitor.getUid() > 0 && msg.VisitorCanComment) { - List blUIDs2 = userService.checkBL(visitor.getUid(), blUIDs); - reply.VisitorCanComment = reply.getUser().getUid() == visitor.getUid() - || !blUIDs2.contains(reply.getUser().getUid()); - } else { - reply.VisitorCanComment = false; + + reply.VisitorCanComment = visitor.getUid() > 0; + if (visitor.getUid() > 0) { + boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); + boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid(); + BooleanSupplier isInBL2 = () -> userService.checkBL(visitor.getUid(), blUIDs).contains(reply.getUser().getUid()); + reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly && (isReplyAuthor || !isInBL2.getAsBoolean())); } } -- cgit v1.2.3