Skip to content

Commit

Permalink
add pagination to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 30, 2024
1 parent b579a65 commit dec2192
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ sealed class Conversation {
)

is Group -> {
group.messages()
group.messages(
limit = limit,
before = before,
after = after,
direction = direction,
)
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,27 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
libXMTPGroup.sync()
}

fun messages(): List<DecodedMessage> {
fun messages(
limit: Int? = null,
before: Date? = null,
after: Date? = null,
direction: PagingInfoSortDirection = MessageApiOuterClass.SortDirection.SORT_DIRECTION_DESCENDING,
): List<DecodedMessage> {
return runBlocking {
libXMTPGroup.sync()
libXMTPGroup.findMessages(
val messages = libXMTPGroup.findMessages(
opts = FfiListMessagesOptions(
sentBeforeNs = null,
sentAfterNs = null,
limit = null
sentBeforeNs = before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
sentAfterNs = after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit = limit?.toLong()
)
).map {
Message(client, it).decode()
}.reversed()
}
when (direction) {
MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING -> messages
else -> messages.reversed()
}
}
}

Expand Down

0 comments on commit dec2192

Please sign in to comment.