Added haschatreference, with possible values of true, false, or null, to allow optional filtering by the presence or absense of a chat reference.

This commit is contained in:
CalDescent 2022-10-24 19:21:29 +01:00
parent 09014d07e0
commit 9d74f0eec0
4 changed files with 15 additions and 4 deletions

View File

@ -71,6 +71,7 @@ public class ChatResource {
@QueryParam("involving") List<String> involvingAddresses,
@QueryParam("reference") String reference,
@QueryParam("chatreference") String chatReference,
@QueryParam("haschatreference") Boolean hasChatReference,
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse) {
@ -104,6 +105,7 @@ public class ChatResource {
txGroupId,
referenceBytes,
chatReferenceBytes,
hasChatReference,
involvingAddresses,
limit, offset, reverse);
} catch (DataException e) {

View File

@ -48,6 +48,7 @@ public class ChatMessagesWebSocket extends ApiWebSocket {
null,
null,
null,
null,
null, null, null);
sendMessages(session, chatMessages);
@ -76,6 +77,7 @@ public class ChatMessagesWebSocket extends ApiWebSocket {
null,
null,
null,
null,
involvingAddresses,
null, null, null);

View File

@ -14,8 +14,8 @@ public interface ChatRepository {
* Expects EITHER non-null txGroupID OR non-null sender and recipient addresses.
*/
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after,
Integer txGroupId, byte[] reference, byte[] chatReferenceBytes, List<String> involving,
Integer limit, Integer offset, Boolean reverse) throws DataException;
Integer txGroupId, byte[] reference, byte[] chatReferenceBytes, Boolean hasChatReference,
List<String> involving, Integer limit, Integer offset, Boolean reverse) throws DataException;
public ChatMessage toChatMessage(ChatTransactionData chatTransactionData) throws DataException;

View File

@ -24,8 +24,8 @@ public class HSQLDBChatRepository implements ChatRepository {
@Override
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after, Integer txGroupId, byte[] referenceBytes,
byte[] chatReferenceBytes, List<String> involving, Integer limit, Integer offset, Boolean reverse)
throws DataException {
byte[] chatReferenceBytes, Boolean hasChatReference, List<String> involving,
Integer limit, Integer offset, Boolean reverse) throws DataException {
// Check args meet expectations
if ((txGroupId != null && involving != null && !involving.isEmpty())
|| (txGroupId == null && (involving == null || involving.size() != 2)))
@ -67,6 +67,13 @@ public class HSQLDBChatRepository implements ChatRepository {
bindParams.add(chatReferenceBytes);
}
if (hasChatReference != null && hasChatReference == true) {
whereClauses.add("chat_reference IS NOT NULL");
}
else if (hasChatReference != null && hasChatReference == false) {
whereClauses.add("chat_reference IS NULL");
}
if (txGroupId != null) {
whereClauses.add("tx_group_id = " + txGroupId); // int safe to use literally
whereClauses.add("recipient IS NULL");