diff options
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r-- | src/main/java/com/juick/server/MessagesQueries.java | 21 | ||||
-rw-r--r-- | src/main/java/com/juick/server/UserQueries.java | 25 |
2 files changed, 26 insertions, 20 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java index 422cfe7da..c4919a8da 100644 --- a/src/main/java/com/juick/server/MessagesQueries.java +++ b/src/main/java/com/juick/server/MessagesQueries.java @@ -349,31 +349,30 @@ public class MessagesQueries { } public static List<Integer> getMyFeed(JdbcTemplate sql, int uid, int before) { - List<Integer> mids = new ArrayList<>(40); + List<Integer> mids; if (before > 0) { mids = sql.queryForList("SELECT message_id FROM messages " + "INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) " + "WHERE message_id<? AND (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id " + "IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20", - Integer.class, new Object[]{uid, before, uid}); + Integer.class, uid, before, uid); } else { mids = sql.queryForList("SELECT message_id FROM messages " + "INNER JOIN subscr_users ON (subscr_users.suser_id=? " + "AND subscr_users.user_id=messages.user_id) " + "WHERE (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id " + "IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20", - Integer.class, new Object[]{uid, uid}); + Integer.class, uid, uid); } if (before > 0) { mids.addAll(sql.queryForList("SELECT message_id FROM messages " + "WHERE user_id=? AND message_id<? ORDER BY message_id DESC LIMIT 20", Integer.class, - new Object[]{uid, before})); + uid, before)); } else { mids.addAll(sql.queryForList("SELECT message_id FROM messages " + - "WHERE user_id=? ORDER BY message_id DESC LIMIT 20", Integer.class, - new Object[]{uid})); + "WHERE user_id=? ORDER BY message_id DESC LIMIT 20", Integer.class, uid)); } Collections.sort(mids, Collections.reverseOrder()); @@ -399,10 +398,10 @@ public class MessagesQueries { public static List<Integer> getDiscussions(JdbcTemplate sql, int uid, int before) { if (before > 0) { return sql.queryForList("SELECT message_id FROM subscr_messages WHERE suser_id=? AND message_id<? " + - "ORDER BY message_id DESC LIMIT 20", new Object[]{uid, before}, Integer.class); + "ORDER BY message_id DESC LIMIT 20", Integer.class, uid, before); } else { return sql.queryForList("SELECT message_id FROM subscr_messages WHERE suser_id=? " + - "ORDER BY message_id DESC LIMIT 20", new Object[]{uid}, Integer.class); + "ORDER BY message_id DESC LIMIT 20", Integer.class, uid); } } @@ -410,11 +409,11 @@ public class MessagesQueries { if (before > 0) { return sql.queryForList("SELECT message_id FROM favorites WHERE user_id " + "IN (SELECT user_id FROM subscr_users WHERE suser_id=?) AND message_id<? " + - "ORDER BY message_id DESC LIMIT 20", new Object[]{uid, before}, Integer.class); + "ORDER BY message_id DESC LIMIT 20", Integer.class, uid, before); } else { return sql.queryForList("SELECT message_id FROM favorites WHERE user_id " + "IN (SELECT user_id FROM subscr_users WHERE suser_id=?) " + - "ORDER BY message_id DESC LIMIT 20", new Object[]{uid}, Integer.class); + "ORDER BY message_id DESC LIMIT 20", Integer.class, uid); } } @@ -422,7 +421,7 @@ public class MessagesQueries { if (before > 0) { return sql.queryForList("SELECT message_id FROM messages WHERE message_id<? AND privacy>0 " + - "AND popular>0 ORDER BY message_id DESC LIMIT 20", new Object[] {before}, Integer.class); + "AND popular>0 ORDER BY message_id DESC LIMIT 20", Integer.class, before); } else { return sql.queryForList("SELECT message_id FROM messages WHERE privacy>0 " + "AND popular>0 ORDER BY message_id DESC LIMIT 20", Integer.class); diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java index 948b42d4f..226e21b1b 100644 --- a/src/main/java/com/juick/server/UserQueries.java +++ b/src/main/java/com/juick/server/UserQueries.java @@ -100,14 +100,12 @@ public class UserQueries { public static User getUserByJID(JdbcTemplate sql, String jid) { return sql.queryForObject("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)", - new Object[] {jid}, - new UserMapper()); + new UserMapper(), jid); } public static List<User> getUsersByName(JdbcTemplate sql, List<String> unames) { - return sql.query("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)", - new UserMapper(), - unames.toArray()); + return sql.query("SELECT id,nick FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")", + new UserMapper()); } public static List<User> getUsersByID(JdbcTemplate sql, List<Integer> uids) { @@ -204,10 +202,19 @@ public class UserQueries { } public static int checkPassword(JdbcTemplate sql, String username, String password) { - String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username); - if (realPassword.equals(password)) { - return UserQueries.getUserByName(sql, username).getUID(); - } else { + try { + String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username); + if (realPassword.equals(password)) { + User user = UserQueries.getUserByName(sql, username); + if (user != null) { + return user.getUID(); + } else { + return -1; + } + } else { + return -1; + } + } catch (EmptyResultDataAccessException e) { return -1; } } |