aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java14
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java3
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java6
3 files changed, 20 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;
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
index 880f18b9..3c35f5b3 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
@@ -192,6 +192,9 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
.filter(currentTags::contains)
.map(tag -> tag.TID)
.collect(Collectors.toList());
+ if (newTags.size() - idsForDelete.size() >= 5) {
+ return currentTags;
+ }
if (!idsForDelete.isEmpty())
getNamedParameterJdbcTemplate().update(
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index c0501661..70dfd175 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -791,6 +791,12 @@ public class ServerTests {
codeAndTagsTags.get(0).getName());
assertEquals("and the message should be with a C-code and without tags", expectedCodeMessage,
codeAndTagsMessage.getText());
+ CommandResult result = commandsManager.processCommand(user, "*one *two *three *four *five *six test", emptyUri);
+ assertThat(result.getNewMessage(), is(Optional.empty()));
+ assertThat(result.getText(), is("Sorry, 5 tags maximum."));
+ result = commandsManager.processCommand(user, String.format("#%d *one *two *three *four *five *six", msg.getMid()), emptyUri);
+ assertThat(result.getNewMessage(), is(Optional.empty()));
+ assertThat(result.getText(), is("Tags are NOT updated (5 tags maximum?)"));
}
@Test
public void mailParserTest() throws Exception {