aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/XMPPConnection.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-29 10:23:04 +0300
committerGravatar Vitaly Takmazov2018-11-29 10:23:04 +0300
commit55cf2dd357088d7bbe0efff6a483679301ab2c22 (patch)
treeda28f282204eda9ebc41a1c5eda553d343ad3bf2 /src/main/java/com/juick/server/XMPPConnection.java
parentaf4ab437d158faec8db8c62bfd88c27dd4f59c8a (diff)
XMPP PMs refactoring
Diffstat (limited to 'src/main/java/com/juick/server/XMPPConnection.java')
-rw-r--r--src/main/java/com/juick/server/XMPPConnection.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/com/juick/server/XMPPConnection.java b/src/main/java/com/juick/server/XMPPConnection.java
index 979ba1fd..f77b2354 100644
--- a/src/main/java/com/juick/server/XMPPConnection.java
+++ b/src/main/java/com/juick/server/XMPPConnection.java
@@ -216,7 +216,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
Jid initiator = e.getInitiator();
ClientMessage result = incomingMessageJuick(
userService.getUserByJID(initiator.asBareJid().toEscapedString()), initiator,
- e.getDescription(), URI.create(String.format("juick://%s", targetFilename)));
+ jid.getLocal(), StringUtils.defaultString(e.getDescription()).trim(), URI.create(String.format("juick://%s", targetFilename)));
if (result != null) {
router.send(result);
}
@@ -594,16 +594,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
attachment = oobX.getUri();
}
try {
- if (msg.getTo().asBareJid().equals(jid.asBareJid())) {
- return incomingMessageJuick(user_from, msg.getFrom(), StringUtils.defaultString(msg.getBody()), attachment);
- } else {
- // PM
- if (!StringUtils.isEmpty(msg.getBody())) {
- result = incomingMessageJuick(user_from, msg.getFrom(),
- String.format("@%s %s", msg.getTo().getLocal(), StringUtils.defaultString(msg.getBody())), attachment);
- }
- }
- messagesService.getUnread(user_from).forEach(mid -> messagesService.setRead(user_from, mid));
+ return incomingMessageJuick(user_from, msg.getFrom(), msg.getTo().getLocal(), StringUtils.defaultString(msg.getBody()).trim(), attachment);
} catch (Exception e1) {
logger.warn("message exception", e1);
}
@@ -621,11 +612,13 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
}
return result;
}
- private ClientMessage incomingMessageJuick(User user_from, Jid from, String command, @Nonnull URI attachment) {
+ private ClientMessage incomingMessageJuick(User user_from, Jid from, String to, String command, @Nonnull URI attachment) {
if (StringUtils.isBlank(command) && attachment.toString().isEmpty()) {
return null;
}
+ messagesService.getUnread(user_from).forEach(mid -> messagesService.setRead(user_from, mid));
+
int commandlen = command.length();
// COMPATIBILITY
@@ -633,8 +626,16 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
command = command.substring(3);
}
+ if (!jid.getLocal().equals(to)) {
+ // PM
+ if (!StringUtils.isEmpty(command)) {
+ commandsManager.commandPM(user_from, null, to, command);
+ return null;
+ }
+ }
+
try {
- CommandResult result = commandsManager.processCommand(user_from, command.trim(), attachment);
+ CommandResult result = commandsManager.processCommand(user_from, command, attachment);
if (StringUtils.isNotBlank(result.getText())) {
return makeReply(from, result.getText());
}