@@ -3,9 +3,11 @@ package org.xmtp.android.library
3
3
import android.util.Log
4
4
import io.grpc.StatusException
5
5
import kotlinx.coroutines.CancellationException
6
+ import kotlinx.coroutines.coroutineScope
6
7
import kotlinx.coroutines.flow.Flow
7
8
import kotlinx.coroutines.flow.MutableStateFlow
8
9
import kotlinx.coroutines.flow.flow
10
+ import kotlinx.coroutines.launch
9
11
import kotlinx.coroutines.runBlocking
10
12
import org.xmtp.android.library.GRPCApiClient.Companion.makeQueryRequest
11
13
import org.xmtp.android.library.GRPCApiClient.Companion.makeSubscribeRequest
@@ -34,6 +36,7 @@ import org.xmtp.proto.message.contents.Contact
34
36
import org.xmtp.proto.message.contents.Invitation
35
37
import uniffi.xmtpv3.FfiConversations
36
38
import uniffi.xmtpv3.FfiListConversationsOptions
39
+ import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupEmitter
37
40
import java.util.Date
38
41
import kotlin.time.Duration.Companion.nanoseconds
39
42
import kotlin.time.DurationUnit
@@ -90,8 +93,8 @@ data class Conversations(
90
93
if (accountAddresses.isEmpty()) {
91
94
throw XMTPException (" Cannot start an empty group chat." )
92
95
}
93
- if (accountAddresses.size == 1 &&
94
- accountAddresses.first() .lowercase() == client.address.lowercase()
96
+ if (accountAddresses.size == 1 && accountAddresses.first()
97
+ .lowercase() == client.address.lowercase()
95
98
) {
96
99
throw XMTPException (" Recipient is sender" )
97
100
}
@@ -473,7 +476,21 @@ data class Conversations(
473
476
* of the information of those conversations according to the topics
474
477
* @return Stream of data information for the conversations
475
478
*/
476
- fun stream (): Flow <Conversation > = flow {
479
+ fun stream (includeGroups : Boolean = false): Flow <Conversation > = flow {
480
+ if (includeGroups) {
481
+ val groupEmitter = GroupEmitter ()
482
+
483
+ coroutineScope {
484
+ launch {
485
+ groupEmitter.groups.collect { group ->
486
+ emit(Conversation .Group (Group (client, group)))
487
+ }
488
+ }
489
+ }
490
+
491
+ libXMTPConversations?.stream(groupEmitter.callback)
492
+ }
493
+
477
494
val streamedConversationTopics: MutableSet <String > = mutableSetOf ()
478
495
client.subscribeTopic(
479
496
listOf (Topic .userIntro(client.address), Topic .userInvite(client.address)),
@@ -497,6 +514,20 @@ data class Conversations(
497
514
}
498
515
}
499
516
517
+ fun streamGroups (): Flow <Group > = flow {
518
+ val groupEmitter = GroupEmitter ()
519
+
520
+ coroutineScope {
521
+ launch {
522
+ groupEmitter.groups.collect { group ->
523
+ emit(Group (client, group))
524
+ }
525
+ }
526
+ }
527
+
528
+ libXMTPConversations?.stream(groupEmitter.callback)
529
+ }
530
+
500
531
/* *
501
532
* Get the stream of all messages of the current [Client]
502
533
* @return Flow object of [DecodedMessage] that represents all the messages of the
0 commit comments