aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-12-18 21:52:28 +0300
committerGravatar Vitaly Takmazov2017-12-18 21:52:28 +0300
commit0b19e12587e25f51a2f398bb9014b71ff9aacbbd (patch)
tree1f3de3b3b49bc436cc242f5d33a40132e8dfbeb6 /juick-xmpp/src/main/java
parent86118361420b2d441e824e4f113a1f4f4c75664b (diff)
xmpp: fix tests
Diffstat (limited to 'juick-xmpp/src/main/java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/JuickBot.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
index 15e1fe66..937645d0 100644
--- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
@@ -551,7 +551,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
}
@UserCommand(pattern = "^(s|u)\\s+#(\\d+)$", help = "S #1234 - subscribe to comments",
patternFlags = Pattern.CASE_INSENSITIVE)
- public String commandSubscribeMessage(User user, String... args) {
+ public String commandSubscribeMessage(User user, Jid from, String... args) {
boolean subscribe = args[0].equalsIgnoreCase("s");
int mid = NumberUtils.toInt(args[1], 0);
if (messagesService.getMessage(mid) != null) {
@@ -570,7 +570,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
}
@UserCommand(pattern = "^(on|off)$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "ON/OFF - Enable/disable subscriptions delivery")
- public String commandOnOff(User user, String[] input) {
+ public String commandOnOff(User user, Jid from, String[] input) {
UserService.ActiveStatus newStatus;
String retValUpdated;
if (input[0].toLowerCase().equals("on")) {
@@ -589,7 +589,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
}
@UserCommand(pattern = "^\\@([^\\s\\n\\+]+)(\\+?)$",
help = "@username+ - Show user's info and last 10 messages (@username++ - second page, ..)")
- public String commandUser(User user, String... arguments) {
+ public String commandUser(User user, Jid from, String... arguments) {
User blogUser = userService.getUserByName(arguments[0]);
int page = arguments[1].length();
if (blogUser.getUid() > 0) {
@@ -601,6 +601,25 @@ public class JuickBot implements StanzaListener, AutoCloseable {
}
return "User not found";
}
+ @UserCommand(pattern = "^#(\\d+)(\\+?)$", help = "#1234 - Show message (#1234+ - message with replies)")
+ public String commandShow(User user, Jid from, String... arguments) {
+ boolean showReplies = arguments[1].length() > 0;
+ int mid = NumberUtils.toInt(arguments[0], 0);
+ if (mid == 0) {
+ return "Error";
+ }
+ com.juick.Message msg = messagesService.getMessage(mid);
+ if (msg != null) {
+ if (showReplies) {
+ List<com.juick.Message> replies = messagesService.getReplies(mid);
+ replies.add(0, msg);
+ return String.join("\n",
+ replies.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList()));
+ }
+ return PlainTextFormatter.formatPost(msg);
+ }
+ return "Message not found";
+ }
void sendReply(Jid jidTo, String txt) {
Message reply = new Message();