aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/XMPPBot.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-28 21:19:07 +0300
committerGravatar Vitaly Takmazov2018-03-28 21:19:07 +0300
commit4b3ddcd138af69f504a9a08281edc1c2e7eb0c7a (patch)
treed1e6b3cc63184564a0ab3d7c59513e5e46b15b1c /juick-server/src/main/java/com/juick/server/XMPPBot.java
parent31226138eb63b25a3b666ad782412a2024b50f74 (diff)
PM events
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.java87
1 files changed, 24 insertions, 63 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 dda7b6de..5f9f83e6 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPBot.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java
@@ -259,31 +259,11 @@ public class XMPPBot implements StanzaListener, AutoCloseable {
}
if (success) {
- Message m = new Message();
- m.setFrom(jid.asBareJid());
com.juick.Message jmsg = new com.juick.Message();
jmsg.setUser(user_from);
jmsg.setTo(userService.getUserByUID(uid_to).get());
jmsg.setText(msg.getBody());
- m.addExtension(jmsg);
-
- List<String> jids;
- boolean inroster = false;
- jids = userService.getJIDsbyUID(uid_to);
- for (String userJid : jids) {
- Message mm = new Message();
- mm.setTo(Jid.of(userJid));
- mm.setType(Message.Type.CHAT);
- inroster = pmQueriesService.havePMinRoster(user_from.getUid(), userJid);
- if (inroster) {
- mm.setFrom(Jid.of(jmsg.getUser().getName(), "juick.com", "Juick"));
- mm.setBody(msg.getBody());
- } else {
- mm.setFrom(jid);
- mm.setBody("Private message from @" + jmsg.getUser().getName() + ":\n" + msg.getBody());
- }
- xmpp.sendOut(ClientMessage.from(mm));
- }
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
} else {
Message reply = new Message();
reply.setFrom(msg.getTo());
@@ -347,6 +327,22 @@ public class XMPPBot implements StanzaListener, AutoCloseable {
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));
+ } else if (msg.getTo() != null) {
+ userService.getJIDsbyUID(msg.getTo().getUid())
+ .forEach(userJid -> {
+ Message mm = new Message();
+ mm.setTo(Jid.of(userJid));
+ mm.setType(Message.Type.CHAT);
+ boolean inroster = pmQueriesService.havePMinRoster(msg.getUser().getUid(), userJid);
+ if (inroster) {
+ mm.setFrom(Jid.of(msg.getUser().getName(), "juick.com", "Juick"));
+ mm.setBody(msg.getText());
+ } else {
+ mm.setFrom(jid);
+ mm.setBody("Private message from @" + msg.getUser().getName() + ":\n" + msg.getText());
+ }
+ xmpp.sendOut(ClientMessage.from(mm));
+ });
}
}
@@ -377,57 +373,22 @@ public class XMPPBot implements StanzaListener, AutoCloseable {
@UserCommand(pattern = "^\\@(\\S+)\\s+([\\s\\S]+)$", help = "@username message - send PM to username")
public String commandPM(User user_from, Jid from, String... arguments) {
String body = arguments[1];
- int ret = 0;
User user_to = userService.getUserByName(arguments[0]);
- List<String> jids_to = null;
- boolean haveInRoster = false;
if (user_to.getUid() > 0) {
if (!userService.isInBLAny(user_to.getUid(), user_from.getUid())) {
if (pmQueriesService.createPM(user_from.getUid(), user_to.getUid(), body)) {
- jids_to = userService.getJIDsbyUID(user_to.getUid());
- ret = 200;
- } else {
- ret = 500;
+ com.juick.Message jmsg = new com.juick.Message();
+ jmsg.setUser(user_from);
+ jmsg.setTo(user_to);
+ jmsg.setText(body);
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ return "Private message sent";
}
- } else {
- ret = 403;
}
- } else {
- ret = 404;
- }
-
- if (ret == 200) {
- Message msg = new Message();
- msg.setFrom(jid.asBareJid());
- com.juick.Message jmsg = new com.juick.Message();
- jmsg.setUser(user_from);
- jmsg.setTo(user_to);
- jmsg.setText(body);
- msg.addExtension(jmsg);
-
- for (String userJid : jids_to) {
- Message mm = new Message();
- mm.setTo(Jid.of(userJid));
- mm.setType(Message.Type.CHAT);
- haveInRoster = pmQueriesService.havePMinRoster(user_from.getUid(), userJid);
- if (haveInRoster) {
- mm.setFrom(Jid.of(user_from.getName(), "juick.com", "Juick"));
- mm.setBody(body);
- } else {
- mm.setFrom(jid);
- mm.setBody("Private message from @" + user_from.getName() + ":\n" + body);
- }
- xmpp.sendOut(ClientMessage.from(mm));
- }
- }
-
- if (ret == 200) {
- return "Private message sent";
- } else {
- return "Error " + ret;
}
+ return "Error";
}
@UserCommand(pattern = "^bl$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "BL - Show your blacklist")