aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com/juick/server/CommandsManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-05 22:17:57 +0300
committerGravatar Vitaly Takmazov2018-04-05 22:17:57 +0300
commit767aec7729a326ff1ccc225d8623a24dd1e698d5 (patch)
treec694fc17767170200888a3348acebed67afe5e06 /juick-common/src/main/java/com/juick/server/CommandsManager.java
parent0cd08c7161fd3b5fe54d90b01ea35360ea5390dc (diff)
server: markdown command reply
* also fixes new messages with one tag and attachment
Diffstat (limited to 'juick-common/src/main/java/com/juick/server/CommandsManager.java')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java20
1 files changed, 14 insertions, 6 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 9bde0884..4f115577 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)));
}
}