Skip to content

Commit eae74a3

Browse files
committed
dont return self for peers and add erroring to new group creation
1 parent 655ad0d commit eae74a3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ sealed class Conversation {
5555
return when (this) {
5656
is V1 -> conversationV1.peerAddress
5757
is V2 -> conversationV2.peerAddress
58-
is Group -> group.memberAddresses().joinToString(",")
58+
is Group -> {
59+
val addresses = group.memberAddresses().toMutableList()
60+
addresses.remove(clientAddress)
61+
addresses.joinToString(",")
62+
}
5963
}
6064
}
6165

@@ -64,7 +68,11 @@ sealed class Conversation {
6468
return when (this) {
6569
is V1 -> listOf(conversationV1.peerAddress)
6670
is V2 -> listOf(conversationV2.peerAddress)
67-
is Group -> group.memberAddresses()
71+
is Group -> {
72+
val addresses = group.memberAddresses().toMutableList()
73+
addresses.remove(clientAddress)
74+
addresses
75+
}
6876
}
6977
}
7078

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

+13
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ data class Conversations(
9090
}
9191

9292
fun newGroup(accountAddresses: List<String>): Group {
93+
if (accountAddresses.isEmpty()) {
94+
throw XMTPException("Cannot start an empty group chat.")
95+
}
96+
if (accountAddresses.size == 1 && accountAddresses.first()
97+
.lowercase() == client.address.lowercase()
98+
) {
99+
throw XMTPException("Recipient is sender")
100+
}
101+
val contacts = accountAddresses.map { client.contacts.find(it) }
102+
if (contacts.size != accountAddresses.size) {
103+
throw XMTPException("Recipient not on network")
104+
}
105+
93106
val group = runBlocking {
94107
libXMTPConversations?.createGroup(accountAddresses)
95108
?: throw XMTPException("Client does not support Groups")

0 commit comments

Comments
 (0)