Skip to content

Commit

Permalink
stream group conversations returns groups
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 9, 2024
1 parent 165f2b2 commit b8bcfb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ class GroupTest {
boClient.conversations.streamGroups().test {
val group =
alixClient.conversations.newGroup(listOf(bo.walletAddress))
assertEquals(group.id.toHex(), awaitItem().topic)
assertEquals(group.id.toHex(), awaitItem().id.toHex())
val group2 =
caroClient.conversations.newGroup(listOf(bo.walletAddress))
assertEquals(group2.id.toHex(), awaitItem().topic)
assertEquals(group2.id.toHex(), awaitItem().id.toHex())
}
}

Expand Down
15 changes: 13 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ data class Conversations(
}

fun streamAll(): Flow<Conversation> {
return merge(streamGroups(), stream())
return merge(streamGroupConversations(), stream())
}

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

fun streamGroups(): Flow<Group> = callbackFlow {
val groupCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiGroup) {
trySend(Group(client, conversation))
}
}
val stream = libXMTPConversations?.stream(groupCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}

/**
* Get the stream of all messages of the current [Client]
* @return Flow object of [DecodedMessage] that represents all the messages of the
Expand Down

0 comments on commit b8bcfb0

Please sign in to comment.