mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-26 23:44:34 +00:00
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.
This commit is contained in:
parent
a9852e5305
commit
f29ae656b9
@ -227,10 +227,14 @@ public class ChatResource {
|
|||||||
|
|
||||||
chatTransaction.computeNonce();
|
chatTransaction.computeNonce();
|
||||||
|
|
||||||
|
// Re-check, but ignores signature
|
||||||
result = chatTransaction.isValidUnconfirmed();
|
result = chatTransaction.isValidUnconfirmed();
|
||||||
if (result != ValidationResult.OK)
|
if (result != ValidationResult.OK)
|
||||||
throw TransactionsResource.createTransactionInvalidException(request, result);
|
throw TransactionsResource.createTransactionInvalidException(request, result);
|
||||||
|
|
||||||
|
// Strip zeroed signature
|
||||||
|
transactionData.setSignature(null);
|
||||||
|
|
||||||
byte[] bytes = ChatTransactionTransformer.toBytes(transactionData);
|
byte[] bytes = ChatTransactionTransformer.toBytes(transactionData);
|
||||||
return Base58.encode(bytes);
|
return Base58.encode(bytes);
|
||||||
} catch (TransformationException e) {
|
} catch (TransformationException e) {
|
||||||
|
@ -12,13 +12,14 @@ public class ActiveChats {
|
|||||||
public static class GroupChat {
|
public static class GroupChat {
|
||||||
private int groupId;
|
private int groupId;
|
||||||
private String groupName;
|
private String groupName;
|
||||||
private long timestamp;
|
// Might not be present for groupId 0
|
||||||
|
private Long timestamp;
|
||||||
|
|
||||||
protected GroupChat() {
|
protected GroupChat() {
|
||||||
/* JAXB */
|
/* JAXB */
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupChat(int groupId, String groupName, long timestamp) {
|
public GroupChat(int groupId, String groupName, Long timestamp) {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
@ -32,7 +33,7 @@ public class ActiveChats {
|
|||||||
return this.groupName;
|
return this.groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimestamp() {
|
public Long getTimestamp() {
|
||||||
return this.timestamp;
|
return this.timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,28 @@ public class HSQLDBChatRepository implements ChatRepository {
|
|||||||
throw new DataException("Unable to fetch active group chats from repository", e);
|
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;
|
return groupChats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user