From eae74a3b831d58a9197ccb4c83488c2fa790bbe2 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 30 Jan 2024 07:28:20 -0800 Subject: [PATCH] dont return self for peers and add erroring to new group creation --- .../java/org/xmtp/android/library/Conversation.kt | 12 ++++++++++-- .../java/org/xmtp/android/library/Conversations.kt | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index f8a37ef8b..534e42a0f 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -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(",") + } } } @@ -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 + } } } diff --git a/library/src/main/java/org/xmtp/android/library/Conversations.kt b/library/src/main/java/org/xmtp/android/library/Conversations.kt index 51226c7b7..2e3d26a34 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -90,6 +90,19 @@ data class Conversations( } fun newGroup(accountAddresses: List): 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")