Skip to content

Commit

Permalink
Allow empty groups (#242)
Browse files Browse the repository at this point in the history
* allow empty groups

* fix the test
  • Loading branch information
nplasterer authored May 13, 2024
1 parent 1ebf896 commit 9e06a7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,9 @@ class GroupTest {
}

@Test
fun testCannotStartEmptyGroupChat() {
assertThrows("Cannot start an empty group chat.", XMTPException::class.java) {
runBlocking { boClient.conversations.newGroup(listOf()) }
}
fun testCanStartEmptyGroupChat() {
val group = runBlocking { boClient.conversations.newGroup(listOf()) }
assert(group.id.isNotEmpty())
}

@Test
Expand Down
11 changes: 6 additions & 5 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ data class Conversations(
accountAddresses: List<String>,
permissions: GroupPermissions = GroupPermissions.EVERYONE_IS_ADMIN,
): 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 falseAddresses =
client.canMessageV3(accountAddresses).filter { !it.value }.map { it.key }
if (accountAddresses.isNotEmpty()) client.canMessageV3(accountAddresses)
.filter { !it.value }.map { it.key } else emptyList()
if (falseAddresses.isNotEmpty()) {
throw XMTPException("${falseAddresses.joinToString()} not on network")
}
Expand Down Expand Up @@ -150,7 +148,10 @@ data class Conversations(
} ?: emptyList()
}

private suspend fun handleConsentProof(consentProof: Invitation.ConsentProofPayload, peerAddress: String) {
private suspend fun handleConsentProof(
consentProof: Invitation.ConsentProofPayload,
peerAddress: String,
) {
val signature = consentProof.signature
val timestamp = consentProof.timestamp

Expand Down

0 comments on commit 9e06a7c

Please sign in to comment.