Skip to content

Commit

Permalink
dont return self for peers and add erroring to new group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 30, 2024
1 parent 655ad0d commit eae74a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Conversation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ sealed class Conversation {
return when (this) {
is V1 -> conversationV1.peerAddress
is V2 -> conversationV2.peerAddress
is Group -> group.memberAddresses().joinToString(",")
is Group -> {
val addresses = group.memberAddresses().toMutableList()
addresses.remove(clientAddress)
addresses.joinToString(",")
}
}
}

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

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

fun newGroup(accountAddresses: List<String>): Group {
if (accountAddresses.isEmpty()) {
throw XMTPException("Cannot start an empty group chat.")
}
if (accountAddresses.size == 1 && accountAddresses.first()
.lowercase() == client.address.lowercase()
) {
throw XMTPException("Recipient is sender")
}
val contacts = accountAddresses.map { client.contacts.find(it) }
if (contacts.size != accountAddresses.size) {
throw XMTPException("Recipient not on network")
}

val group = runBlocking {
libXMTPConversations?.createGroup(accountAddresses)
?: throw XMTPException("Client does not support Groups")
Expand Down

0 comments on commit eae74a3

Please sign in to comment.