From 6108e4b2fd2dd231096d6b4512c4cdb4e56e74e7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 26 Mar 2018 10:55:22 +0300 Subject: server: publish events from xmpp --- juick-server/src/main/java/com/juick/server/XMPPConnection.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'juick-server/src/main/java/com') diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index 03720a3f..d50c4400 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -18,6 +18,8 @@ package com.juick.server; import com.juick.User; +import com.juick.server.component.LikeEvent; +import com.juick.server.component.MessageEvent; import com.juick.server.xmpp.s2s.BasicXmppSession; import com.juick.server.helpers.UserInfo; import com.juick.service.MessagesService; @@ -31,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; @@ -103,6 +106,8 @@ public class XMPPConnection implements AutoCloseable { private BasicXmppSession session; @Inject private ExecutorService service; + @Inject + private ApplicationEventPublisher applicationEventPublisher; @PostConstruct public void init() { @@ -158,6 +163,8 @@ public class XMPPConnection implements AutoCloseable { if (jmsg != null) { if (jid.getLocal().equals("recomm")) { sendJuickRecommendation(jmsg); + User fromUser = userService.getUserByJID(message.getFrom().asBareJid().toEscapedString()); + applicationEventPublisher.publishEvent(new LikeEvent(this, fromUser, jmsg)); } else { if (jmsg.getRid() > 0) { // to get quote and attachment @@ -166,6 +173,7 @@ public class XMPPConnection implements AutoCloseable { } else if (jmsg.getMid() > 0) { sendJuickMessage(jmsg); } + applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg)); } } } else if (jid.getDomain().endsWith(bot.getJid().getDomain()) && (jid.getDomain().equals(bot.getJid().getDomain()) -- cgit v1.2.3