From 0b19e12587e25f51a2f398bb9014b71ff9aacbbd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 18 Dec 2017 21:52:28 +0300 Subject: xmpp: fix tests --- .../main/java/com/juick/components/JuickBot.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'juick-xmpp/src/main') 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 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(); -- cgit v1.2.3