diff options
Diffstat (limited to 'src/main/java/com/juick/xmpp')
-rw-r--r-- | src/main/java/com/juick/xmpp/JuickBot.java | 52 | ||||
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionListener.java | 8 | ||||
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/S2SComponent.java | 11 |
3 files changed, 39 insertions, 32 deletions
diff --git a/src/main/java/com/juick/xmpp/JuickBot.java b/src/main/java/com/juick/xmpp/JuickBot.java index 6104d19d..56260f97 100644 --- a/src/main/java/com/juick/xmpp/JuickBot.java +++ b/src/main/java/com/juick/xmpp/JuickBot.java @@ -1,6 +1,6 @@ package com.juick.xmpp; -import com.juick.JuickNotificator; +import com.juick.JuickApplication; import com.juick.User; import com.juick.server.PMQueries; import com.juick.server.TagQueries; @@ -22,12 +22,14 @@ public class JuickBot { JdbcTemplate sql; Stream xmpp; - JuickNotificator notificator; + JuickApplication notificator; + S2SComponent s2s; - public JuickBot(JuickNotificator notificator, JdbcTemplate sql, Stream xmpp) { + public JuickBot(JuickApplication notificator, S2SComponent s2s) { this.notificator = notificator; - this.sql = sql; - this.xmpp = xmpp; + sql = notificator.getSql(); + xmpp = notificator.getRouter(); + this.s2s = s2s; } public static final JID JuickJID = new JID("juick", "juick.com", "Juick"); @@ -74,7 +76,7 @@ public class JuickBot { reply.from = new JID(p.to.Username, p.to.Host, null); reply.to = new JID(p.from.Username, p.from.Host, null); reply.type = Presence.Type.unsubscribe; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } else if (p.type.equals(Presence.Type.probe)) { int uid_to = 0; @@ -88,12 +90,12 @@ public class JuickBot { reply.from.Resource = "Juick"; reply.to = p.from; reply.priority = 10; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } return true; @@ -111,19 +113,19 @@ public class JuickBot { if (canSubscribe) { Presence reply = new Presence(p.to, p.from, Presence.Type.subscribed); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); reply.from.Resource = "Juick"; reply.priority = 10; reply.type = null; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } } else if (p.type.equals(Presence.Type.unsubscribe)) { @@ -135,7 +137,7 @@ public class JuickBot { } Presence reply = new Presence(p.to, p.from, Presence.Type.unsubscribed); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } return false; @@ -162,7 +164,7 @@ public class JuickBot { } else { reply.body = "Внимание, системное сообщение!\nВаш JabberID не обнаружен в списке доверенных. Для того, чтобы отправить сообщение пользователю " + username + "@juick.com, пожалуйста зарегистрируйте свой JabberID в системе: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nWarning, system message!\nYour JabberID is not found in our server's white list. To send a message to " + username + "@juick.com, 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."; } - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } @@ -176,7 +178,7 @@ public class JuickBot { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } @@ -217,14 +219,14 @@ public class JuickBot { mm.from = new JID("juick", "juick.com", "Juick"); mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body; } - S2SComponent.sendOut(mm); + s2s.sendOut(mm); } } else { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; reply.addChild(new Error(Error.Type.cancel, "not-allowed")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } return true; @@ -268,26 +270,26 @@ public class JuickBot { return false; } - private static void commandPing(Message m) { + private void commandPing(Message m) { Presence p = new Presence(JuickJID, m.from); p.priority = 10; - S2SComponent.sendOut(p); + s2s.sendOut(p); Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = "PONG"; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } - private static void commandHelp(Message m) { + private void commandHelp(Message m) { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = HELPTEXT; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandLogin(Message m, User user_from) { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = "http://juick.com/login?" + UserQueries.getHashByUID(sql, user_from.getUID()); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandPM(Message m, User user_from, String user_to, String body) { @@ -346,7 +348,7 @@ public class JuickBot { mm.from = new JID("juick", "juick.com", "Juick"); mm.body = "Private message from @" + user_from.getUName() + ":\n" + body; } - S2SComponent.sendOut(mm); + s2s.sendOut(mm); } } @@ -358,7 +360,7 @@ public class JuickBot { reply.type = Message.Type.error; reply.body = "Error " + ret; } - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandBLShow(Message m, User user_from) { @@ -390,6 +392,6 @@ public class JuickBot { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = txt; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } } diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java index 28ff48f9..320df347 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java @@ -1,5 +1,6 @@ package com.juick.xmpp.s2s; +import com.juick.JuickApplication; import com.juick.xmpp.JuickBot; import com.juick.xmpp.Stream; @@ -23,10 +24,11 @@ public class ConnectionListener implements Runnable { JuickBot bot; Stream xmpp; - public ConnectionListener(ExecutorService executorService, JuickBot bot, Stream xmpp) { - this.executorService = executorService; + public ConnectionListener(JuickApplication app, JuickBot bot) { + this.executorService = app.getExecutorService(); + this.xmpp = app.getRouter(); this.bot = bot; - this.xmpp = xmpp; + } @Override diff --git a/src/main/java/com/juick/xmpp/s2s/S2SComponent.java b/src/main/java/com/juick/xmpp/s2s/S2SComponent.java index dcb547fb..b7155643 100644 --- a/src/main/java/com/juick/xmpp/s2s/S2SComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/S2SComponent.java @@ -1,5 +1,6 @@ package com.juick.xmpp.s2s; +import com.juick.JuickApplication; import com.juick.JuickComponent; import com.juick.User; import com.juick.server.MessagesQueries; @@ -33,6 +34,7 @@ public class S2SComponent implements JuickComponent { static final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>()); static final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>()); JdbcTemplate sql; + JuickBot bot; final public static HashMap<String, StanzaChild> childParsers = new HashMap<>(); public static void addConnectionIn(ConnectionIn c) { @@ -147,14 +149,15 @@ public class S2SComponent implements JuickComponent { } } - public S2SComponent(JdbcTemplate sql, ExecutorService executorService, Properties conf) { + public S2SComponent(JuickApplication application, Properties conf) { LOGGER.info("component initialized"); HOSTNAME = conf.getProperty("hostname"); componentName = conf.getProperty("componentname"); STATSFILE = conf.getProperty("statsfile"); - this.sql = sql; - this.executorService = executorService; - executorService.submit(new ConnectionListener(executorService)); + this.sql = application.getSql(); + this.executorService = application.getExecutorService(); + this.bot = new JuickBot(application, this); + executorService.submit(new ConnectionListener(application, bot)); executorService.submit(new CleaningUp()); } @Override |