diff options
author | Vitaly Takmazov | 2016-05-11 15:34:44 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-05-11 15:35:00 +0300 |
commit | 0a9cd317b878d6c2c777ec4eb19173a7d651abe5 (patch) | |
tree | 9aeb9699a3e71330524242994b5e8ac5af434200 /src/main/java/com/juick | |
parent | 69a435dfef1bc656dc1d9d3da0f049f86d18fdaf (diff) |
fix fill users, part 2
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r-- | src/main/java/com/juick/server/PMQueries.java | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/src/main/java/com/juick/server/PMQueries.java b/src/main/java/com/juick/server/PMQueries.java index d1d826cc..6de30995 100644 --- a/src/main/java/com/juick/server/PMQueries.java +++ b/src/main/java/com/juick/server/PMQueries.java @@ -100,39 +100,15 @@ public class PMQueries { } public static List<User> getPMLastConversationsUsers(JdbcTemplate sql, int uid, int cnt) { - List<User> users = sql.query("SELECT user_id,unread FROM pm_streams " - + "WHERE user_id_to=? AND unread>0 " - + "ORDER BY lastmessage DESC LIMIT " + cnt, (rs, rowNum) -> { + return sql.query("SELECT users.id, users.nick,pm_streams.unread FROM pm_streams " + + "INNER JOIN users ON users.id = pm_streams.user_id WHERE user_id_to=? " + + "ORDER BY pm_streams.lastmessage DESC LIMIT ?", (rs, rowNum) -> { com.juick.User u = new com.juick.User(); u.setUID(rs.getInt(1)); - u.MessagesCount = rs.getInt(2); + u.setUName(rs.getString(2)); + u.MessagesCount = rs.getInt(3); return u; - }, uid); - - if (users.size() < cnt) { - List<User> addUsers = sql.query("SELECT user_id,user_id_to " - + "FROM pm_streams WHERE (user_id=? OR user_id_to=?) " - + "AND lastmessage>TIMESTAMPADD(MONTH,-1,NOW()) " - + "ORDER BY lastmessage DESC LIMIT ?", (rs, num) -> { - User u = new com.juick.User(); - int uuid = rs.getInt(1) + rs.getInt(2) - uid; - u.setUID(uuid); - return u; - }, uid, uid, cnt * 2); - for (User addUser : addUsers) { - if (!haveUserInArray(users, addUser.getUID())) { - users.add(addUser); - if (users.size() >= cnt) { - break; - } - } - } - } - if (!users.isEmpty()) { - UserQueries.fillUsersByID(sql, users); - } - - return users; + }, uid, cnt); } public static boolean haveUserInArray(List<com.juick.User> arr, int uid) { @@ -156,10 +132,10 @@ public class PMQueries { msg.setText(rs.getString(2)); msg.setDate(rs.getTimestamp(3)); return msg; - }, new Object[]{uid, uid_to, uid, uid_to}); + }, uid, uid_to, uid, uid_to); sql.update("UPDATE pm_streams SET lastview=NOW(),unread=0 " - + "WHERE user_id_to=? AND user_id=?", new Object[]{uid, uid_to}); + + "WHERE user_id_to=? AND user_id=?", uid, uid_to); return msgs; } |