diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/concord/ConcordCreateScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/concord/ConcordCreateScreen.kt index 5429ace9f9..6efc450133 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/concord/ConcordCreateScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/concord/ConcordCreateScreen.kt @@ -49,6 +49,7 @@ import com.vitorpamplona.amethyst.commons.model.navigation.Route import com.vitorpamplona.amethyst.commons.resources.Res import com.vitorpamplona.amethyst.commons.resources.back import com.vitorpamplona.amethyst.commons.resources.concord_create_action +import com.vitorpamplona.amethyst.commons.resources.concord_create_failed import com.vitorpamplona.amethyst.commons.resources.concord_create_relays import com.vitorpamplona.amethyst.commons.resources.concord_create_relays_desc import com.vitorpamplona.amethyst.commons.resources.concord_create_title @@ -139,7 +140,11 @@ fun ConcordCreateScreen( // Replace this form with the new community, as the Marmot and relay-group creators // do. newStack only popped up to the community route itself, which was not on the // stack, so Back from the new community reopened a filled-in create form. - if (communityId != null) nav.popUpTo(Route.ConcordServer(communityId), Route.ConcordCreate::class) + if (communityId != null) { + nav.popUpTo(Route.ConcordServer(communityId), Route.ConcordCreate::class) + } else { + accountViewModel.toastManager.toast(Res.string.concord_create_title, Res.string.concord_create_failed) + } } }, enabled = name.value.isNotBlank() && !working, diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/AccountConcordActions.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/AccountConcordActions.kt index d9229873d9..e75c1f3fb8 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/AccountConcordActions.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/AccountConcordActions.kt @@ -232,7 +232,7 @@ class AccountConcordActions( * Create a new Concord community: mint its genesis (metadata + #general), * publish the owner-signed genesis wraps to [relays] (or our outbox), and add * the secret-bearing entry to the Community List (kind 33302). Returns the new - * community id, or null if not writeable. + * community id, or null if not writeable or no relay accepted the genesis. */ suspend fun createConcordCommunity( name: String, @@ -251,7 +251,18 @@ class AccountConcordActions( val community = ConcordActions.createCommunity(account.signer, name, TimeUtils.now(), description, relayUrls, icon) val publishTo = relayUrls.mapNotNullTo(mutableSetOf()) { RelayUrlNormalizer.normalizeOrNull(it) }.ifEmpty { account.outboxRelays.flow.value } - community.genesisWraps.forEach { account.client.publish(it, publishTo) } + // The genesis is the community: with no relay holding it, nobody (us included, after a + // restart) can ever fold it. It used to be fired and forgotten, then the community saved + // anyway, so a genesis a relay refused or an app killed mid-send left a community in the + // List that could never load again. Confirm every genesis wrap before saving it. + val landed = + coroutineScope { + community.genesisWraps.map { async { account.client.publishAndConfirm(it, publishTo) } }.awaitAll() + } + if (!landed.all { it }) { + Log.w("Concord") { "createConcordCommunity: no relay in $publishTo accepted the genesis; not creating ${community.communityIdHex}" } + return null + } joinConcordCommunity( ConcordCommunityListEntry( diff --git a/commonsUI/src/commonMain/composeResources/values/strings.xml b/commonsUI/src/commonMain/composeResources/values/strings.xml index d83cb04e80..f1900d96b2 100644 --- a/commonsUI/src/commonMain/composeResources/values/strings.xml +++ b/commonsUI/src/commonMain/composeResources/values/strings.xml @@ -3614,6 +3614,7 @@ Rename No channels yet. Create + No relay accepted the new community, so it was not created. Check the relays and try again. Relays Relays that store this community's encrypted messages. Leave empty to use your own. New Concord Channel