From de81a033905d1c4cd18ac9b5af8a7f8fb853b121 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sun, 14 Apr 2013 06:44:35 +0700 Subject: PushQueries --- src/com/juick/server/MessagesQueries.java | 4 +- src/com/juick/server/PushQueries.java | 61 +++++++++++++++++++++++++++++++ src/com/juick/server/UserQueries.java | 12 ++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/com/juick/server/PushQueries.java (limited to 'src/com/juick/server') diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java index ad00b9d2..42b45c24 100644 --- a/src/com/juick/server/MessagesQueries.java +++ b/src/com/juick/server/MessagesQueries.java @@ -283,11 +283,11 @@ public class MessagesQueries { ResultSet rs = null; try { if (before > 0) { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 OR user_id=?) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 OR user_id=?) AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, before); stmt.setInt(2, visitor_uid); } else { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, visitor_uid); } rs = stmt.executeQuery(); diff --git a/src/com/juick/server/PushQueries.java b/src/com/juick/server/PushQueries.java new file mode 100644 index 00000000..a532622a --- /dev/null +++ b/src/com/juick/server/PushQueries.java @@ -0,0 +1,61 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.juick.server; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +/** + * + * @author ugnich + */ +public class PushQueries { + + public static ArrayList getAndroidSubscribers(Connection sql, int uid) { + ArrayList regids = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT regid FROM android INNER JOIN subscr_users ON (subscr_users.user_id=? AND android.user_id=subscr_users.suser_id)"); + stmt.setInt(1, uid); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + regids.add(rs.getString(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return regids; + } + + public static ArrayList getWinPhoneSubscribers(Connection sql, int uid) { + ArrayList urls = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT url FROM winphone INNER JOIN subscr_users ON (subscr_users.user_id=? AND winphone.user_id=subscr_users.suser_id)"); + stmt.setInt(1, uid); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + urls.add(rs.getString(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return urls; + } + +} diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index 17873676..a9f00f94 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -53,6 +53,18 @@ public class UserQueries { } finally { Utils.finishSQL(rs, stmt); } + + PreparedStatement stmt2 = null; + try { + stmt2 = sql.prepareStatement("INSERT INTO useroptions(user_id) VALUES (?)"); + stmt2.setInt(1, uid); + stmt2.executeUpdate(); + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + return uid; } -- cgit v1.2.3