mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-13 11:12:31 +00:00
Added optional filtering by reference in GET /chat/messages
This commit is contained in:
parent
4681218416
commit
aa9da45c01
@ -69,6 +69,7 @@ public class ChatResource {
|
|||||||
public List<ChatMessage> searchChat(@QueryParam("before") Long before, @QueryParam("after") Long after,
|
public List<ChatMessage> searchChat(@QueryParam("before") Long before, @QueryParam("after") Long after,
|
||||||
@QueryParam("txGroupId") Integer txGroupId,
|
@QueryParam("txGroupId") Integer txGroupId,
|
||||||
@QueryParam("involving") List<String> involvingAddresses,
|
@QueryParam("involving") List<String> involvingAddresses,
|
||||||
|
@QueryParam("reference") String reference,
|
||||||
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
||||||
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
||||||
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse) {
|
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse) {
|
||||||
@ -87,11 +88,16 @@ public class ChatResource {
|
|||||||
if (after != null && after < 1500000000000L)
|
if (after != null && after < 1500000000000L)
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||||
|
|
||||||
|
byte[] referenceBytes = null;
|
||||||
|
if (reference != null)
|
||||||
|
referenceBytes = Base58.decode(reference);
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
return repository.getChatRepository().getMessagesMatchingCriteria(
|
return repository.getChatRepository().getMessagesMatchingCriteria(
|
||||||
before,
|
before,
|
||||||
after,
|
after,
|
||||||
txGroupId,
|
txGroupId,
|
||||||
|
referenceBytes,
|
||||||
involvingAddresses,
|
involvingAddresses,
|
||||||
limit, offset, reverse);
|
limit, offset, reverse);
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
|
@ -46,6 +46,7 @@ public class ChatMessagesWebSocket extends ApiWebSocket {
|
|||||||
null,
|
null,
|
||||||
txGroupId,
|
txGroupId,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
sendMessages(session, chatMessages);
|
sendMessages(session, chatMessages);
|
||||||
@ -72,6 +73,7 @@ public class ChatMessagesWebSocket extends ApiWebSocket {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
involvingAddresses,
|
involvingAddresses,
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ public interface ChatRepository {
|
|||||||
* Expects EITHER non-null txGroupID OR non-null sender and recipient addresses.
|
* Expects EITHER non-null txGroupID OR non-null sender and recipient addresses.
|
||||||
*/
|
*/
|
||||||
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after,
|
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after,
|
||||||
Integer txGroupId, List<String> involving,
|
Integer txGroupId, byte[] reference, List<String> involving,
|
||||||
Integer limit, Integer offset, Boolean reverse) throws DataException;
|
Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
public ChatMessage toChatMessage(ChatTransactionData chatTransactionData) throws DataException;
|
public ChatMessage toChatMessage(ChatTransactionData chatTransactionData) throws DataException;
|
||||||
|
@ -23,7 +23,7 @@ public class HSQLDBChatRepository implements ChatRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after, Integer txGroupId,
|
public List<ChatMessage> getMessagesMatchingCriteria(Long before, Long after, Integer txGroupId, byte[] referenceBytes,
|
||||||
List<String> involving, Integer limit, Integer offset, Boolean reverse)
|
List<String> involving, Integer limit, Integer offset, Boolean reverse)
|
||||||
throws DataException {
|
throws DataException {
|
||||||
// Check args meet expectations
|
// Check args meet expectations
|
||||||
@ -57,6 +57,11 @@ public class HSQLDBChatRepository implements ChatRepository {
|
|||||||
bindParams.add(after);
|
bindParams.add(after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (referenceBytes != null) {
|
||||||
|
whereClauses.add("reference = ?");
|
||||||
|
bindParams.add(referenceBytes);
|
||||||
|
}
|
||||||
|
|
||||||
if (txGroupId != null) {
|
if (txGroupId != null) {
|
||||||
whereClauses.add("tx_group_id = " + txGroupId); // int safe to use literally
|
whereClauses.add("tx_group_id = " + txGroupId); // int safe to use literally
|
||||||
whereClauses.add("recipient IS NULL");
|
whereClauses.add("recipient IS NULL");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user