aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java41
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java11
2 files changed, 14 insertions, 38 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 c73b7cb1..a96e3180 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
@@ -546,11 +546,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
String signuphash = userService.getSignUpHashByJID(msg.getFrom().asBareJid().toEscapedString());
return makeReply(msg.getFrom(), "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
}
- Jid jid = msg.getTo();
- if (jid.getDomain().equals(router.getDomain().toEscapedString()) || jid.equals(this.jid)) {
+ Jid to = msg.getTo();
+ if (to.getDomain().equals(router.getDomain().toEscapedString()) || to.equals(this.jid)) {
com.juick.Message jmsg = msg.getExtension(com.juick.Message.class);
if (jmsg != null) {
- if (jid.getLocal().equals("pm")) {
+ if (to.getLocal().equals("pm")) {
applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
} else {
if (MessageUtils.isReply(jmsg)) {
@@ -575,38 +575,9 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
router.send(result);
}
} 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));
- return ClientMessage.from(reply);
- }
-
- 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 pm = new com.juick.Message();
- pm.setUser(user_from);
- pm.setTo(userService.getUserByUID(uid_to).get());
- pm.setText(msg.getBody());
- applicationEventPublisher.publishEvent(new MessageEvent(this, pm));
- } 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));
- return ClientMessage.from(reply);
- }
+ // PM
+ result = incomingMessageJuick(user_from, msg.getFrom(),
+ String.format("@%s %s", msg.getTo().getLocal(), StringUtils.defaultString(msg.getBody())), attachment);
}
} catch (Exception e1) {
logger.warn("message exception", e1);
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 43bc119e..358fac3d 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -532,10 +532,10 @@ public class ServerTests {
}
@Test
public void botIsUpAndProcessingResourceConstraints() throws Exception {
- int renhaId;
- renhaId = userService.createUser("renha", "umnnbt");
+ int renhaId = userService.createUser("renha", "umnnbt");
Jid from = Jid.of("renha@serverstorageisfull.tld");
- jdbcTemplate.update("INSERT INTO jids(user_id,jid,active) VALUES(?,?,?)", renhaId, from.toEscapedString(), 1);
+ jdbcTemplate.update("INSERT INTO jids(user_id,jid,active) VALUES(?,?,?)",
+ renhaId, from.toEscapedString(), 1);
rocks.xmpp.core.stanza.model.Message xmppMessage = new rocks.xmpp.core.stanza.model.Message();
xmppMessage.setType(rocks.xmpp.core.stanza.model.Message.Type.ERROR);
xmppMessage.setFrom(from);
@@ -560,6 +560,11 @@ public class ServerTests {
xmppMessage.setBody("PING");
result = router.incomingMessage(xmppMessage);
assertThat(result.getBody(), equalTo("PONG"));
+ int secretlySadId = userService.createUser("secretlysad", "bbk");
+ xmppMessage.setTo(botJid.withLocal("secretlysad"));
+ xmppMessage.setBody("What's up?");
+ result = router.incomingMessage(xmppMessage);
+ assertThat(result.getBody(), startsWith("Private message sent"));
}
@Test
public void botCommandsTests() throws Exception {