Skip to content

Commit

Permalink
fix up actually removing self from peer addresses (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer authored Feb 22, 2024
1 parent e1eec1d commit 8cb7090
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 10 additions & 4 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ class GroupTest {
bo.walletAddress.lowercase()
).sorted()
)

assertEquals(
Conversation.Group(group).peerAddresses.sorted(),
listOf(
caro.walletAddress.lowercase(),
alix.walletAddress.lowercase(),
).sorted()
)
}

@Test
Expand Down Expand Up @@ -430,8 +438,7 @@ class GroupTest {
)

var result = boClient.contacts.isGroupAllowed(group.id)

assert(!result)
assert(result)

boClient.contacts.allowGroup(listOf(group.id))

Expand All @@ -448,8 +455,7 @@ class GroupTest {
)
)
var result = boClient.contacts.isGroupAllowed(group.id)

assert(!result)
assert(result)

boClient.contacts.denyGroup(listOf(group.id))

Expand Down
12 changes: 2 additions & 10 deletions library/src/main/java/org/xmtp/android/library/Conversation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ sealed class Conversation {
return when (this) {
is V1 -> conversationV1.peerAddress
is V2 -> conversationV2.peerAddress
is Group -> {
val addresses = group.memberAddresses().toMutableList()
addresses.remove(clientAddress)
addresses.joinToString(",")
}
is Group -> group.peerAddresses().joinToString(",")
}
}

Expand All @@ -68,11 +64,7 @@ sealed class Conversation {
return when (this) {
is V1 -> listOf(conversationV1.peerAddress)
is V2 -> listOf(conversationV2.peerAddress)
is Group -> {
val addresses = group.memberAddresses().toMutableList()
addresses.remove(clientAddress)
addresses
}
is Group -> group.peerAddresses()
}
}

Expand Down
6 changes: 6 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
}
}

fun peerAddresses(): List<String> {
val addresses = memberAddresses().map { it.lowercase() }.toMutableList()
addresses.remove(client.address.lowercase())
return addresses
}

fun streamMessages(): Flow<DecodedMessage> = callbackFlow {
val messageCallback = object : FfiMessageCallback {
override fun onMessage(message: FfiMessage) {
Expand Down

0 comments on commit 8cb7090

Please sign in to comment.