From aee19737f688f2bfabb9b6f17a47a756bf4f8563 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Tue, 6 Oct 2026 15:01:09 -0500 Subject: [PATCH] feat(frost): the knock, under the list of doors it is for The resend gets its affordance on the signing screen, below the member list and above the approval block. The list is already the screen's answer to whose door to knock on; this is the knock. Coordinator only, and the state says why rather than leaving it to the button: `acceptProposal` takes a session's coordinator from the author of the proposal that opened it, so a resend from anybody else would have a member who was missing the session believe the resender coordinates -- and then drop the real coordinator's signer set. `silent` is derived on the UI state rather than collected. Everything it is made of is already there -- the share holders, who offered a nonce, who signed, who refused -- and a second flow would be a second thing that can disagree with the rows the screen draws. A member who refused is not silent: they answered. The cooldown disables the button rather than hiding the section, because a control that vanishes after a tap reads as one that failed, and what happened is that it worked. `resend` hands back whether anything went out, so the snackbar says which: asked again, or everyone has since answered and there was nobody left to ask. The transcript line gets its own icon. A resend must not read as a second proposal, which is the one thing a session can never have -- two proposals under one session id would be asking for two signatures out of one secret nonce. `ask_again` already existed in the catalogue for re-querying a list's relays and means exactly this, so it is reused rather than duplicated. m3Audit: all budgets met. jvmTest: 1260 tests, no failures. Plan: docs/frost-session-resend.md, Phases 5-7. Co-Authored-By: Claude Opus 5 --- .../composeResources/values/strings.xml | 5 ++ .../ui/composable/FrostSigningScreen.kt | 67 +++++++++++++++++++ .../composable/widgets/chat/ChatTranscript.kt | 5 ++ .../ui/view/model/FrostSigningViewModel.kt | 29 ++++++++ .../ui/view/state/FrostSigningUIState.kt | 50 ++++++++++++++ 5 files changed, 156 insertions(+) diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index fa7d0073..7232b68b 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -196,6 +196,11 @@ Propose translation Publish new key package Re-broadcast + Asked the members who have not answered to take another look + Everyone has answered. There is nobody left to ask. + One member has not answered. They may never have received it. + %1$s members have not answered. They may never have received it. + Asked again just now. You can ask again in a few minutes. Read to the end of the list to sign. Recovery phrase Ready to sign diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt index 0bf81af2..f1254e56 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Block +import androidx.compose.material.icons.filled.Campaign import androidx.compose.material.icons.filled.CheckCircle import androidx.compose.material.icons.filled.Draw import androidx.compose.material.icons.filled.ErrorOutline @@ -34,6 +35,7 @@ import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign @@ -58,7 +60,13 @@ import to.curare.compose.ui.theme.spacing import to.curare.compose.ui.composable.widgets.Decorative import curare.composeapp.generated.resources.Res import org.jetbrains.compose.resources.stringResource +import curare.composeapp.generated.resources.ask_again +import curare.composeapp.generated.resources.asked_again +import curare.composeapp.generated.resources.asked_again_recently import curare.composeapp.generated.resources.declined_to_sign +import curare.composeapp.generated.resources.everyone_has_answered_this_session +import curare.composeapp.generated.resources.members_have_not_answered +import curare.composeapp.generated.resources.one_member_has_not_answered import curare.composeapp.generated.resources.don_t_sign import curare.composeapp.generated.resources.has_not_taken_part_yet import curare.composeapp.generated.resources.members @@ -70,6 +78,7 @@ import curare.composeapp.generated.resources.signed_their_part import curare.composeapp.generated.resources.events_signed_together import androidx.compose.material3.SnackbarHost import to.curare.compose.ui.composable.widgets.LocalSnackbarHostState +import to.curare.compose.ui.composable.widgets.rememberNotifier import to.curare.compose.ui.composable.widgets.NavigateBackButton import to.curare.compose.ui.theme.readableContent import to.curare.compose.ui.theme.ConformancePreviews @@ -115,6 +124,13 @@ fun FrostSigningScreen( } } + // Both of these are composable and an onClick lambda is not, so they are + // read here rather than in the handler. The notifier takes the caller's + // scope on purpose -- see rememberNotifier. + val notify = rememberNotifier(rememberCoroutineScope()) + val askedAgain = stringResource(Res.string.asked_again) + val everyoneAnswered = stringResource(Res.string.everyone_has_answered_this_session) + Scaffold( snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) }, topBar = { @@ -261,6 +277,57 @@ fun FrostSigningScreen( } } + // The coordinator's knock, under the list of doors it is for. + // + // A session can wait forever on a member whose copy of the + // proposal never arrived -- MLS dropped the generation it came + // in at, or a disappearing-message group expired it off the + // relay -- and neither heals on its own. Repeating the proposal + // is the only thing that reaches them, and it also names them, + // so that a member whose own answer went missing on the way + // here says it again. + if (state.canResend) { + HorizontalDivider() + + Text( + text = if (state.silent.size == 1) { + stringResource(Res.string.one_member_has_not_answered) + } else { + stringResource( + Res.string.members_have_not_answered, + state.silent.size + ) + }, + style = MaterialTheme.typography.bodySmall + ) + + // Disabled rather than hidden while the cooldown runs. A + // control that vanishes after a tap reads as one that + // failed, and what happened is that it worked. + val waiting = state.resendAvailableAt != null + + if (waiting) { + Text( + text = stringResource(Res.string.asked_again_recently), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + + Button( + enabled = !waiting && !frostSigningViewModel.isActionPending.value, + onClick = { + frostSigningViewModel.resend { sent -> + notify(if (sent) askedAgain else everyoneAnswered) + } + } + ) { + Icon(Icons.Default.Campaign, contentDescription = Decorative) + Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125)) + Text(stringResource(Res.string.ask_again)) + } + } + // Asked rather than re-derived: the manager owns when a session // is still waiting on its owner, and a second copy of that rule // here is a second copy to keep in step. diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt index c3da195e..d7631fc2 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt @@ -33,6 +33,7 @@ import androidx.compose.material.icons.filled.CheckCircle import androidx.compose.material.icons.filled.ChevronRight import androidx.compose.material.icons.filled.ErrorOutline import androidx.compose.material.icons.filled.CallMerge +import androidx.compose.material.icons.filled.Campaign import androidx.compose.material.icons.filled.FactCheck import androidx.compose.material.icons.filled.Draw import androidx.compose.material.icons.filled.Download @@ -825,6 +826,10 @@ private fun RitualNotice( // A refusal the session survived. Quiet on purpose: it is not an error, // and the one that ends a session is written as a failure instead. ChatMessage.TYPE_FROST_DECLINED -> Icons.Default.Block + // Nothing moved; somebody knocked. Its own icon rather than the + // proposal's, so that a resend does not read as a second proposal -- + // which is the one thing a session must never have. + ChatMessage.TYPE_FROST_RESENT -> Icons.Default.Campaign ChatMessage.TYPE_FROST_APPROVAL_NEEDED -> Icons.Default.Draw ChatMessage.TYPE_CHRONICLE_REQUESTED -> Icons.Default.History diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt index 1f730feb..08c0a212 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt @@ -133,6 +133,35 @@ class FrostSigningViewModel( } } + /** + * Asks the members this session has heard nothing from to take another look. + * + * Unlike [approve] and [decline] this does not navigate away: the point of + * pressing it is to go on watching whether anybody answers, and the screen + * is the only place that says who has. [onResult] is handed whether anything + * actually went out, so the caller can say which happened -- a resend inside + * the cooldown, or one where everybody has since answered, publishes nothing + * and should not claim to have. + */ + fun resend(onResult: (sent: Boolean) -> Unit) { + val state = frostSigningUIState as? FrostSigningUIState.Loaded ?: return + val sessionId = state.session?.id ?: return + + if (isActionPending.value) return + isActionPending.value = true + + viewModelScope.launch(Dispatchers.IO) { + val sent = frostSigningRepository.resend( + localChatRoom = state.localChatRoom, + sessionId = sessionId + ) + + isActionPending.value = false + + viewModelScope.launch(Dispatchers.Main) { onResult.invoke(sent) } + } + } + fun decline(onDone: () -> Unit) { val state = frostSigningUIState as? FrostSigningUIState.Loaded ?: return val sessionId = state.session?.id ?: return diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt index cbcedb3b..55e267a3 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt @@ -1,11 +1,15 @@ package to.curare.compose.ui.view.state import com.vitorpamplona.quartz.nip01Core.core.HexKey +import kotlin.time.Clock +import kotlin.time.Instant import to.curare.compose.database.model.FrostSigningItem import to.curare.compose.database.model.FrostSigningSession import to.curare.compose.database.model.Participant import to.curare.compose.database.model.intermdiate.LocalChatRoom import to.curare.compose.database.model.intermdiate.LocalParticipant +import to.curare.compose.database.model.types.FrostSigningStage +import to.curare.compose.managers.FrostSigningManager sealed interface FrostSigningUIState { data class Loaded( @@ -76,6 +80,52 @@ sealed interface FrostSigningUIState { return inRoom + elsewhere } + + /** + * The share holders this session has heard nothing at all from. + * + * Whose door to knock on, as a set rather than as a list of rows: it is + * what decides whether there is anything to knock about. A member who + * refused is not here -- they answered, and asking again would be asking + * a question they have closed. + * + * Derived rather than collected. Everything it is made of is already on + * this state, and a second flow for it would be a second thing that can + * disagree with the rows the screen draws. + */ + val silent: Set get() = + shareHolders - offeredNonce - signed - declined - localChatRoom.chatRoom.userPublicKey + + /** + * Whether this device may ask the quiet members to take another look. + * + * The coordinator's, and nobody else's: `acceptProposal` takes a + * session's coordinator from the author of the proposal that opened it, + * so a resend from anybody else would have a member who was missing the + * session believe the resender coordinates -- and then drop the real + * coordinator's signer set. See `FrostSigningManager.resend`. + * + * An abandoned session is not resent either. Its nonce seeds have been + * published against an aggregate already, so the retry is a fresh + * proposal, which is what the status line says. + * + * The cooldown is deliberately not read here. A control that vanishes + * after a tap reads as one that failed, so the section stays and the + * button inside it is what goes quiet -- see [resendAvailableAt]. + */ + val canResend: Boolean get() { + val session = session ?: return false + + return session.isCoordinator() && + session.stage != FrostSigningStage.FAILED && + items.isNotEmpty() && + silent.isNotEmpty() + } + + /** When the next resend may go out, or null when one may go out now. */ + val resendAvailableAt: Instant? get() = session?.resentAt + ?.plus(FrostSigningManager.RESEND_COOLDOWN) + ?.takeIf { it > Clock.System.now() } } data class Error(