Skip to content

Commit

Permalink
add pagination to group listing
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 30, 2024
1 parent ee6b1cb commit 655ad0d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import uniffi.xmtpv3.FfiConversations
import uniffi.xmtpv3.FfiListConversationsOptions
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupEmitter
import java.util.Date
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.DurationUnit

data class Conversations(
var client: Client,
Expand Down Expand Up @@ -99,9 +101,15 @@ data class Conversations(
libXMTPConversations?.sync()
}

fun listGroups(): List<Group> {
fun listGroups(after: Date? = null, before: Date? = null, limit: Int? = null): List<Group> {
return runBlocking {
libXMTPConversations?.list(opts = FfiListConversationsOptions(null, null, null))?.map {
libXMTPConversations?.list(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
)
)?.map {
Group(client, it)
}
} ?: emptyList()
Expand Down Expand Up @@ -230,7 +238,10 @@ data class Conversations(
}.map { Pair(it.topic, it) }

if (includeGroups) {
val groups = runBlocking { listGroups() }
val groups = runBlocking {
syncGroups()
listGroups()
}
conversationsByTopic += groups.map { Pair(it.id.toString(), Conversation.Group(it)) }
}
return conversationsByTopic.values.sortedByDescending { it.createdAt }
Expand Down

0 comments on commit 655ad0d

Please sign in to comment.