diff options
author | 2018-03-22 12:09:35 +0300 | |
---|---|---|
committer | 2018-03-22 12:09:35 +0300 | |
commit | 17e72bb8c612e34ec3aac56dd906bd9fefc2bc7c (patch) | |
tree | f84400450dea9a77ef741062ddf71bbb0535d6b4 /juick-server/src/main/java/com/juick/server/XMPPBot.java | |
parent | 679731ebbea77a7d361a53bb8280d1869c2a95d3 (diff) |
server: event listeners are beans
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/XMPPBot.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/XMPPBot.java | 27 |
1 files changed, 12 insertions, 15 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 e9eacdd7..f9cdf9c8 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPBot.java +++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java @@ -88,21 +88,11 @@ public class XMPPBot implements StanzaListener, AutoCloseable { @Inject private ApplicationEventPublisher applicationEventPublisher; - private ApplicationListener<MessageEvent> onMessage; - @PostConstruct public void init() { xmpp.addStanzaListener(this); broadcastPresence(null); pt = new PrettyTime(new Locale("ru")); - onMessage = event -> { - com.juick.Message msg = event.getMessage(); - if (msg.getRid() == 0 && msg.getMid() > 0) { - String notify = "New message posted.\n#" + msg.getMid() + " https://juick.com/" + msg.getMid(); - userService.getJIDsbyUID(msg.getUser().getUid()) - .forEach(jid -> sendReply(Jid.of(jid), notify)); - } - }; } public Jid getJid() { @@ -239,7 +229,7 @@ public class XMPPBot implements StanzaListener, AutoCloseable { if (username.equals(jid.getLocal())) { try { - return incomingMessageJuick(user_from, msg); + return incomingMessageJuick(user_from, msg.getFrom(), msg.getBody().trim()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return false; } @@ -324,8 +314,7 @@ public class XMPPBot implements StanzaListener, AutoCloseable { } return Optional.empty(); } - public boolean incomingMessageJuick(User user_from, Message msg) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - String command = msg.getBody().trim(); + public boolean incomingMessageJuick(User user_from, Jid from, String command) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { int commandlen = command.length(); // COMPATIBILITY @@ -333,9 +322,9 @@ public class XMPPBot implements StanzaListener, AutoCloseable { command = command.substring(3).trim(); } - Optional<String> result = processCommand(user_from, msg.getFrom(), command); + Optional<String> result = processCommand(user_from, from, command); if (result.isPresent()) { - sendReply(msg.getFrom(), result.get()); + sendReply(from, result.get()); } else { // new message List<Tag> tags = tagService.fromString(command, false); @@ -347,6 +336,14 @@ public class XMPPBot implements StanzaListener, AutoCloseable { return true; } + public void processMessage(com.juick.Message msg) { + if (msg.getRid() == 0 && msg.getMid() > 0) { + String notify = "New message posted.\n#" + msg.getMid() + " https://juick.com/" + msg.getMid(); + userService.getJIDsbyUID(msg.getUser().getUid()) + .forEach(jid -> sendReply(Jid.of(jid), notify)); + } + } + @UserCommand(pattern = "^ping$", patternFlags = Pattern.CASE_INSENSITIVE, help = "PING - returns you a PONG") public String commandPing(User user, Jid from, String[] input) { |