aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java5
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java10
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java3
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java38
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java55
5 files changed, 61 insertions, 50 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 7be2400ac..a26389ea0 100644
--- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
@@ -10,7 +10,6 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
@@ -44,13 +43,11 @@ public class XMPPServer implements AutoCloseable {
private final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
private final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>());
- public JdbcTemplate jdbc;
final public HashMap<String, StanzaChild> childParsers = new HashMap<>();
- public XMPPServer(Environment env, ExecutorService service, JdbcTemplate jdbc) {
+ public XMPPServer(Environment env, ExecutorService service) {
this.service = service;
- this.jdbc = jdbc;
logger.info("component initialized");
try {
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
index 5a19270b9..31ffae9eb 100644
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
@@ -5,12 +5,12 @@ package com.juick.components.configuration;
*/
import com.juick.components.XMPPServer;
+import com.juick.configuration.DataConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.DependsOn;
+import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
-import org.springframework.jdbc.core.JdbcTemplate;
import javax.inject.Inject;
import java.util.concurrent.ExecutorService;
@@ -18,16 +18,14 @@ import java.util.concurrent.Executors;
@Configuration
@PropertySource("classpath:juick.conf")
+@Import(DataConfiguration.class)
public class XmppAppConfiguration {
@Inject
private Environment env;
- @Inject
- private JdbcTemplate jdbcTemplate;
@Bean
- @DependsOn("jdbcTemplate")
public XMPPServer xmpp() {
- return new XMPPServer(env, service(), jdbcTemplate);
+ return new XMPPServer(env, service());
}
@Bean
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
index 89dd69e18..ee2ddceb7 100644
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
@@ -1,6 +1,5 @@
package com.juick.components.configuration;
-import com.juick.configuration.DataConfiguration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -13,7 +12,7 @@ public class XmppInitializer extends AbstractAnnotationConfigDispatcherServletIn
@Override
protected Class<?>[] getRootConfigClasses() {
- return new Class<?>[]{XmppAppConfiguration.class, DataConfiguration.class};
+ return new Class<?>[]{XmppAppConfiguration.class};
}
@Override
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 9272a3d0f..cb3bc46f4 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,9 @@ package com.juick.components.s2s;
import com.juick.User;
import com.juick.components.XMPPServer;
-import com.juick.server.MessagesQueries;
-import com.juick.server.SubscriptionsQueries;
-import com.juick.server.UserQueries;
+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,6 +19,7 @@ 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;
@@ -40,6 +41,13 @@ 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;
@@ -144,11 +152,11 @@ public class ConnectionRouter extends Connection implements Runnable {
List<String> jids = new ArrayList<>();
if (jmsg.FriendsOnly) {
- jids = SubscriptionsQueries.getJIDSubscribedToUser(xmpp.jdbc, jmsg.getUser().getUid(), jmsg.FriendsOnly);
+ jids = subscriptionService.getJIDSubscribedToUser(jmsg.getUser().getUid(), jmsg.FriendsOnly);
} else {
- List<User> users = SubscriptionsQueries.getSubscribedUsers(xmpp.jdbc, jmsg.getUser().getUid(), jmsg.getMid());
+ List<User> users = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid());
for (User user : users) {
- for (String jid : UserQueries.getJIDsbyUID(xmpp.jdbc, user.getUid())) {
+ for (String jid : userService.getJIDsbyUID(user.getUid())) {
jids.add(jid);
}
}
@@ -189,11 +197,11 @@ public class ConnectionRouter extends Connection implements Runnable {
String replyQuote;
String replyTo;
- users = SubscriptionsQueries.getUsersSubscribedToComments(xmpp.jdbc, jmsg.getMid(), jmsg.getUser().getUid());
- com.juick.Message replyMessage = jmsg.getReplyto() > 0 ? MessagesQueries.getReply(xmpp.jdbc, jmsg.getMid(), jmsg.getReplyto())
- : MessagesQueries.getMessage(xmpp.jdbc, jmsg.getMid());
+ 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());
replyTo = replyMessage.getUser().getName();
- com.juick.Message fullReply = MessagesQueries.getReply(xmpp.jdbc, jmsg.getMid(), jmsg.getRid());
+ com.juick.Message fullReply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
replyQuote = fullReply.getReplyQuote();
String txt = "Reply by @" + jmsg.getUser().getName() + ":\n" + replyQuote + "\n@" + replyTo + " ";
@@ -209,7 +217,7 @@ public class ConnectionRouter extends Connection implements Runnable {
msg.type = Message.Type.chat;
msg.addChild(jmsg);
for (User user : users) {
- for (String jid : UserQueries.getJIDsbyUID(xmpp.jdbc, user.getUid())) {
+ for (String jid : userService.getJIDsbyUID(user.getUid())) {
msg.to = new JID(jid);
xmpp.sendOut(msg);
}
@@ -219,9 +227,9 @@ public class ConnectionRouter extends Connection implements Runnable {
public void sendJuickRecommendation(JuickMessage recomm) {
List<User> users;
JuickMessage jmsg;
- jmsg = new JuickMessage(MessagesQueries.getMessage(xmpp.jdbc, recomm.getMid()));
- users = SubscriptionsQueries.getUsersSubscribedToUserRecommendations(xmpp.jdbc,
- recomm.getUser().getUid(), recomm.getMid(), jmsg.getUser().getUid());
+ jmsg = new JuickMessage(messagesService.getMessage(recomm.getMid()));
+ users = subscriptionService.getUsersSubscribedToUserRecommendations(recomm.getUser().getUid(),
+ recomm.getMid(), jmsg.getUser().getUid());
String txt = "Recommended by @" + recomm.getUser().getName() + ":\n";
txt += "@" + jmsg.getUser().getName() + ":" + jmsg.getTagsString() + "\n";
@@ -257,7 +265,7 @@ public class ConnectionRouter extends Connection implements Runnable {
}
for (User user : users) {
- for (String jid : UserQueries.getJIDsbyUID(xmpp.jdbc, user.getUid())) {
+ for (String jid : 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 ac7d122f5..1b9892493 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,15 +2,17 @@ package com.juick.components.s2s;
import com.juick.User;
import com.juick.components.XMPPServer;
-import com.juick.server.PMQueries;
import com.juick.server.TagQueries;
-import com.juick.server.UserQueries;
+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;
@@ -21,6 +23,13 @@ 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;
this.jid = jid;
@@ -75,7 +84,7 @@ public class JuickBot {
} else if (p.type.equals(Presence.Type.probe)) {
int uid_to = 0;
if (!toJuick) {
- uid_to = UserQueries.getUIDbyName(xmpp.jdbc, username);
+ uid_to = userService.getUIDbyName(username);
}
if (toJuick || uid_to > 0) {
@@ -98,9 +107,9 @@ public class JuickBot {
if (toJuick) {
canSubscribe = true;
} else {
- int uid_to = UserQueries.getUIDbyName(xmpp.jdbc, username);
+ int uid_to = userService.getUIDbyName(username);
if (uid_to > 0) {
- PMQueries.addPMinRoster(xmpp.jdbc, uid_to, p.from.Bare());
+ pmQueriesService.addPMinRoster(uid_to, p.from.Bare());
canSubscribe = true;
}
}
@@ -124,9 +133,9 @@ public class JuickBot {
}
} else if (p.type.equals(Presence.Type.unsubscribe)) {
if (!toJuick) {
- int uid_to = UserQueries.getUIDbyName(xmpp.jdbc, username);
+ int uid_to = userService.getUIDbyName(username);
if (uid_to > 0) {
- PMQueries.removePMinRoster(xmpp.jdbc, uid_to, p.from.Bare());
+ pmQueriesService.removePMinRoster(uid_to, p.from.Bare());
}
}
@@ -146,9 +155,9 @@ public class JuickBot {
User user_from = null;
String signuphash = "";
- user_from = UserQueries.getUserByJID(xmpp.jdbc, msg.from.Bare());
+ user_from = userService.getUserByJID(msg.from.Bare());
if (user_from == null) {
- signuphash = UserQueries.getSignUpHashByJID(xmpp.jdbc, msg.from.Bare());
+ signuphash = userService.getSignUpHashByJID(msg.from.Bare());
}
if (user_from == null) {
@@ -166,7 +175,7 @@ public class JuickBot {
return incomingMessageJuick(user_from, msg);
}
- int uid_to = UserQueries.getUIDbyName(xmpp.jdbc, username);
+ int uid_to = userService.getUIDbyName(username);
if (uid_to == 0) {
Message reply = new Message(msg.to, msg.from, Message.Type.error);
@@ -177,8 +186,8 @@ public class JuickBot {
}
boolean success = false;
- if (!UserQueries.isInBLAny(xmpp.jdbc, uid_to, user_from.getUid())) {
- success = PMQueries.createPM(xmpp.jdbc, user_from.getUid(), uid_to, msg.body);
+ if (!userService.isInBLAny(uid_to, user_from.getUid())) {
+ success = pmQueriesService.createPM(user_from.getUid(), uid_to, msg.body);
}
if (success) {
@@ -196,12 +205,12 @@ public class JuickBot {
List<String> jids;
boolean inroster = false;
- jids = UserQueries.getJIDsbyUID(xmpp.jdbc, uid_to);
+ jids = userService.getJIDsbyUID(uid_to);
for (String jid : jids) {
Message mm = new Message();
mm.to = new JID(jid);
mm.type = Message.Type.chat;
- inroster = PMQueries.havePMinRoster(xmpp.jdbc, user_from.getUid(), jid);
+ inroster = pmQueriesService.havePMinRoster(user_from.getUid(), jid);
if (inroster) {
mm.from = new JID(jmsg.getUser().getName(), "juick.com", "Juick");
mm.body = msg.body;
@@ -277,7 +286,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?" + UserQueries.getHashByUID(xmpp.jdbc, user_from.getUid());
+ reply.body = "http://juick.com/login?" + userService.getHashByUID(user_from.getUid());
xmpp.sendOut(reply);
}
@@ -289,15 +298,15 @@ public class JuickBot {
boolean haveInRoster = false;
if (user_to.indexOf('@') > 0) {
- uid_to = UserQueries.getUIDbyJID(xmpp.jdbc, user_to);
+ uid_to = userService.getUIDbyJID(user_to);
} else {
- uid_to = UserQueries.getUIDbyName(xmpp.jdbc, user_to);
+ uid_to = userService.getUIDbyName(user_to);
}
if (uid_to > 0) {
- if (!UserQueries.isInBLAny(xmpp.jdbc, uid_to, user_from.getUid())) {
- if (PMQueries.createPM(xmpp.jdbc, user_from.getUid(), uid_to, body)) {
- jids_to = UserQueries.getJIDsbyUID(xmpp.jdbc, uid_to);
+ if (!userService.isInBLAny(uid_to, user_from.getUid())) {
+ if (pmQueriesService.createPM(user_from.getUid(), uid_to, body)) {
+ jids_to = userService.getJIDsbyUID(uid_to);
ret = 200;
} else {
ret = 500;
@@ -326,7 +335,7 @@ public class JuickBot {
Message mm = new Message();
mm.to = new JID(jid);
mm.type = Message.Type.chat;
- haveInRoster = PMQueries.havePMinRoster(xmpp.jdbc, user_from.getUid(), jid);
+ haveInRoster = pmQueriesService.havePMinRoster(user_from.getUid(), jid);
if (haveInRoster) {
mm.from = new JID(user_from.getName(), "juick.com", "Juick");
mm.body = body;
@@ -350,8 +359,8 @@ public class JuickBot {
}
private void commandBLShow(Message m, User user_from) throws Exception {
- List<User> blusers = UserQueries.getUserBLUsers(xmpp.jdbc, user_from.getUid());
- List<String> bltags = TagQueries.getUserBLTags(xmpp.jdbc, user_from.getUid());
+ List<User> blusers = userService.getUserBLUsers(user_from.getUid());
+ List<String> bltags = tagService.getUserBLTags(user_from.getUid());
String txt = "";
if (bltags.size() > 0) {