Merge pull request #109 from AlphaX-Projects/master

Add more data to active chats websocket
This commit is contained in:
CalDescent 2023-02-11 13:25:13 +00:00 committed by GitHub
commit 26587067d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 8 deletions

View File

@ -17,17 +17,21 @@ public class ActiveChats {
private Long timestamp;
private String sender;
private String senderName;
private byte[] signature;
private byte[] data;
protected GroupChat() {
/* JAXB */
}
public GroupChat(int groupId, String groupName, Long timestamp, String sender, String senderName) {
public GroupChat(int groupId, String groupName, Long timestamp, String sender, String senderName, byte[] signature, byte[] data) {
this.groupId = groupId;
this.groupName = groupName;
this.timestamp = timestamp;
this.sender = sender;
this.senderName = senderName;
this.signature = signature;
this.data = data;
}
public int getGroupId() {
@ -49,6 +53,14 @@ public class ActiveChats {
public String getSenderName() {
return this.senderName;
}
public byte[] getSignature() {
return this.signature;
}
public byte[] getData() {
return this.data;
}
}
@XmlAccessorType(XmlAccessType.FIELD)

View File

@ -177,11 +177,11 @@ public class HSQLDBChatRepository implements ChatRepository {
private List<GroupChat> getActiveGroupChats(String address) throws DataException {
// Find groups where address is a member and potential latest message details
String groupsSql = "SELECT group_id, group_name, latest_timestamp, sender, sender_name "
String groupsSql = "SELECT group_id, group_name, latest_timestamp, sender, sender_name, signature, data "
+ "FROM GroupMembers "
+ "JOIN Groups USING (group_id) "
+ "LEFT OUTER JOIN LATERAL("
+ "SELECT created_when AS latest_timestamp, sender, name AS sender_name "
+ "SELECT created_when AS latest_timestamp, sender, name AS sender_name, signature, data "
+ "FROM ChatTransactions "
+ "JOIN Transactions USING (signature) "
+ "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
@ -205,8 +205,10 @@ public class HSQLDBChatRepository implements ChatRepository {
String sender = resultSet.getString(4);
String senderName = resultSet.getString(5);
byte[] signature = resultSet.getBytes(6);
byte[] data = resultSet.getBytes(7);
GroupChat groupChat = new GroupChat(groupId, groupName, timestamp, sender, senderName);
GroupChat groupChat = new GroupChat(groupId, groupName, timestamp, sender, senderName, signature, data);
groupChats.add(groupChat);
} while (resultSet.next());
}
@ -215,7 +217,7 @@ public class HSQLDBChatRepository implements ChatRepository {
}
// We need different SQL to handle group-less chat
String grouplessSql = "SELECT created_when, sender, SenderNames.name "
String grouplessSql = "SELECT created_when, sender, SenderNames.name, signature, data "
+ "FROM ChatTransactions "
+ "JOIN Transactions USING (signature) "
+ "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
@ -228,15 +230,19 @@ public class HSQLDBChatRepository implements ChatRepository {
Long timestamp = null;
String sender = null;
String senderName = null;
byte[] signature = null;
byte[] data = null;
if (resultSet != null) {
// We found a recipient-less, group-less CHAT message, so report its details
timestamp = resultSet.getLong(1);
sender = resultSet.getString(2);
senderName = resultSet.getString(3);
signature = resultSet.getBytes(4);
data = resultSet.getBytes(5);
}
GroupChat groupChat = new GroupChat(0, null, timestamp, sender, senderName);
GroupChat groupChat = new GroupChat(0, null, timestamp, sender, senderName, signature, data);
groupChats.add(groupChat);
} catch (SQLException e) {
throw new DataException("Unable to fetch active group chats from repository", e);