aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/server/SubscriptionsQueries.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-04-23 21:27:46 +0700
committerGravatar Ugnich Anton2014-04-23 21:27:46 +0700
commit3406753be46b637c0afee894cb12ed1bc5de9d29 (patch)
tree95a541edb549b01e328b6602fe8a41c19c0d5ff8 /src/com/juick/server/SubscriptionsQueries.java
parent29df00e4fa77ba4aeda0b9780e30c17dd57d92b2 (diff)
Recommendations (getJIDSubscribedToUserRecommendations)
Diffstat (limited to 'src/com/juick/server/SubscriptionsQueries.java')
-rw-r--r--src/com/juick/server/SubscriptionsQueries.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/com/juick/server/SubscriptionsQueries.java b/src/com/juick/server/SubscriptionsQueries.java
index ac465948..d0f5f308 100644
--- a/src/com/juick/server/SubscriptionsQueries.java
+++ b/src/com/juick/server/SubscriptionsQueries.java
@@ -126,6 +126,42 @@ public class SubscriptionsQueries {
return jids;
}
+ public static ArrayList<String> getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) {
+ ArrayList<String> jids = new ArrayList<String>();
+
+ ArrayList<Integer> tags = MessagesQueries.getMessageTagsIDs(sql, mid);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ String query = "SELECT jid FROM jids WHERE active=1 AND user_id!=" + uid;
+ query += " AND user_id IN (SELECT suser_id FROM subscr_users WHERE user_id=" + uid + ")";
+ query += " AND user_id NOT IN (SELECT user_id FROM bl_users WHERE bl_user_id=" + muid + ")";
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_users WHERE user_id=" + muid + ")";
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_messages WHERE message_id=" + mid + ")";
+ query += " AND user_id NOT IN (SELECT user_id FROM favorites WHERE message_id=" + mid + ")";
+ query += " AND user_id NOT IN (SELECT subscr_users.suser_id FROM subscr_users INNER JOIN favorites ON (favorites.message_id=" + mid + " AND subscr_users.user_id=favorites.user_id AND favorites.user_id!=" + uid + "))";
+ if (!tags.isEmpty()) {
+ String tagsStr = Utils.convertArrayInt2String(tags);
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_tags WHERE tag_id IN (" + tagsStr + "))";
+ query += " AND user_id NOT IN (SELECT user_id FROM bl_tags WHERE tag_id IN (" + tagsStr + "))";
+ }
+
+ stmt = sql.prepareStatement(query);
+ 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 boolean subscribeMessage(Connection sql, int mid, int vuid) {
return SQLHelpers.execute(sql, "INSERT IGNORE INTO subscr_messages(suser_id,message_id) VALUES (" + vuid + "," + mid + ")") == 1;
}