From 219f82f56288fe20d5ac311e61383711c84249b6 Mon Sep 17 00:00:00 2001 From: catbref Date: Tue, 19 May 2020 17:12:41 +0100 Subject: [PATCH] Modify API call GET /chats/active/{address} to return info on all joined groups. Previously GET /chats/active/{address} would only return an active group chat entry where 'address' was a member AND there was an existing CHAT transaction with the same tx_group_id (and no recipient). Now the response contains entries for ALL groups where 'address' is a member, regardless of an existing CHAT transactions, omitting the 'timestamp' entry if there are none. --- .../repository/hsqldb/HSQLDBChatRepository.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java index fd4b6202..8a3a5fc3 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java @@ -120,17 +120,17 @@ public class HSQLDBChatRepository implements ChatRepository { } private List getActiveGroupChats(String address) throws DataException { - // Find groups where address is a member and there is a chat - String groupsSql = "SELECT group_id, group_name, latest_timestamp " - + "FROM GroupMembers " - + "JOIN Groups USING (group_id) " - + "CROSS JOIN LATERAL(" + // Find groups where address is a member and potential latest timestamp + String groupsSql = "SELECT group_id, group_name, (" + "SELECT created_when " + "FROM Transactions " + // NOTE: We need to qualify "Groups.group_id" here to avoid "General error" bug in HSQLDB v2.5.0 + "WHERE tx_group_id = Groups.group_id AND type = " + TransactionType.CHAT.value + " " + "ORDER BY created_when DESC " + "LIMIT 1" - + ") AS LatestMessages (latest_timestamp) " + + ") AS latest_timestamp " + + "FROM GroupMembers " + + "JOIN Groups USING (group_id) " + "WHERE address = ?"; List groupChats = new ArrayList<>(); @@ -139,7 +139,10 @@ public class HSQLDBChatRepository implements ChatRepository { do { int groupId = resultSet.getInt(1); String groupName = resultSet.getString(2); - long timestamp = resultSet.getLong(3); + + Long timestamp = resultSet.getLong(3); + if (timestamp == 0 && resultSet.wasNull()) + timestamp = null; GroupChat groupChat = new GroupChat(groupId, groupName, timestamp); groupChats.add(groupChat);