aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/server/MessagesQueries.java23
-rw-r--r--src/main/java/com/juick/server/PushQueries.java26
2 files changed, 44 insertions, 5 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 99ab1ce4..7501e869 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -81,7 +81,11 @@ public class MessagesQueries {
try {
stmt = sql.prepareStatement("INSERT INTO messages_txt(message_id,tags,txt) VALUES (?,?,?)");
stmt.setInt(1, mid);
- stmt.setString(2, tagsNames);
+ if (tagsNames == "") {
+ stmt.setNull(2, Types.VARCHAR);
+ } else {
+ stmt.setString(2, tagsNames);
+ }
stmt.setString(3, txt);
stmt.executeUpdate();
} catch (SQLException e) {
@@ -412,21 +416,29 @@ public class MessagesQueries {
try {
if (visitor_uid > 1) {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND hidden=0" +
+ " AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?)" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
stmt.setInt(2, visitor_uid);
stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0" +
+ " AND (privacy>0 OR user_id=?)" +
+ " AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?)" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
stmt.setInt(2, visitor_uid);
}
} else {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<?" +
+ " AND hidden=0 AND privacy>0 AND user_id NOT IN (SELECT id from users WHERE banned=1) " +
+ " ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND privacy>0" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
}
}
@@ -735,6 +747,7 @@ public class MessagesQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
+
if (before > 0) {
stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id<? ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
diff --git a/src/main/java/com/juick/server/PushQueries.java b/src/main/java/com/juick/server/PushQueries.java
index 84f42722..bf7505ca 100644
--- a/src/main/java/com/juick/server/PushQueries.java
+++ b/src/main/java/com/juick/server/PushQueries.java
@@ -9,6 +9,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.List;
/**
*
@@ -65,4 +66,29 @@ public class PushQueries {
}
return urls;
}
+
+ public static String getAPNSToken(Connection sql, int uid) {
+ return SQLHelpers.getString(sql, "SELECT token from ios WHERE user_id=?", uid);
+ }
+
+ public static List<String> getAPNSSubscribers(Connection sql, int uid) {
+ List<String> urls = new ArrayList<String>();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT token FROM ios INNER JOIN subscr_users ON (subscr_users.user_id=? AND ios.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;
+ }
}