forked from Qortal/qortal
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.
This commit is contained in:
parent
51bfd49e25
commit
219f82f562
@ -120,17 +120,17 @@ public class HSQLDBChatRepository implements ChatRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<GroupChat> getActiveGroupChats(String address) throws DataException {
|
private List<GroupChat> getActiveGroupChats(String address) throws DataException {
|
||||||
// Find groups where address is a member and there is a chat
|
// Find groups where address is a member and potential latest timestamp
|
||||||
String groupsSql = "SELECT group_id, group_name, latest_timestamp "
|
String groupsSql = "SELECT group_id, group_name, ("
|
||||||
+ "FROM GroupMembers "
|
|
||||||
+ "JOIN Groups USING (group_id) "
|
|
||||||
+ "CROSS JOIN LATERAL("
|
|
||||||
+ "SELECT created_when "
|
+ "SELECT created_when "
|
||||||
+ "FROM Transactions "
|
+ "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 + " "
|
+ "WHERE tx_group_id = Groups.group_id AND type = " + TransactionType.CHAT.value + " "
|
||||||
+ "ORDER BY created_when DESC "
|
+ "ORDER BY created_when DESC "
|
||||||
+ "LIMIT 1"
|
+ "LIMIT 1"
|
||||||
+ ") AS LatestMessages (latest_timestamp) "
|
+ ") AS latest_timestamp "
|
||||||
|
+ "FROM GroupMembers "
|
||||||
|
+ "JOIN Groups USING (group_id) "
|
||||||
+ "WHERE address = ?";
|
+ "WHERE address = ?";
|
||||||
|
|
||||||
List<GroupChat> groupChats = new ArrayList<>();
|
List<GroupChat> groupChats = new ArrayList<>();
|
||||||
@ -139,7 +139,10 @@ public class HSQLDBChatRepository implements ChatRepository {
|
|||||||
do {
|
do {
|
||||||
int groupId = resultSet.getInt(1);
|
int groupId = resultSet.getInt(1);
|
||||||
String groupName = resultSet.getString(2);
|
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);
|
GroupChat groupChat = new GroupChat(groupId, groupName, timestamp);
|
||||||
groupChats.add(groupChat);
|
groupChats.add(groupChat);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user