diff options
Diffstat (limited to 'juick-server/src/main')
-rw-r--r-- | juick-server/src/main/assets/scripts.js | 12 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Post.java | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js index 19383e94..5bbbe6f2 100644 --- a/juick-server/src/main/assets/scripts.js +++ b/juick-server/src/main/assets/scripts.js @@ -350,11 +350,15 @@ function showCommentForm(mid, rid) { credentials: 'omit' }).then(response => { if (response.ok) { - return response.json(); + response.json().then(result => { + if (result.newMessage) { + window.location.href = new URL(`${mid}#${result.newMessage.rid}`, window.location.href); + } else { + alert(result.text); + } + window.location.reload(true); + }); } - }).then(reply => { - window.location.href = new URL(`${mid}#${reply.rid}`, window.location.href); - window.location.reload(true); }).catch(error => { alert(error.message); }) diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java index d6f085bb..b36f324a 100644 --- a/juick-server/src/main/java/com/juick/server/api/Post.java +++ b/juick-server/src/main/java/com/juick/server/api/Post.java @@ -102,7 +102,7 @@ public class Post { } @RequestMapping(value = "/api/comment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public com.juick.Message doPostComment( + public CommandResult doPostComment( @RequestParam(defaultValue = "0") int mid, @RequestParam(defaultValue = "0") int rid, @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body, @@ -150,8 +150,8 @@ public class Post { throw new HttpBadRequestException(); } } - - return commandsManager.processCommand(visitor, String.format("#%d/%d %s", mid, rid, body), attachmentFName).getNewMessage().get(); + return commandsManager.processCommand(visitor, String.format("#%d/%d %s", mid, rid, body), + attachmentFName); } @PostMapping("/api/like") |