diff options
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components')
3 files changed, 45 insertions, 55 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index a26389ea..b5065c74 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -1,6 +1,7 @@ package com.juick.components; import com.juick.components.s2s.*; +import com.juick.service.*; import com.juick.xmpp.JID; import com.juick.xmpp.Stanza; import com.juick.xmpp.StanzaChild; @@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import org.xmlpull.v1.XmlPullParserException; +import javax.inject.Inject; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; @@ -45,6 +47,17 @@ public class XMPPServer implements AutoCloseable { final public HashMap<String, StanzaChild> childParsers = new HashMap<>(); + @Inject + public MessagesService messagesService; + @Inject + public UserService userService; + @Inject + public TagService tagService; + @Inject + public PMQueriesService pmQueriesService; + @Inject + public SubscriptionService subscriptionService; + public XMPPServer(Environment env, ExecutorService service) { this.service = service; @@ -67,7 +80,6 @@ public class XMPPServer implements AutoCloseable { if (!disabled) { router = new ConnectionRouter(this, componentName, componentPort, env.getProperty("xmpp_password")); - service.submit(router); service.submit(() -> { diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java index cb3bc46f..d9763709 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java @@ -2,9 +2,6 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.service.MessagesService; -import com.juick.service.SubscriptionService; -import com.juick.service.UserService; import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.extensions.JuickMessage; @@ -19,7 +16,6 @@ import org.slf4j.LoggerFactory; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import javax.inject.Inject; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; @@ -41,13 +37,6 @@ public class ConnectionRouter extends Connection implements Runnable { private int componentPort; private String password; - @Inject - SubscriptionService subscriptionService; - @Inject - UserService userService; - @Inject - MessagesService messagesService; - public ConnectionRouter(XMPPServer s2s, String componentName, int componentPort, String password) throws Exception { super(s2s); this.componentName = componentName; @@ -152,11 +141,11 @@ public class ConnectionRouter extends Connection implements Runnable { List<String> jids = new ArrayList<>(); if (jmsg.FriendsOnly) { - jids = subscriptionService.getJIDSubscribedToUser(jmsg.getUser().getUid(), jmsg.FriendsOnly); + jids = xmpp.subscriptionService.getJIDSubscribedToUser(jmsg.getUser().getUid(), jmsg.FriendsOnly); } else { - List<User> users = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()); + List<User> users = xmpp.subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()); for (User user : users) { - for (String jid : userService.getJIDsbyUID(user.getUid())) { + for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { jids.add(jid); } } @@ -197,11 +186,11 @@ public class ConnectionRouter extends Connection implements Runnable { String replyQuote; String replyTo; - users = subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()); - com.juick.Message replyMessage = jmsg.getReplyto() > 0 ? messagesService.getReply(jmsg.getMid(), jmsg.getReplyto()) - : messagesService.getMessage(jmsg.getMid()); + users = xmpp.subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()); + com.juick.Message replyMessage = jmsg.getReplyto() > 0 ? xmpp.messagesService.getReply(jmsg.getMid(), jmsg.getReplyto()) + : xmpp.messagesService.getMessage(jmsg.getMid()); replyTo = replyMessage.getUser().getName(); - com.juick.Message fullReply = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); + com.juick.Message fullReply = xmpp.messagesService.getReply(jmsg.getMid(), jmsg.getRid()); replyQuote = fullReply.getReplyQuote(); String txt = "Reply by @" + jmsg.getUser().getName() + ":\n" + replyQuote + "\n@" + replyTo + " "; @@ -217,7 +206,7 @@ public class ConnectionRouter extends Connection implements Runnable { msg.type = Message.Type.chat; msg.addChild(jmsg); for (User user : users) { - for (String jid : userService.getJIDsbyUID(user.getUid())) { + for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { msg.to = new JID(jid); xmpp.sendOut(msg); } @@ -227,8 +216,8 @@ public class ConnectionRouter extends Connection implements Runnable { public void sendJuickRecommendation(JuickMessage recomm) { List<User> users; JuickMessage jmsg; - jmsg = new JuickMessage(messagesService.getMessage(recomm.getMid())); - users = subscriptionService.getUsersSubscribedToUserRecommendations(recomm.getUser().getUid(), + jmsg = new JuickMessage(xmpp.messagesService.getMessage(recomm.getMid())); + users = xmpp.subscriptionService.getUsersSubscribedToUserRecommendations(recomm.getUser().getUid(), recomm.getMid(), jmsg.getUser().getUid()); String txt = "Recommended by @" + recomm.getUser().getName() + ":\n"; @@ -265,7 +254,7 @@ public class ConnectionRouter extends Connection implements Runnable { } for (User user : users) { - for (String jid : userService.getJIDsbyUID(user.getUid())) { + for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { msg.to = new JID(jid); xmpp.sendOut(msg); } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java index 1b989249..2ed3eaf5 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java @@ -2,17 +2,12 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.server.TagQueries; -import com.juick.service.PMQueriesService; -import com.juick.service.TagService; -import com.juick.service.UserService; import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.extensions.Error; import com.juick.xmpp.extensions.JuickMessage; -import javax.inject.Inject; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -23,12 +18,6 @@ import java.util.regex.Pattern; */ public class JuickBot { XMPPServer xmpp; - @Inject - UserService userService; - @Inject - PMQueriesService pmQueriesService; - @Inject - TagService tagService; public JuickBot(XMPPServer xmpp, JID jid) { this.xmpp = xmpp; @@ -84,7 +73,7 @@ public class JuickBot { } else if (p.type.equals(Presence.Type.probe)) { int uid_to = 0; if (!toJuick) { - uid_to = userService.getUIDbyName(username); + uid_to = xmpp.userService.getUIDbyName(username); } if (toJuick || uid_to > 0) { @@ -107,9 +96,9 @@ public class JuickBot { if (toJuick) { canSubscribe = true; } else { - int uid_to = userService.getUIDbyName(username); + int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - pmQueriesService.addPMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.addPMinRoster(uid_to, p.from.Bare()); canSubscribe = true; } } @@ -133,9 +122,9 @@ public class JuickBot { } } else if (p.type.equals(Presence.Type.unsubscribe)) { if (!toJuick) { - int uid_to = userService.getUIDbyName(username); + int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - pmQueriesService.removePMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.removePMinRoster(uid_to, p.from.Bare()); } } @@ -155,9 +144,9 @@ public class JuickBot { User user_from = null; String signuphash = ""; - user_from = userService.getUserByJID(msg.from.Bare()); + user_from = xmpp.userService.getUserByJID(msg.from.Bare()); if (user_from == null) { - signuphash = userService.getSignUpHashByJID(msg.from.Bare()); + signuphash = xmpp.userService.getSignUpHashByJID(msg.from.Bare()); } if (user_from == null) { @@ -175,7 +164,7 @@ public class JuickBot { return incomingMessageJuick(user_from, msg); } - int uid_to = userService.getUIDbyName(username); + int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to == 0) { Message reply = new Message(msg.to, msg.from, Message.Type.error); @@ -186,8 +175,8 @@ public class JuickBot { } boolean success = false; - if (!userService.isInBLAny(uid_to, user_from.getUid())) { - success = pmQueriesService.createPM(user_from.getUid(), uid_to, msg.body); + if (!xmpp.userService.isInBLAny(uid_to, user_from.getUid())) { + success = xmpp.pmQueriesService.createPM(user_from.getUid(), uid_to, msg.body); } if (success) { @@ -205,12 +194,12 @@ public class JuickBot { List<String> jids; boolean inroster = false; - jids = userService.getJIDsbyUID(uid_to); + jids = xmpp.userService.getJIDsbyUID(uid_to); for (String jid : jids) { Message mm = new Message(); mm.to = new JID(jid); mm.type = Message.Type.chat; - inroster = pmQueriesService.havePMinRoster(user_from.getUid(), jid); + inroster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (inroster) { mm.from = new JID(jmsg.getUser().getName(), "juick.com", "Juick"); mm.body = msg.body; @@ -286,7 +275,7 @@ public class JuickBot { private void commandLogin(Message m, User user_from) throws Exception { Message reply = new Message(jid, m.from, Message.Type.chat); - reply.body = "http://juick.com/login?" + userService.getHashByUID(user_from.getUid()); + reply.body = "http://juick.com/login?" + xmpp.userService.getHashByUID(user_from.getUid()); xmpp.sendOut(reply); } @@ -298,15 +287,15 @@ public class JuickBot { boolean haveInRoster = false; if (user_to.indexOf('@') > 0) { - uid_to = userService.getUIDbyJID(user_to); + uid_to = xmpp.userService.getUIDbyJID(user_to); } else { - uid_to = userService.getUIDbyName(user_to); + uid_to = xmpp.userService.getUIDbyName(user_to); } if (uid_to > 0) { - if (!userService.isInBLAny(uid_to, user_from.getUid())) { - if (pmQueriesService.createPM(user_from.getUid(), uid_to, body)) { - jids_to = userService.getJIDsbyUID(uid_to); + if (!xmpp.userService.isInBLAny(uid_to, user_from.getUid())) { + if (xmpp.pmQueriesService.createPM(user_from.getUid(), uid_to, body)) { + jids_to = xmpp.userService.getJIDsbyUID(uid_to); ret = 200; } else { ret = 500; @@ -335,7 +324,7 @@ public class JuickBot { Message mm = new Message(); mm.to = new JID(jid); mm.type = Message.Type.chat; - haveInRoster = pmQueriesService.havePMinRoster(user_from.getUid(), jid); + haveInRoster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (haveInRoster) { mm.from = new JID(user_from.getName(), "juick.com", "Juick"); mm.body = body; @@ -359,8 +348,8 @@ public class JuickBot { } private void commandBLShow(Message m, User user_from) throws Exception { - List<User> blusers = userService.getUserBLUsers(user_from.getUid()); - List<String> bltags = tagService.getUserBLTags(user_from.getUid()); + List<User> blusers = xmpp.userService.getUserBLUsers(user_from.getUid()); + List<String> bltags = xmpp.tagService.getUserBLTags(user_from.getUid()); String txt = ""; if (bltags.size() > 0) { |