aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java44
1 files changed, 40 insertions, 4 deletions
diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
index db925400..7cdb7fcc 100644
--- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
@@ -191,12 +191,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
if (jid.getLocal().equals("pm")) {
applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
} else {
- if (jmsg.getRid() > 0) {
+ if (MessageUtils.isReply(jmsg)) {
// to get quote and attachment
com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
- } else if (jmsg.getMid() > 0) {
- sendJuickMessage(jmsg);
+ } else if (!MessageUtils.isPM(jmsg)) {
applicationEventPublisher.publishEvent(new MessageEvent(this,
messagesService.getMessage(jmsg.getMid())));
}
@@ -414,6 +413,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
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));
+ sendJuickMessage(msg);
}
}
@@ -587,7 +587,43 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
if (oobX != null) {
attachmentURI = oobX.getUri();
}
- incomingMessageJuick(user_from, msg.getFrom(), StringUtils.defaultString(msg.getBody()), attachmentURI);
+ if (msg.getTo().equals(jid)) {
+ incomingMessageJuick(user_from, msg.getFrom(), StringUtils.defaultString(msg.getBody()), attachmentURI);
+ } else {
+ int uid_to = userService.getUIDbyName(msg.getTo().getLocal());
+
+ if (uid_to == 0) {
+ Message reply = new Message();
+ reply.setFrom(msg.getTo());
+ reply.setTo(msg.getFrom());
+ reply.setType(Message.Type.ERROR);
+ reply.setId(msg.getId());
+ reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND));
+ router.send(ClientMessage.from(reply));
+ return;
+ }
+
+ boolean success = false;
+ if (!userService.isInBLAny(uid_to, user_from.getUid())) {
+ success = pmQueriesService.createPM(user_from.getUid(), uid_to, msg.getBody());
+ }
+
+ if (success) {
+ com.juick.Message jmsg = new com.juick.Message();
+ jmsg.setUser(user_from);
+ jmsg.setTo(userService.getUserByUID(uid_to).get());
+ jmsg.setText(msg.getBody());
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ } else {
+ Message reply = new Message();
+ reply.setFrom(msg.getTo());
+ reply.setTo(msg.getFrom());
+ reply.setType(Message.Type.ERROR);
+ reply.setId(msg.getId());
+ reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.NOT_ALLOWED));
+ router.send(ClientMessage.from(reply));
+ }
+ }
}
private void incomingMessageJuick(User user_from, Jid from, String command, @Nonnull URI attachment)
throws Exception {