diff options
author | Vitaly Takmazov | 2018-01-30 13:30:20 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-01-30 13:30:20 +0300 |
commit | 59e0c016bcb3e5f5260bf35bed63994fc9df3016 (patch) | |
tree | 9d870ee328696bf6c5bcb8cc93164346f03f7104 /juick-xmpp/src | |
parent | 9c22987d6309b91fbe41bd47e410b1f809144c41 (diff) |
xmpp: S @username
Diffstat (limited to 'juick-xmpp/src')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/JuickBot.java | 18 | ||||
-rw-r--r-- | juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java | 4 |
2 files changed, 20 insertions, 2 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 7a25f5d5..2884fdd4 100644 --- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java @@ -528,6 +528,24 @@ public class JuickBot implements StanzaListener, AutoCloseable { } return "No favorite messages, try to \"like\" something ;)"; } + // TODO: target notification + @UserCommand(pattern = "^(s|u)\\s+\\@(\\S+)$", help = "S @username - subscribe to user" + + "\nU @username - unsubscribe from user", patternFlags = Pattern.CASE_INSENSITIVE) + public String commandSubscribeUser(User user, Jid from, String... args) { + boolean subscribe = args[0].equalsIgnoreCase("s"); + User toUser = userService.getUserByName(args[1]); + if (subscribe) { + if (subscriptionService.subscribeUser(user, toUser)) { + return "Subscribed to @" + toUser.getName(); + } + } else { + if (subscriptionService.unSubscribeUser(user, toUser)) { + return "Unsubscribed from @" + toUser.getName(); + } + return "You was not subscribed to @" + toUser.getName(); + } + return "Error"; + } @UserCommand(pattern = "^(s|u)\\s+\\*(\\S+)$", help = "S *tag - subscribe to tag" + "\nU *tag - unsubscribe from tag", patternFlags = Pattern.CASE_INSENSITIVE) public String commandSubscribeTag(User user, Jid from, String... args) { diff --git a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java index 537445ea..784c29b2 100644 --- a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java +++ b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java @@ -95,8 +95,8 @@ public class XMPPServerTests extends AbstractJUnit4SpringContextTests { @Test public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG")); - // tag help have two lines, others have 1 - assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(18)); + // tag and user help have two lines, others have 1 + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(20)); } @Test |