From 81f82943e8c37f47bd02d7490935121ff16f6d71 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 25 Feb 2018 08:46:01 +0300 Subject: xmpp: show reply command --- juick-server/src/main/java/com/juick/server/XMPPBot.java | 12 +++++++++++- .../src/test/java/com/juick/server/tests/ServerTests.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/juick-server/src/main/java/com/juick/server/XMPPBot.java b/juick-server/src/main/java/com/juick/server/XMPPBot.java index 1c17a0aa..a07dbe86 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPBot.java +++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java @@ -617,10 +617,20 @@ public class XMPPBot implements StanzaListener, AutoCloseable { return String.join("\n", replies.stream().map(PlainTextFormatter::formatPostSummary).collect(Collectors.toList())); } - return PlainTextFormatter.formatPostSummary(msg); + return PlainTextFormatter.formatPost(msg); } return "Message not found"; } + @UserCommand(pattern = "^#(\\d+)\\/(\\d+)$", help = "#1234/5 - Show reply") + public String commandShowReply(User user, Jid from, String... arguments) { + int mid = NumberUtils.toInt(arguments[0], 0); + int rid = NumberUtils.toInt(arguments[1], 0); + com.juick.Message reply = messagesService.getReply(mid, rid); + if (reply != null) { + return PlainTextFormatter.formatPost(reply); + } + return "Reply not found"; + } @UserCommand(pattern = "^D #(\\d+)$", help = "D #1234 - Delete post", patternFlags = Pattern.CASE_INSENSITIVE) public String commandDeletePost(User user, Jid from, String... args) { int mid = Integer.valueOf(args[0]); 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 c9c47a39..4496f68c 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 @@ -379,7 +379,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG")); // subscription commands have two lines, others have 1 - assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(23)); + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(24)); } @Test -- cgit v1.2.3