aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/CommandsManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/CommandsManager.java')
-rw-r--r--src/main/java/com/juick/server/CommandsManager.java30
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)));
}
}