From 85abc3e201539f81500754a7fb0e4f3a9d148fc4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 25 Sep 2018 10:28:54 +0300 Subject: fix new message tags extracting --- .../src/main/java/com/juick/server/CommandsManager.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'juick-common/src/main/java/com/juick/server') diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java index 13d9b436..7c4692d2 100644 --- a/juick-common/src/main/java/com/juick/server/CommandsManager.java +++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java @@ -33,6 +33,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.reflect.MethodUtils; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; @@ -100,12 +101,12 @@ public class CommandsManager { return commandResult; } } - List tags = tagService.fromString(input); - if (tags.size() > 5) { + Pair> tags = tagService.fromString(input); + if (tags.getRight().size() > 5) { return CommandResult.fromString("Sorry, 5 tags maximum."); } // new message - String body = TagUtils.toString(tags).equals(input) ? StringUtils.EMPTY : input.substring(TagUtils.toString(tags).length()).trim(); + String body = tags.getLeft().trim(); boolean haveAttachment = StringUtils.isNotEmpty(attachment.toString()); String attachmentFName = null; String attachmentType = null; @@ -114,7 +115,7 @@ public class CommandsManager { : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); attachmentType = attachmentFName.substring(attachmentFName.length() - 3); } - int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags); + int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags.getRight()); if (haveAttachment) { String fname = String.format("%d.%s", mid, attachmentType); imagesService.saveImageWithPreviews(attachmentFName, fname); @@ -488,12 +489,12 @@ public class CommandsManager { int rid = NumberUtils.toInt(args[4], 0); String txt = StringUtils.defaultString(args[5]); Message msg = messagesService.getMessage(mid); - List messageTags = tagService.fromString(txt); - if (messageTags.size() > 0) { + Pair> messageTags = tagService.fromString(txt); + if (messageTags.getRight().size() > 0) { if (user.getUid() != msg.getUser().getUid()) { return CommandResult.fromString("It is not your message"); } - if (!CollectionUtils.isEqualCollection(tagService.updateTags(mid, messageTags), msg.getTags())) { + if (!CollectionUtils.isEqualCollection(tagService.updateTags(mid, messageTags.getRight()), msg.getTags())) { return CommandResult.fromString("Tags are updated"); } else { return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)"); -- cgit v1.2.3