aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/XMPPConnection.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-26 10:55:22 +0300
committerGravatar Vitaly Takmazov2018-03-26 10:55:22 +0300
commit6108e4b2fd2dd231096d6b4512c4cdb4e56e74e7 (patch)
treed343d9323baf28564e19d09f274fb5d516302400 /juick-server/src/main/java/com/juick/server/XMPPConnection.java
parent5863621118700b538ab01ba3a74a0b013e1334c7 (diff)
server: publish events from xmpp
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/XMPPConnection.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPConnection.java8
1 files changed, 8 insertions, 0 deletions
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())