aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-common/src/main')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java20
-rw-r--r--juick-common/src/main/java/com/juick/server/helpers/CommandResult.java13
-rw-r--r--juick-common/src/main/java/com/juick/server/util/TagUtils.java4
3 files changed, 26 insertions, 11 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 9bde08840..4f115577b 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -90,12 +90,15 @@ public class CommandsManager {
groups.add(matcher.group(i));
}
}
- return (CommandResult) getClass().getMethod(cmd.get().getName(), User.class, Jid.class, URI.class, String[].class)
+ CommandResult commandResult = (CommandResult) getClass().getMethod(cmd.get().getName(), User.class, Jid.class, URI.class, String[].class)
.invoke(this, user, from, attachment, groups.toArray(new String[groups.size()]));
+ if (StringUtils.isNotEmpty(commandResult.getText())) {
+ return commandResult;
+ }
}
// new message
List<Tag> tags = tagService.fromString(input, false);
- String body = input.substring(TagUtils.toString(tags).length());
+ 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);
subscriptionService.subscribeMessage(mid, user.getUid());
@@ -107,7 +110,7 @@ public class CommandsManager {
}
com.juick.Message msg = messagesService.getMessage(mid);
applicationEventPublisher.publishEvent(new MessageEvent(this, msg));
- return CommandResult.fromMessage(msg, StringUtils.EMPTY);
+ return CommandResult.build(msg, StringUtils.EMPTY, String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg)));
}
@UserCommand(pattern = "^ping$", patternFlags = Pattern.CASE_INSENSITIVE,
@@ -407,9 +410,13 @@ public class CommandsManager {
}
@UserCommand(pattern = "^\\*(\\S+)(\\+?)$", help = "*tag - Show last messages with tag")
public CommandResult commandShowTag(User user, Jid from, URI attachment, String... arguments) {
+ if (StringUtils.isNotEmpty(attachment.toString())) {
+ // new message with tag
+ return CommandResult.fromString(StringUtils.EMPTY);
+ }
Tag tag = tagService.getTag(arguments[0], false);
if (tag != null) {
- // TODO: synonims
+ // TODO: synonyms
List<Integer> mids = messagesService.getTag(tag.TID, user.getUid(), 0, 10);
return CommandResult.fromString("Last messages with *" + tag.getName() + ":\n" + printMessages(mids, true));
}
@@ -480,8 +487,9 @@ public class CommandsManager {
}
Message reply = messagesService.getReply(mid, newrid);
applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
- return CommandResult.fromMessage(reply,"Reply posted.\n#" + mid + "/" + newrid + " "
- + "https://juick.com/" + mid + "#" + newrid);
+ return CommandResult.build(reply,"Reply posted.\n#" + mid + "/" + newrid + " "
+ + "https://juick.com/" + mid + "#" + newrid,
+ String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply)));
}
}
diff --git a/juick-common/src/main/java/com/juick/server/helpers/CommandResult.java b/juick-common/src/main/java/com/juick/server/helpers/CommandResult.java
index 292441151..a772153b4 100644
--- a/juick-common/src/main/java/com/juick/server/helpers/CommandResult.java
+++ b/juick-common/src/main/java/com/juick/server/helpers/CommandResult.java
@@ -2,21 +2,28 @@ package com.juick.server.helpers;
import com.juick.Message;
+import java.util.Optional;
+
public class CommandResult {
private String text;
+ private String markdown;
private Message newMessage;
public String getText() {
return text;
}
+ public String getMarkdown() {
+ return markdown;
+ }
- public Message getNewMessage() {
- return newMessage;
+ public Optional<Message> getNewMessage() {
+ return Optional.of(newMessage);
}
- public static CommandResult fromMessage(Message newMessage, String text) {
+ public static CommandResult build(Message newMessage, String text, String markdown) {
CommandResult result = new CommandResult();
result.newMessage = newMessage;
result.text = text;
+ result.markdown = markdown;
return result;
}
public static CommandResult fromString(String text) {
diff --git a/juick-common/src/main/java/com/juick/server/util/TagUtils.java b/juick-common/src/main/java/com/juick/server/util/TagUtils.java
index 9edeab32a..cb828933b 100644
--- a/juick-common/src/main/java/com/juick/server/util/TagUtils.java
+++ b/juick-common/src/main/java/com/juick/server/util/TagUtils.java
@@ -36,7 +36,7 @@ public class TagUtils {
if (CollectionUtils.isEmpty(tags))
return StringUtils.EMPTY;
- return tags.stream().map(t -> " *" + t.getName())
- .collect(Collectors.joining());
+ return tags.stream().map(t -> "*" + t.getName())
+ .collect(Collectors.joining(" "));
}
}