Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream Groups Returns Groups #174

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading