aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java b/juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java
index b68e0236..ee49755d 100644
--- a/juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java
@@ -17,6 +17,7 @@
package com.juick.service;
+import com.juick.Chat;
import com.juick.User;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -89,20 +90,25 @@ public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesSe
@Transactional(readOnly = true)
@Override
- public List<User> getPMLastConversationsUsers(final int uid, final int cnt) {
+ public List<Chat> getLastChats(final User user) {
return getJdbcTemplate().query(
- "SELECT pm_streams.user_id, users.nick, pm_streams.unread FROM pm_streams "
+ "SELECT pm_streams.user_id, users.nick, l.last, pm.txt, pm_streams.unread FROM pm_streams "
+ "INNER JOIN users ON users.id = pm_streams.user_id "
+ + "INNER JOIN pm ON pm.user_id = pm_streams.user_id "
+ + "INNER JOIN (SELECT user_id, MAX(ts) AS last FROM pm "
+ + "WHERE user_id_to=? GROUP BY user_id) l ON l.last = pm.ts "
+ "WHERE pm_streams.user_id_to=? "
- + "ORDER BY pm_streams.unread DESC, pm_streams.lastmessage DESC LIMIT ?",
+ + "ORDER BY pm_streams.unread DESC, l.last DESC",
(rs, rowNum) -> {
- com.juick.User u = new com.juick.User();
+ com.juick.Chat u = new com.juick.Chat();
u.setUid(rs.getInt(1));
u.setName(rs.getString(2));
- u.setUnreadCount(rs.getInt(3));
+ u.setLastMessageTimestamp(rs.getTimestamp(3).toInstant());
+ u.setLastMessageText(rs.getString(4));
+ u.setUnreadCount(rs.getInt(5));
return u;
},
- uid, cnt);
+ user.getUid(), user.getUid());
}
@Transactional