Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List batch messages takes query parameter #77

Merged
merged 11 commits into from
Jul 21, 2023
Merged

Conversation

nplasterer
Copy link
Contributor

@nplasterer nplasterer commented Jul 18, 2023

Fixes #68

This takes a list of query objects so each topic can have it's own pagination associated with it.

Matches the query type specified in xmtp-js https://github.com/xmtp/xmtp-js/blob/main/src/ApiClient.ts#L56-L74

Note: This is a breaking change.

@nplasterer nplasterer marked this pull request as ready for review July 21, 2023 20:20
@nplasterer nplasterer requested a review from a team as a code owner July 21, 2023 20:20
Comment on lines +1 to +5
export type Query = {
startTime?: Date | undefined;
endTime?: Date | undefined;
contentTopic: string;
pageSize?: number | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type matches the JS type.

Comment on lines +201 to +217
AsyncFunction("loadMessages") { clientAddress: String, topic: String, limit: Int?, before: Long?, after: Long? ->
logV("loadMessages")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val conversation =
findConversation(
clientAddress = clientAddress,
topic = topic,
) ?: throw XMTPException("no conversation found for $topic")
val beforeDate = if (before != null) Date(before) else null
val afterDate = if (after != null) Date(after) else null

client.conversations.listBatchMessages(topics, limit, beforeDate, afterDate).map {
conversation.messages(limit = limit, before = beforeDate, after = afterDate)
.map {
EncodedMessageWrapper.encode(it)
}
}

AsyncFunction("loadBatchMessages") { clientAddress: String, topics: List<String> ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadMessages - lists all the messages via the envelopesList query inside of the SDKs

loadBatchMessages - lists all the messages for a batch of topics with given pagination parameters.

These are two different methods in the sdks and should be here as well. Previously both messages, and batch messages called the batch method.

Comment on lines +118 to +123
return JSON.stringify({
limit: item.pageSize || 0,
topic: item.contentTopic,
after: item.startTime?.getTime() || 0,
before: item.endTime?.getTime() || 0,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converts the javascript type to the JSON string that the SDKS expect.

@nplasterer nplasterer merged commit d9f5e8a into main Jul 21, 2023
1 check failed
@nplasterer nplasterer deleted the np/list-batch-messages branch July 21, 2023 20:51
@github-actions
Copy link

🎉 This PR is included in version 1.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: specify timestamps in listBatchMessages for each topic
3 participants