@@ -38,6 +38,8 @@ import uniffi.xmtpv3.FfiConversations
38
38
import uniffi.xmtpv3.FfiListConversationsOptions
39
39
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupEmitter
40
40
import java.util.Date
41
+ import kotlin.time.Duration.Companion.nanoseconds
42
+ import kotlin.time.DurationUnit
41
43
42
44
data class Conversations (
43
45
var client : Client ,
@@ -99,9 +101,15 @@ data class Conversations(
99
101
libXMTPConversations?.sync()
100
102
}
101
103
102
- fun listGroups (): List <Group > {
104
+ fun listGroups (after : Date ? = null, before : Date ? = null, limit : Int? = null ): List <Group > {
103
105
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 {
105
113
Group (client, it)
106
114
}
107
115
} ? : emptyList()
@@ -230,7 +238,10 @@ data class Conversations(
230
238
}.map { Pair (it.topic, it) }
231
239
232
240
if (includeGroups) {
233
- val groups = runBlocking { listGroups() }
241
+ val groups = runBlocking {
242
+ syncGroups()
243
+ listGroups()
244
+ }
234
245
conversationsByTopic + = groups.map { Pair (it.id.toString(), Conversation .Group (it)) }
235
246
}
236
247
return conversationsByTopic.values.sortedByDescending { it.createdAt }
0 commit comments