aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/jabber/ws/XMPPConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/jabber/ws/XMPPConnection.java')
-rw-r--r--src/main/java/com/juick/jabber/ws/XMPPConnection.java41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/main/java/com/juick/jabber/ws/XMPPConnection.java b/src/main/java/com/juick/jabber/ws/XMPPConnection.java
index df403083..1679ae8f 100644
--- a/src/main/java/com/juick/jabber/ws/XMPPConnection.java
+++ b/src/main/java/com/juick/jabber/ws/XMPPConnection.java
@@ -1,23 +1,23 @@
package com.juick.jabber.ws;
+import com.juick.User;
import com.juick.json.MessageSerializer;
import com.juick.server.MessagesQueries;
-import com.juick.server.Utils;
+import com.juick.server.SubscriptionsQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.extensions.JuickMessage;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
/**
*
@@ -25,11 +25,11 @@ import java.util.Iterator;
*/
public class XMPPConnection implements Runnable, Stream.StreamListener, Message.MessageListener {
- Connection sql;
+ JdbcTemplate sql;
Stream xmpp;
String xmppPassword;
- public XMPPConnection(Connection sql, String password) {
+ public XMPPConnection(JdbcTemplate sql, String password) {
this.sql = sql;
xmppPassword = password;
}
@@ -54,7 +54,7 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
}
@Override
- public void onStreamFail(Exception msg) {
+ public void onStreamFail(String msg) {
System.err.println("Stream failed: " + msg);
}
@@ -102,27 +102,8 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
String json = messageSerializer.serialize(jmsg).toString();
ByteBuffer bbMsg = buildTextFrame(json);
- ArrayList<Integer> uids = new ArrayList<Integer>();
- String query = "SELECT suser_id FROM subscr_users WHERE user_id=" + jmsg.getUser().getUID() +
- " AND suser_id NOT IN (SELECT user_id FROM bl_tags " +
- "INNER JOIN messages_tags USING(tag_id) WHERE message_id=" + jmsg.getMID() + ")";
- if (jmsg.Privacy < 0) {
- query += " AND suser_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=" + jmsg.getUser().getUID() + ")";
- }
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.createStatement();
- rs = stmt.executeQuery(query);
- rs.beforeFirst();
- while (rs.next()) {
- uids.add(rs.getInt(1));
- }
- } catch (SQLException e) {
- System.err.println("onJuickMessagePost: " + e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
+ List<Integer> uids = SubscriptionsQueries.getSubscribedUsers(sql, jmsg.getUser().getUID(), jmsg.getMID())
+ .stream().map(User::getUID).collect(Collectors.toList());
synchronized (Main.clients) {
for (Iterator<SocketSubscribed> i = Main.clients.iterator(); i.hasNext();) {