aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/PM.java10
-rw-r--r--juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java18
2 files changed, 15 insertions, 13 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/PM.java b/juick-server/src/main/java/com/juick/server/api/PM.java
index 80be92f0..0c36fe00 100644
--- a/juick-server/src/main/java/com/juick/server/api/PM.java
+++ b/juick-server/src/main/java/com/juick/server/api/PM.java
@@ -17,6 +17,7 @@
package com.juick.server.api;
+import com.juick.Chat;
import com.juick.User;
import com.juick.service.component.MessageEvent;
import com.juick.model.AnonymousUser;
@@ -105,14 +106,9 @@ public class PM {
if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
- if (cnt < 3) {
- cnt = 3;
- }
- if (cnt > 10) {
- cnt = 10;
- }
+ // TODO: ignore cnt param for now but make sure paging param will not be cnt
- List<User> lastconv = pmQueriesService.getPMLastConversationsUsers(visitor.getUid(), cnt);
+ List<Chat> lastconv = pmQueriesService.getLastChats(visitor);
PrivateChats pms = new PrivateChats();
pms.setUsers(lastconv);
return pms;
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