From 7b97f3df5a5c31c5d85ee71c902fa9bf979ffc54 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 28 Nov 2018 14:58:45 +0300 Subject: Fix EditOrReply command flow --- src/main/java/com/juick/server/CommandsManager.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/juick/server') diff --git a/src/main/java/com/juick/server/CommandsManager.java b/src/main/java/com/juick/server/CommandsManager.java index 2eb58188..3257304b 100644 --- a/src/main/java/com/juick/server/CommandsManager.java +++ b/src/main/java/com/juick/server/CommandsManager.java @@ -498,13 +498,19 @@ public class CommandsManager { int mid = NumberUtils.toInt(args[1]); int rid = NumberUtils.toInt(args[4], 0); String txt = StringUtils.defaultString(args[5]); - Message msg = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); - Pair> messageTags = tagService.fromString(txt); - if (messageTags.getRight().size() > 0) { - if (user.getUid() != msg.getUser().getUid()) { - return CommandResult.fromString("It is not your message"); + Optional msg = messagesService.getMessage(mid); + if (!msg.isPresent()) { + return CommandResult.fromString("Message not found"); + } + if (rid > 0) { + Message reply = messagesService.getReply(mid, rid); + if (reply == null) { + return CommandResult.fromString("Reply not found"); } - if (!CollectionUtils.isEqualCollection(tagService.updateTags(mid, messageTags.getRight()), msg.getTags())) { + } + Pair> messageTags = tagService.fromString(txt); + if (user.getUid() == msg.get().getUser().getUid() && rid == 0 && messageTags.getRight().size() > 0) { + if (!CollectionUtils.isEqualCollection(tagService.updateTags(mid, messageTags.getRight()), msg.get().getTags())) { return CommandResult.fromString("Tags are updated"); } else { return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)"); @@ -527,7 +533,7 @@ public class CommandsManager { imagesService.saveImageWithPreviews(attachmentFName, fname); } applicationEventPublisher.publishEvent( - new MessageReadEvent(this, user, msg)); + new MessageReadEvent(this, user, msg.get())); Message original = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); subscriptionService.subscribeMessage(original, user); Message reply = messagesService.getReply(mid, newrid); -- cgit v1.2.3