aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-27 09:49:21 +0300
committerGravatar Vitaly Takmazov2018-03-27 09:49:21 +0300
commited4067c05b68fdb70f8a1edbf520627cd96845d9 (patch)
tree35b0d7a86c86d39c0077ca91c3991fa7bab06ea5 /juick-server
parent7bd9d90ce7716a4224442967a6e06f023a2b66a2 (diff)
server: xmpp refactoring
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPBot.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPConnection.java48
2 files changed, 26 insertions, 26 deletions
diff --git a/juick-server/src/main/java/com/juick/server/XMPPBot.java b/juick-server/src/main/java/com/juick/server/XMPPBot.java
index c304473c..dda7b6de 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPBot.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java
@@ -763,10 +763,6 @@ public class XMPPBot implements StanzaListener, AutoCloseable {
xmpp.sendOut(ClientMessage.from(reply));
}
- void sendNotification(Stanza stanza) {
- xmpp.sendOut(stanza);
- }
-
@Override
public void stanzaReceived(Stanza xmlValue) {
if (xmlValue instanceof Presence) {
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 16f7b869..77ffebd4 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
@@ -82,7 +82,9 @@ public class XMPPConnection implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(XMPPConnection.class);
private ExternalComponent router;
- private XMPPBot bot;
+ private XMPPServer xmpp;
+ @Value("${xmppbot_jid:juick@localhost}")
+ private Jid jid;
@Value("${componentname:localhost}")
private String componentName;
@@ -96,11 +98,11 @@ public class XMPPConnection implements AutoCloseable {
private String tmpDir;
@Inject
- public MessagesService messagesService;
+ private MessagesService messagesService;
@Inject
- public UserService userService;
+ private UserService userService;
@Inject
- public SubscriptionService subscriptionService;
+ private SubscriptionService subscriptionService;
@Inject
private BasicXmppSession session;
@Inject
@@ -111,17 +113,20 @@ public class XMPPConnection implements AutoCloseable {
@PostConstruct
public void init() {
logger.info("stream router start connecting to {}", componentPort);
- router = ExternalComponent.create(componentName, password, session.getConfiguration(), "localhost", componentPort);
+ router = ExternalComponent.create(componentName, password, session.getConfiguration(), "localhost",
+ componentPort);
PingManager pingManager = router.getManager(PingManager.class);
pingManager.setEnabled(true);
router.disableFeature(EntityCapabilities.NAMESPACE);
SoftwareVersionManager softwareVersionManager = router.getManager(SoftwareVersionManager.class);
- softwareVersionManager.setSoftwareVersion(new SoftwareVersion("Juick", "2.x", System.getProperty("os.name", "generic")));
+ softwareVersionManager.setSoftwareVersion(new SoftwareVersion("Juick", "2.x",
+ System.getProperty("os.name", "generic")));
VCard vCard = new VCard();
vCard.setFormattedName("Juick");
try {
vCard.setUrl(new URL("http://juick.com/"));
- vCard.setPhoto(new VCard.Image("image/png", IOUtils.toByteArray(getClass().getClassLoader().getResource("juick.png"))));
+ vCard.setPhoto(new VCard.Image("image/png", IOUtils.toByteArray(
+ getClass().getClassLoader().getResource("juick.png"))));
} catch (MalformedURLException e) {
logger.error("invalid url", e);
} catch (IOException e) {
@@ -130,8 +135,8 @@ public class XMPPConnection implements AutoCloseable {
router.addIQHandler(VCard.class, new AbstractIQHandler(IQ.Type.GET) {
@Override
protected IQ processRequest(IQ iq) {
- if (iq.getTo().equals(bot.getJid()) || iq.getTo().asBareJid().equals(bot.getJid().asBareJid())
- || iq.getTo().asBareJid().toEscapedString().equals(bot.getJid().getDomain())) {
+ if (iq.getTo().equals(jid) || iq.getTo().asBareJid().equals(jid.asBareJid())
+ || iq.getTo().asBareJid().toEscapedString().equals(jid.getDomain())) {
return iq.createResult(vCard);
}
User user = userService.getUserByName(iq.getTo().getLocal());
@@ -173,12 +178,13 @@ public class XMPPConnection implements AutoCloseable {
applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
} else if (jmsg.getMid() > 0) {
sendJuickMessage(jmsg);
- applicationEventPublisher.publishEvent(new MessageEvent(this, messagesService.getMessage(jmsg.getMid())));
+ applicationEventPublisher.publishEvent(new MessageEvent(this,
+ messagesService.getMessage(jmsg.getMid())));
}
}
}
- } else if (jid.getDomain().endsWith(bot.getJid().getDomain()) && (jid.getDomain().equals(bot.getJid().getDomain())
- || jid.getDomain().endsWith("." + bot.getJid().getDomain()))) {
+ } else if (jid.getDomain().endsWith(jid.getDomain()) && (jid.getDomain().equals(this.jid.getDomain())
+ || jid.getDomain().endsWith("." + jid.getDomain()))) {
if (logger.isInfoEnabled()) {
try {
logger.info("unhandled message: {}", stanzaToString(message));
@@ -193,7 +199,7 @@ public class XMPPConnection implements AutoCloseable {
router.addInboundIQListener(e -> {
IQ iq = e.getIQ();
Jid jid = iq.getTo();
- if (!jid.getDomain().equals(bot.getJid().getDomain())) {
+ if (!jid.getDomain().equals(this.jid.getDomain())) {
route(iq);
}
});
@@ -218,7 +224,7 @@ public class XMPPConnection implements AutoCloseable {
Message msg = new Message();
msg.setType(Message.Type.CHAT);
msg.setFrom(e.getInitiator());
- msg.setTo(bot.getJid());
+ msg.setTo(jid);
msg.setBody(e.getDescription());
try {
String attachmentUrl = String.format("juick://%s", targetFilename);
@@ -231,7 +237,7 @@ public class XMPPConnection implements AutoCloseable {
logger.info("transfer failed", ft.getException());
Message msg = new Message();
msg.setType(Message.Type.CHAT);
- msg.setFrom(bot.getJid());
+ msg.setFrom(jid);
msg.setTo(e.getInitiator());
msg.setBody("File transfer failed, please report to us");
router.sendMessage(msg);
@@ -280,7 +286,7 @@ public class XMPPConnection implements AutoCloseable {
try {
String xml = stanzaToString(stanza);
logger.debug("stream router (out): {}", xml);
- bot.sendNotification(stanza);
+ xmpp.sendOut(stanza);
} catch (XMLStreamException | JAXBException e) {
logger.error("JAXB exception", e);
}
@@ -301,9 +307,7 @@ public class XMPPConnection implements AutoCloseable {
} else {
List<User> users = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid());
for (User user : users) {
- for (String jid : userService.getJIDsbyUID(user.getUid())) {
- jids.add(jid);
- }
+ jids.addAll(userService.getJIDsbyUID(user.getUid()));
}
}
com.juick.Message fullMsg = messagesService.getMessage(jmsg.getMid());
@@ -318,7 +322,7 @@ public class XMPPConnection implements AutoCloseable {
Nickname nick = new Nickname("@" + jmsg.getUser().getName());
Message msg = new Message();
- msg.setFrom(bot.getJid());
+ msg.setFrom(jid);
msg.setBody(txt);
msg.setType(Message.Type.CHAT);
msg.setThread("juick-" + jmsg.getMid());
@@ -359,7 +363,7 @@ public class XMPPConnection implements AutoCloseable {
txt += StringUtils.defaultString(jmsg.getText()) + "\n\n" + "#" + jmsg.getMid() + "/" + jmsg.getRid() + " http://juick.com/" + jmsg.getMid() + "#" + jmsg.getRid();
Message msg = new Message();
- msg.setFrom(bot.getJid());
+ msg.setFrom(jid);
msg.setBody(txt);
msg.setType(Message.Type.CHAT);
msg.addExtension(jmsg);
@@ -397,7 +401,7 @@ public class XMPPConnection implements AutoCloseable {
Nickname nick = new Nickname("@" + jmsg.getUser().getName());
Message msg = new Message();
- msg.setFrom(bot.getJid());
+ msg.setFrom(jid);
msg.setBody(txt);
msg.setType(Message.Type.CHAT);
msg.setThread("juick-" + jmsg.getMid());