From 567e9a870645d527da95d07103dd0fce31f14585 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 11 Jul 2016 10:32:18 +0300 Subject: api: fix groups_pms --- juick-core/src/main/java/com/juick/server/PMQueries.java | 13 +++++-------- juick-core/src/main/java/com/juick/server/UserQueries.java | 14 -------------- 2 files changed, 5 insertions(+), 22 deletions(-) (limited to 'juick-core/src/main') diff --git a/juick-core/src/main/java/com/juick/server/PMQueries.java b/juick-core/src/main/java/com/juick/server/PMQueries.java index 10de9a69..fa1dd05f 100644 --- a/juick-core/src/main/java/com/juick/server/PMQueries.java +++ b/juick-core/src/main/java/com/juick/server/PMQueries.java @@ -68,19 +68,16 @@ public class PMQueries { } public static List getPMLastConversationsUsers(JdbcTemplate sql, int uid, int cnt) { - List qusers = sql.query("SELECT user_id,unread FROM pm_streams " - + "WHERE user_id_to=? " + return sql.query("SELECT pm_streams.user_id, users.nick, pm_streams.unread FROM pm_streams " + + "INNER JOIN users ON users.id = pm_streams.user_id" + + "WHERE pm_streams.user_id_to=? " + "ORDER BY unread DESC, lastmessage DESC LIMIT " + cnt, (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 (!qusers.isEmpty()) { - UserQueries.fillUsersByID(sql, qusers); - } - - return qusers; } public static List getPMMessages(JdbcTemplate sql, int uid, int uid_to) { diff --git a/juick-core/src/main/java/com/juick/server/UserQueries.java b/juick-core/src/main/java/com/juick/server/UserQueries.java index 1ba0f83b..13a330e5 100644 --- a/juick-core/src/main/java/com/juick/server/UserQueries.java +++ b/juick-core/src/main/java/com/juick/server/UserQueries.java @@ -133,20 +133,6 @@ public class UserQueries { return Collections.emptyList(); } - public static boolean fillUsersByID(JdbcTemplate sql, List users) { - String uids = StringUtils.arrayToCommaDelimitedString(users.stream().map(u -> u.getUID()).collect(Collectors.toList()).toArray()); - - sql.query("SELECT id,nick,banned FROM users WHERE id IN (" + uids + ")", - (rs, num) -> { - User u = new User(); - u.setUID(rs.getInt(1)); - u.setUName(rs.getString(2)); - return u; - }); - - return true; - } - public static List getUsersByJID(JdbcTemplate sql, List jids) { if (!jids.isEmpty()) { return sql.query("SELECT users.id,users.nick,jids.jid FROM users " -- cgit v1.2.3