From 930e6ab6d604963ae6a48c58fc1bd3735071d9ee Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Nov 2018 00:07:06 +0300 Subject: getMessage refactoring --- src/main/java/com/juick/server/www/controllers/MessagesWWW.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/juick/server/www/controllers') diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java index 0708e27f..77ee6e15 100644 --- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java @@ -496,12 +496,14 @@ public class MessagesWWW { throw new HttpForbiddenException(); } - com.juick.Message msg = messagesService.getMessage(mid); + Optional message = messagesService.getMessage(mid); - if (msg == null || msg.getUser().isBanned()) { + if (!message.isPresent() || message.get().getUser().isBanned()) { throw new HttpNotFoundException(); } + Message msg = message.get(); + com.juick.User user = userService.getUserByName(uname); if (user.isAnonymous() || !msg.getUser().equals(user)) { return String.format("redirect:/%s/%d", msg.getUser().getName(), mid); -- cgit v1.2.3