diff options
Diffstat (limited to 'juick-server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/XMPPConnection.java | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index c246fdd6..ee67a15c 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -207,14 +207,14 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } } } else { - route(ClientMessage.from(message)); + s2s(ClientMessage.from(message)); } }); router.addInboundIQListener(e -> { IQ iq = e.getIQ(); Jid jid = iq.getTo(); if (!jid.getDomain().equals(this.jid.getDomain())) { - route(iq); + s2s(iq); } }); FileTransferManager fileTransferManager = router.getManager(FileTransferManager.class); @@ -286,7 +286,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } } - String stanzaToString(Stanza stanza) throws XMLStreamException, JAXBException { + private String stanzaToString(Stanza stanza) throws XMLStreamException, JAXBException { StringWriter stanzaWriter = new StringWriter(); XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter( router.getConfiguration().getXmlOutputFactory().createXMLStreamWriter(stanzaWriter)); @@ -296,7 +296,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { return stanzaWriter.toString(); } - void route(Stanza stanza) { + private void s2s(Stanza stanza) { try { String xml = stanzaToString(stanza); logger.info("stream router (out): {}", xml); @@ -307,13 +307,9 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } - public void sendStanza(Stanza xml) { - router.send(xml); - } - - public void sendJuickMessage(com.juick.Message jmsg) { + private void sendJuickMessage(com.juick.Message jmsg) { List<String> jids = new ArrayList<>(); if (jmsg.FriendsOnly) { @@ -352,7 +348,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } for (String jid : jids) { msg.setTo(Jid.of(jid)); - route(ClientMessage.from(msg)); + s2s(ClientMessage.from(msg)); } } @@ -384,7 +380,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { for (User user : users) { for (String jid : userService.getJIDsbyUID(user.getUid())) { msg.setTo(Jid.of(jid)); - route(ClientMessage.from(msg)); + s2s(ClientMessage.from(msg)); } } } @@ -408,7 +404,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { mm.setFrom(jid); mm.setBody("Private message from @" + msg.getUser().getName() + ":\n" + msg.getText()); } - xmpp.sendOut(ClientMessage.from(mm)); + s2s(ClientMessage.from(mm)); }); } else if (!isReply) { String notify = "New message posted.\n#" + msg.getMid() + " https://juick.com/" + msg.getMid(); @@ -417,13 +413,13 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } } - void sendReply(Jid jidTo, String txt) { + private void sendReply(Jid jidTo, String txt) { Message reply = new Message(); reply.setFrom(jid); reply.setTo(jidTo); reply.setType(Message.Type.CHAT); reply.setBody(txt); - xmpp.sendOut(ClientMessage.from(reply)); + s2s(ClientMessage.from(reply)); } @Override @@ -477,7 +473,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { for (User user : users) { for (String jid : userService.getJIDsbyUID(user.getUid())) { msg.setTo(Jid.of(jid)); - route(ClientMessage.from(msg)); + s2s(ClientMessage.from(msg)); } } } @@ -489,7 +485,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { Presence p = new Presence(Jid.of(userJid)); p.setFrom(jid); p.setPriority((byte) 10); - xmpp.sendOut(ClientPresence.from(p)); + s2s(ClientPresence.from(p)); }); } @@ -502,7 +498,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setFrom(p.getTo().asBareJid()); reply.setTo(p.getFrom().asBareJid()); reply.setType(Presence.Type.UNSUBSCRIBE); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } else if (p.getType().equals(Presence.Type.PROBE)) { int uid_to = 0; if (!toJuick) { @@ -517,7 +513,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { if (!userService.getActiveJIDs().contains(p.getFrom().asBareJid().toEscapedString())) { reply.setStatus("Send ON to enable notifications"); } - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } else { Presence reply = new Presence(); reply.setFrom(p.getTo()); @@ -525,7 +521,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setType(Presence.Type.ERROR); reply.setId(p.getId()); reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND)); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } } else if (p.getType().equals(Presence.Type.SUBSCRIBE)) { boolean canSubscribe = false; @@ -543,12 +539,12 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setFrom(p.getTo()); reply.setTo(p.getFrom()); reply.setType(Presence.Type.SUBSCRIBED); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); reply.setFrom(reply.getFrom().withResource(jid.getResource())); reply.setPriority((byte) 10); reply.setType(null); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } else { Presence reply = new Presence(); reply.setFrom(p.getTo()); @@ -556,7 +552,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setType(Presence.Type.ERROR); reply.setId(p.getId()); reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND)); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } } else if (p.getType().equals(Presence.Type.UNSUBSCRIBE)) { if (!toJuick) { @@ -570,7 +566,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setFrom(p.getTo()); reply.setTo(p.getFrom()); reply.setType(Presence.Type.UNSUBSCRIBED); - xmpp.sendOut(ClientPresence.from(reply)); + s2s(ClientPresence.from(reply)); } } @@ -604,7 +600,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setTo(msg.getFrom()); reply.setType(Message.Type.CHAT); reply.setBody("Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: 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."); - xmpp.sendOut(ClientMessage.from(reply)); + s2s(ClientMessage.from(reply)); return true; } @@ -625,7 +621,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setType(Message.Type.ERROR); reply.setId(msg.getId()); reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND)); - xmpp.sendOut(ClientMessage.from(reply)); + s2s(ClientMessage.from(reply)); return true; } @@ -647,7 +643,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { reply.setType(Message.Type.ERROR); reply.setId(msg.getId()); reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.NOT_ALLOWED)); - xmpp.sendOut(ClientMessage.from(reply)); + s2s(ClientMessage.from(reply)); } return false; @@ -684,11 +680,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } else if (xmlValue instanceof Message) { Message msg = (Message) xmlValue; if (!incomingMessage(msg)) { - sendStanza(msg); + router.send(msg); } } else if (xmlValue instanceof IQ) { IQ iq = (IQ) xmlValue; - sendStanza(iq); + router.send(iq); } } @@ -701,7 +697,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { userService.getActiveJIDs().forEach(j -> { try { presence.setTo(Jid.of(j)); - xmpp.sendOut(ClientPresence.from(presence)); + s2s(ClientPresence.from(presence)); } catch (IllegalArgumentException ex) { logger.warn("Invalid jid: {}", j, ex); } |