aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
committerGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
commitbd3892546b51f0d31e959d45c138b009d35b2692 (patch)
tree3c3945f114472344cc3a8866391fa08f02975143 /src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
parentf2a2660e753fa11478fd3edadfdff9c000b22cc9 (diff)
spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
index 4634ca99..c96a5cce 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
@@ -1,7 +1,9 @@
package com.juick.xmpp.s2s;
+import com.juick.User;
import com.juick.server.MessagesQueries;
import com.juick.server.SubscriptionsQueries;
+import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.extensions.JuickMessage;
@@ -9,6 +11,7 @@ import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
import com.juick.xmpp.utils.SHA1;
import com.juick.xmpp.utils.XmlUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
import org.xmlpull.v1.XmlPullParser;
import java.io.IOException;
@@ -143,16 +146,16 @@ public class ConnectionRouter extends Connection implements Runnable {
}
public void sendJuickMessage(JuickMessage jmsg) {
- List<String> jids;
+ List<User> users;
- synchronized (XMPPComponent.sqlSync) {
- if (jmsg.FriendsOnly) {
- jids = SubscriptionsQueries.getJIDSubscribedToUser(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.FriendsOnly);
- } else {
- jids = SubscriptionsQueries.getJIDSubscribedToUserAndTags(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID());
- }
+
+ if (jmsg.FriendsOnly) {
+ users = SubscriptionsQueries.getUsersSubscribedToUser(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.FriendsOnly);
+ } else {
+ users = SubscriptionsQueries.getSubscribedUsers(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID());
}
+
String txt = "@" + jmsg.getUser().getUName() + ":" + jmsg.getTagsString() + "\n";
String attachment = jmsg.getAttachmentURL();
if (attachment != null) {
@@ -176,21 +179,19 @@ public class ConnectionRouter extends Connection implements Runnable {
oob.URL = attachment;
msg.addChild(oob);
}
-
- for (int i = 0; i < jids.size(); i++) {
- msg.to = new JID(jids.get(i));
- XMPPComponent.sendOut(msg);
+ for (User user : users) {
+ for (String jid : UserQueries.getActiveJIDs(XMPPComponent.sql, user)) {
+ msg.to = new JID(jid);
+ XMPPComponent.sendOut(msg);
+ }
}
}
public void sendJuickComment(JuickMessage jmsg) {
- List<String> jids;
String replyQuote;
- synchronized (XMPPComponent.sqlSync) {
- jids = SubscriptionsQueries.getJIDSubscribedToComments(XMPPComponent.sql, jmsg.getMID(), jmsg.getUser().getUID());
- replyQuote = getReplyQuote(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo);
- }
+ List<User> users = SubscriptionsQueries.getSubscribedUsers(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID());
+ replyQuote = getReplyQuote(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo);
String txt = "Reply by @" + jmsg.getUser().getUName() + ":\n" + replyQuote + "\n";
String attachment = jmsg.getAttachmentURL();
@@ -204,13 +205,16 @@ public class ConnectionRouter extends Connection implements Runnable {
msg.body = txt;
msg.type = Message.Type.chat;
msg.addChild(jmsg);
- for (int i = 0; i < jids.size(); i++) {
- msg.to = new JID(jids.get(i));
- XMPPComponent.sendOut(msg);
+ for (User user : users) {
+ // TODO: make single query
+ for (String jid : UserQueries.getActiveJIDs(XMPPComponent.sql, user)) {
+ msg.to = new JID(jid);
+ XMPPComponent.sendOut(msg);
+ }
}
}
- private String getReplyQuote(java.sql.Connection sql, int MID, int ReplyTo) {
+ private String getReplyQuote(JdbcTemplate sql, int MID, int ReplyTo) {
String quote = "";
if (ReplyTo > 0) {
com.juick.Message q = MessagesQueries.getReply(sql, MID, ReplyTo);
@@ -232,13 +236,10 @@ public class ConnectionRouter extends Connection implements Runnable {
}
public void sendJuickRecommendation(JuickMessage recomm) {
- List<String> jids;
JuickMessage jmsg;
- synchronized (XMPPComponent.sqlSync) {
- jmsg = new JuickMessage(MessagesQueries.getMessage(XMPPComponent.sql, recomm.getMID()));
- jids = SubscriptionsQueries.getJIDSubscribedToUserRecommendations(XMPPComponent.sql,
- recomm.getUser().getUID(), recomm.getMID(), jmsg.getUser().getUID());
- }
+ jmsg = new JuickMessage(MessagesQueries.getMessage(XMPPComponent.sql, recomm.getMID()));
+ List<User> users = SubscriptionsQueries.getUsersSubscribedToComments(XMPPComponent.sql,
+ recomm.getMID(), jmsg.getUser().getUID());
String txt = "Recommended by @" + recomm.getUser().getUName() + ":\n";
txt += "@" + jmsg.getUser().getUName() + ":" + jmsg.getTagsString() + "\n";
@@ -272,10 +273,11 @@ public class ConnectionRouter extends Connection implements Runnable {
oob.URL = attachment;
msg.addChild(oob);
}
-
- for (int i = 0; i < jids.size(); i++) {
- msg.to = new JID(jids.get(i));
- XMPPComponent.sendOut(msg);
+ for (User user : users) {
+ for (String jid : UserQueries.getActiveJIDs(XMPPComponent.sql, user)) {
+ msg.to = new JID(jid);
+ XMPPComponent.sendOut(msg);
+ }
}
}
}