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/PMQueries.java40
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 d1d826ccc..6de309956 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;
}