Skip to content

Commit 655ad0d

Browse files
committed
add pagination to group listing
1 parent ee6b1cb commit 655ad0d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

library/src/main/java/org/xmtp/android/library/Conversations.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import uniffi.xmtpv3.FfiConversations
3838
import uniffi.xmtpv3.FfiListConversationsOptions
3939
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupEmitter
4040
import java.util.Date
41+
import kotlin.time.Duration.Companion.nanoseconds
42+
import kotlin.time.DurationUnit
4143

4244
data class Conversations(
4345
var client: Client,
@@ -99,9 +101,15 @@ data class Conversations(
99101
libXMTPConversations?.sync()
100102
}
101103

102-
fun listGroups(): List<Group> {
104+
fun listGroups(after: Date? = null, before: Date? = null, limit: Int? = null): List<Group> {
103105
return runBlocking {
104-
libXMTPConversations?.list(opts = FfiListConversationsOptions(null, null, null))?.map {
106+
libXMTPConversations?.list(
107+
opts = FfiListConversationsOptions(
108+
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
109+
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
110+
limit?.toLong()
111+
)
112+
)?.map {
105113
Group(client, it)
106114
}
107115
} ?: emptyList()
@@ -230,7 +238,10 @@ data class Conversations(
230238
}.map { Pair(it.topic, it) }
231239

232240
if (includeGroups) {
233-
val groups = runBlocking { listGroups() }
241+
val groups = runBlocking {
242+
syncGroups()
243+
listGroups()
244+
}
234245
conversationsByTopic += groups.map { Pair(it.id.toString(), Conversation.Group(it)) }
235246
}
236247
return conversationsByTopic.values.sortedByDescending { it.createdAt }

0 commit comments

Comments
 (0)