diff options
author | Vitaly Takmazov | 2019-09-18 11:35:55 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-09-18 11:35:55 +0300 |
commit | 32c7f35bda7ed3bdad93db4cce0dd17e7f48c3bd (patch) | |
tree | 7e41b69ad86b2f78d9e3ed37c889715408b5be7e /src/main/java/com/juick/server | |
parent | 13993e1cf558baf27e8381b934286afb49b65371 (diff) |
Readonly messages
Diffstat (limited to 'src/main/java/com/juick/server')
-rw-r--r-- | src/main/java/com/juick/server/CommandsManager.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main/java/com/juick/server/CommandsManager.java b/src/main/java/com/juick/server/CommandsManager.java index 634deb35..b21ff81c 100644 --- a/src/main/java/com/juick/server/CommandsManager.java +++ b/src/main/java/com/juick/server/CommandsManager.java @@ -550,20 +550,24 @@ public class CommandsManager { boolean attachmentProcessed = !haveAttachment || StringUtils.isNotEmpty(attachmentType); String messageText = attachmentProcessed ? txt : String.format("%s %s", txt, attachment.toASCIIString()); int newrid = messagesService.createReply(mid, rid, user, messageText, attachmentType); - if (haveAttachment && attachmentProcessed) { - String fname = String.format("%d-%d.%s", mid, newrid, attachmentType); - imagesService.saveImageWithPreviews(attachmentFName, fname); + if (newrid > 0) { + if (haveAttachment && attachmentProcessed) { + String fname = String.format("%d-%d.%s", mid, newrid, attachmentType); + imagesService.saveImageWithPreviews(attachmentFName, fname); + } + applicationEventPublisher.publishEvent( + new MessageReadEvent(this, user, msg.get())); + Message original = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); + subscriptionService.subscribeMessage(original, user); + Message reply = messagesService.getReply(mid, newrid); + reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser())); + applicationEventPublisher.publishEvent(new MessageEvent(this, reply, subscriptionService.getUsersSubscribedToComments(original, reply))); + return CommandResult.build(reply, "Reply posted.\n#" + mid + "/" + newrid + " " + + "https://juick.com/m/" + mid + "#" + newrid, + String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply))); + } else { + return CommandResult.fromString("Message is read-only"); } - applicationEventPublisher.publishEvent( - new MessageReadEvent(this, user, msg.get())); - Message original = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); - subscriptionService.subscribeMessage(original, user); - Message reply = messagesService.getReply(mid, newrid); - reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser())); - applicationEventPublisher.publishEvent(new MessageEvent(this, reply, subscriptionService.getUsersSubscribedToComments(original, reply))); - return CommandResult.build(reply,"Reply posted.\n#" + mid + "/" + newrid + " " - + "https://juick.com/m/" + mid + "#" + newrid, - String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply))); } } |