diff options
author | 2018-11-20 00:07:06 +0300 | |
---|---|---|
committer | 2018-11-20 00:07:06 +0300 | |
commit | 930e6ab6d604963ae6a48c58fc1bd3735071d9ee (patch) | |
tree | bb236bf36ccab695bef4d45012135c2396c84f77 /src/main/java/com/juick/server/api/Messages.java | |
parent | 74740d5d989f11746266a994840f89e9f6784f73 (diff) |
getMessage refactoring
Diffstat (limited to 'src/main/java/com/juick/server/api/Messages.java')
-rw-r--r-- | src/main/java/com/juick/server/api/Messages.java | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/main/java/com/juick/server/api/Messages.java b/src/main/java/com/juick/server/api/Messages.java index 4f0009dd..f7485d55 100644 --- a/src/main/java/com/juick/server/api/Messages.java +++ b/src/main/java/com/juick/server/api/Messages.java @@ -39,10 +39,7 @@ import org.springframework.web.bind.annotation.*; import javax.inject.Inject; import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * @author ugnich @@ -163,8 +160,9 @@ public class Messages { public ResponseEntity<List<com.juick.Message>> getThread( @RequestParam(defaultValue = "0") int mid) { User visitor = UserUtils.getCurrentUser(); - com.juick.Message msg = messagesService.getMessage(mid); - if (msg != null) { + Optional<Message> message = messagesService.getMessage(mid); + if (message.isPresent()) { + Message msg = message.get(); if (!messagesService.canViewThread(mid, visitor.getUid())) { return FORBIDDEN; } else { @@ -189,7 +187,7 @@ public class Messages { User visitor = UserUtils.getCurrentUser(); if (!visitor.isAnonymous()) { messagesService.setLastReadComment(visitor, mid, rid); - Message msg = messagesService.getMessage(mid); + Message msg = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); userService.updateLastSeen(visitor); applicationEventPublisher.publishEvent( new MessageReadEvent(this, visitor, msg)); |