Browse Source

More work on CHAT

Always add group 0 info to output of API call GET /chats/active/{address}.
No groupName entry as it's "no group" or "group-less" or "not group related".
Timestamp also might be omitted if no message found.

Fix output of POST /chats/compute so it doesn't include zeroed 64-byte signature.
split-DB
catbref 4 years ago
parent
commit
f29ae656b9
  1. 4
      src/main/java/org/qortal/api/resource/ChatResource.java
  2. 7
      src/main/java/org/qortal/data/chat/ActiveChats.java
  3. 22
      src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java

4
src/main/java/org/qortal/api/resource/ChatResource.java

@ -227,10 +227,14 @@ public class ChatResource {
chatTransaction.computeNonce();
// Re-check, but ignores signature
result = chatTransaction.isValidUnconfirmed();
if (result != ValidationResult.OK)
throw TransactionsResource.createTransactionInvalidException(request, result);
// Strip zeroed signature
transactionData.setSignature(null);
byte[] bytes = ChatTransactionTransformer.toBytes(transactionData);
return Base58.encode(bytes);
} catch (TransformationException e) {

7
src/main/java/org/qortal/data/chat/ActiveChats.java

@ -12,13 +12,14 @@ public class ActiveChats {
public static class GroupChat {
private int groupId;
private String groupName;
private long timestamp;
// Might not be present for groupId 0
private Long timestamp;
protected GroupChat() {
/* JAXB */
}
public GroupChat(int groupId, String groupName, long timestamp) {
public GroupChat(int groupId, String groupName, Long timestamp) {
this.groupId = groupId;
this.groupName = groupName;
this.timestamp = timestamp;
@ -32,7 +33,7 @@ public class ActiveChats {
return this.groupName;
}
public long getTimestamp() {
public Long getTimestamp() {
return this.timestamp;
}
}

22
src/main/java/org/qortal/repository/hsqldb/HSQLDBChatRepository.java

@ -145,6 +145,28 @@ public class HSQLDBChatRepository implements ChatRepository {
throw new DataException("Unable to fetch active group chats from repository", e);
}
// We need different SQL to handle group-less chat
String grouplessSql = "SELECT created_when "
+ "FROM ChatTransactions "
+ "JOIN Transactions USING (signature) "
+ "WHERE tx_group_id = 0 "
+ "AND recipient IS NULL "
+ "ORDER BY created_when DESC "
+ "LIMIT 1";
try (ResultSet resultSet = this.repository.checkedExecute(grouplessSql)) {
Long timestamp = null;
if (resultSet != null)
// We found a recipient-less, group-less CHAT message, so report its timestamp
timestamp = resultSet.getLong(1);
GroupChat groupChat = new GroupChat(0, null, timestamp);
groupChats.add(groupChat);
} catch (SQLException e) {
throw new DataException("Unable to fetch active group chats from repository", e);
}
return groupChats;
}

Loading…
Cancel
Save