From c0ccfe940d00f4eeb888c5f721e8a63c415daeb3 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sun, 17 Nov 2013 02:13:22 +0700 Subject: SubscriptionsQueries.getJIDSubscribedToUser --- src/com/juick/server/SubscriptionsQueries.java | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/com/juick/server') diff --git a/src/com/juick/server/SubscriptionsQueries.java b/src/com/juick/server/SubscriptionsQueries.java index d7b7fbc3..9f9468cd 100644 --- a/src/com/juick/server/SubscriptionsQueries.java +++ b/src/com/juick/server/SubscriptionsQueries.java @@ -16,13 +16,40 @@ import java.util.ArrayList; */ public class SubscriptionsQueries { + public static ArrayList getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) { + ArrayList jids = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + if (friendsonly == false) { + stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1"); + stmt.setInt(1, uid); + } else { + stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1 AND jids.user_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=?)"); + stmt.setInt(1, uid); + stmt.setInt(2, uid); + } + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + jids.add(rs.getString(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return jids; + } + public static ArrayList getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) { ArrayList jids = new ArrayList(); PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT jid FROM subscr_messages WHERE message_id=? AND active=b'1' AND suser_id!=? AND jid!=''"); + stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_messages INNER JOIN jids ON (subscr_messages.message_id=? AND subscr_messages.suser_id=jids.user_id) WHERE jids.user_id!=? AND jids.active=1"); stmt.setInt(1, mid); stmt.setInt(2, ignore_uid); rs = stmt.executeQuery(); -- cgit v1.2.3