diff options
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java index 443bfa82..d0b3a93b 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.*; import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.Nickname; @@ -9,6 +11,8 @@ import com.juick.xmpp.extensions.XOOB; import java.io.IOException; import java.net.Socket; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -45,13 +49,18 @@ public class ConnectionRouter implements Stream.StreamListener, } public void sendJuickMessage(JuickMessage jmsg) { - List<String> jids; + List<String> jids = new ArrayList<>(); 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()); + List<User> users = SubscriptionsQueries.getSubscribedUsers(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID()); + for (User user : users) { + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + jids.add(jid); + } + } } } @@ -86,14 +95,14 @@ public class ConnectionRouter implements Stream.StreamListener, } public void sendJuickComment(JuickMessage jmsg) { - List<String> jids; + List<User> users; String replyQuote; String replyTo; synchronized (XMPPComponent.sqlSync) { - jids = SubscriptionsQueries.getJIDSubscribedToComments(XMPPComponent.sql, jmsg.getMID(), jmsg.getUser().getUID()); - com.juick.Message replyMessage = jmsg.ReplyTo > 0 ? MessagesQueries.getReply(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo) - : MessagesQueries.getMessage(XMPPComponent.sql, jmsg.getMID()); + users = SubscriptionsQueries.getUsersSubscribedToComments(XMPPComponent.sql, jmsg.getMID(), jmsg.getUser().getUID()); + com.juick.Message replyMessage = jmsg.ReplyTo > 0 ? MessagesQueries.getReply(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo) + : MessagesQueries.getMessage(XMPPComponent.sql, jmsg.getMID()); replyTo = replyMessage.getUser().getUName(); replyQuote = getReplyQuote(replyMessage); } @@ -110,9 +119,13 @@ public class ConnectionRouter implements Stream.StreamListener, msg.body = txt; msg.type = Message.Type.chat; msg.addChild(jmsg); - for (String jid : jids) { - msg.to = new JID(jid); - XMPPComponent.sendOut(msg); + for (User user : users) { + synchronized (XMPPComponent.sqlSync) { + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + msg.to = new JID(jid); + XMPPComponent.sendOut(msg); + } + } } } @@ -127,11 +140,11 @@ public class ConnectionRouter implements Stream.StreamListener, } public void sendJuickRecommendation(JuickMessage recomm) { - List<String> jids; + List<User> users; JuickMessage jmsg; synchronized (XMPPComponent.sqlSync) { jmsg = new JuickMessage(MessagesQueries.getMessage(XMPPComponent.sql, recomm.getMID())); - jids = SubscriptionsQueries.getJIDSubscribedToUserRecommendations(XMPPComponent.sql, + users = SubscriptionsQueries.getUsersSubscribedToUserRecommendations(XMPPComponent.sql, recomm.getUser().getUID(), recomm.getMID(), jmsg.getUser().getUID()); } @@ -168,9 +181,13 @@ public class ConnectionRouter implements Stream.StreamListener, msg.addChild(oob); } - for (String jid : jids) { - msg.to = new JID(jid); - XMPPComponent.sendOut(msg); + for (User user : users) { + synchronized (XMPPComponent.sqlSync) { + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + msg.to = new JID(jid); + XMPPComponent.sendOut(msg); + } + } } } |