aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/ServerManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-30 14:18:56 +0300
committerGravatar Vitaly Takmazov2018-03-30 14:18:56 +0300
commita746598faef08af794c66d65ba9324bee5043b73 (patch)
treeeff6bd472547df069b3fcbd3da2e29f750d58626 /juick-server/src/main/java/com/juick/server/ServerManager.java
parent42e2a727c2bc15ac15c9a3af66f126dbefe508a2 (diff)
server: process everything in one place
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/ServerManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java32
1 files changed, 7 insertions, 25 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java
index 22b78905..6cac270c 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -30,13 +30,10 @@ import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import rocks.xmpp.addr.Jid;
-import rocks.xmpp.core.stanza.model.Message;
-import rocks.xmpp.extensions.oob.model.x.OobX;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.List;
import java.util.stream.Collectors;
@@ -58,31 +55,16 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
@Value("${service_user:juick}")
private String serviceUser;
@Inject
- private XMPPConnection xmppConnection;
+ private XMPPConnection router;
- public void sendMessage(Message message) {
- xmppConnection.getRouter().sendMessage(message);
- }
-
- public void processMessage(User visitor, String body, String attachmentName) {
- Message xmsg = new Message();
- xmsg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl"));
- xmsg.setTo(Jid.of("juick@juick.com/Juick"));
- xmsg.setBody(body);
- try {
- if (StringUtils.isNotEmpty(attachmentName)) {
- URI httpUri = URI.create(attachmentName);
- if (httpUri.isAbsolute()) {
- xmsg.addExtension(new OobX(httpUri));
- } else {
- String attachmentUrl = String.format("juick://%s", attachmentName);
- xmsg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!"));
- }
+ public com.juick.Message processMessage(User visitor, String body, String attachmentName) throws Exception {
+ if (StringUtils.isNotEmpty(attachmentName)) {
+ URI httpUri = URI.create(attachmentName);
+ if (!httpUri.isAbsolute()) {
+ attachmentName = String.format("juick://%s", attachmentName);
}
- } catch (URISyntaxException e1) {
- logger.warn("attachment error", e1);
}
- sendMessage(xmsg);
+ return router.incomingMessageJuick(visitor, Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl"), body, URI.create(attachmentName));
}
private void onJuickPM(final int uid_to, final com.juick.Message jmsg) {