Skip to content

Commit edd7eb2

Browse files
authored
stream group conversations returns groups (#174)
1 parent 165f2b2 commit edd7eb2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ class GroupTest {
232232
boClient.conversations.streamGroups().test {
233233
val group =
234234
alixClient.conversations.newGroup(listOf(bo.walletAddress))
235-
assertEquals(group.id.toHex(), awaitItem().topic)
235+
assertEquals(group.id.toHex(), awaitItem().id.toHex())
236236
val group2 =
237237
caroClient.conversations.newGroup(listOf(bo.walletAddress))
238-
assertEquals(group2.id.toHex(), awaitItem().topic)
238+
assertEquals(group2.id.toHex(), awaitItem().id.toHex())
239239
}
240240
}
241241

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ data class Conversations(
501501
}
502502

503503
fun streamAll(): Flow<Conversation> {
504-
return merge(streamGroups(), stream())
504+
return merge(streamGroupConversations(), stream())
505505
}
506506

507-
fun streamGroups(): Flow<Conversation> = callbackFlow {
507+
private fun streamGroupConversations(): Flow<Conversation> = callbackFlow {
508508
val groupCallback = object : FfiConversationCallback {
509509
override fun onConversation(conversation: FfiGroup) {
510510
trySend(Conversation.Group(Group(client, conversation)))
@@ -515,6 +515,17 @@ data class Conversations(
515515
awaitClose { stream.end() }
516516
}
517517

518+
fun streamGroups(): Flow<Group> = callbackFlow {
519+
val groupCallback = object : FfiConversationCallback {
520+
override fun onConversation(conversation: FfiGroup) {
521+
trySend(Group(client, conversation))
522+
}
523+
}
524+
val stream = libXMTPConversations?.stream(groupCallback)
525+
?: throw XMTPException("Client does not support Groups")
526+
awaitClose { stream.end() }
527+
}
528+
518529
/**
519530
* Get the stream of all messages of the current [Client]
520531
* @return Flow object of [DecodedMessage] that represents all the messages of the

0 commit comments

Comments
 (0)