From b03bca4032912981b9cb642a1ec94143c3410afc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 26 Mar 2018 17:04:30 +0300 Subject: xmpp: view tag command --- juick-server/src/main/java/com/juick/server/XMPPBot.java | 10 ++++++++++ .../src/test/java/com/juick/server/tests/ServerTests.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'juick-server') 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 a3335596..41c98856 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPBot.java +++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java @@ -675,6 +675,16 @@ public class XMPPBot implements StanzaListener, AutoCloseable { } return "Reply not found"; } + @UserCommand(pattern = "^\\*(\\S+)(\\+?)$", help = "*tag - Show last messages with tag") + public String commandShowTag(User user, Jid from, String... arguments) { + Tag tag = tagService.getTag(arguments[0], false); + if (tag != null) { + // TODO: synonims + List mids = messagesService.getTag(tag.TID, user.getUid(), 0, 10); + return "Last messages with *" + tag.getName() + ":\n" + printMessages(mids, true); + } + return "Tag 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 fcc0a422..b8c9d524 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 @@ -391,7 +391,7 @@ public class ServerTests { 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(31)); + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(32)); } @Test -- cgit v1.2.3