diff options
author | 2018-05-08 15:21:50 +0300 | |
---|---|---|
committer | 2018-05-08 15:21:50 +0300 | |
commit | 67c5a5eedcd1bf68ade678935392eace59af1c37 (patch) | |
tree | 511c6765a4a03eb6ba98a4abd2886f9fd52b84d1 /juick-common/src/main/java/com/juick/server | |
parent | 28f91c88d2475c0e8f6b69f2c12200f4c43c98a0 (diff) |
5 tags per message limit
Diffstat (limited to 'juick-common/src/main/java/com/juick/server')
-rw-r--r-- | juick-common/src/main/java/com/juick/server/CommandsManager.java | 14 |
1 files changed, 11 insertions, 3 deletions
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 5927ed3a..82d293fe 100644 --- a/juick-common/src/main/java/com/juick/server/CommandsManager.java +++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java @@ -32,6 +32,7 @@ import com.juick.server.util.HttpUtils; import com.juick.server.util.ImageUtils; import com.juick.server.util.TagUtils; import com.juick.service.*; +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; @@ -100,6 +101,9 @@ public class CommandsManager { } // new message List<Tag> tags = tagService.fromString(input, false); + if (tags.size() >= 5) { + return CommandResult.fromString("Sorry, 5 tags maximum."); + } String body = TagUtils.toString(tags).equals(input) ? StringUtils.EMPTY : input.substring(TagUtils.toString(tags).length()).trim(); String attachmentType = StringUtils.isNotEmpty(attachment.toString()) ? attachment.toString().substring(attachment.toString().length() - 3) : null; int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags); @@ -471,13 +475,17 @@ 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); List<Tag> messageTags = tagService.fromString(txt, true); if (messageTags.size() > 0) { - if (user.getUid() != messagesService.getMessageAuthor(mid).getUid()) { + if (user.getUid() != msg.getUser().getUid()) { return CommandResult.fromString("It is not your message"); } - tagService.updateTags(mid, messageTags); - return CommandResult.fromString("Tags are updated"); + if (!CollectionUtils.isEqualCollection(tagService.updateTags(mid, messageTags), msg.getTags())) { + return CommandResult.fromString("Tags are updated"); + } else { + return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)"); + } } else { String attachmentStr = attachment.toString(); String attachmentType = StringUtils.isNotEmpty(attachmentStr) ? attachmentStr.substring(attachmentStr.length() - 3) : null; |