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 <noreply@anthropic.com>
This commit is contained in:
1 parent
01e022fdcc
commit
aee19737f6
5 files changed
+156
No files matched your search
@@ -196,6 +196,11 @@
|
||||
<string name="propose_translation">Propose translation</string>
|
||||
<string name="publish_new_key_package">Publish new key package</string>
|
||||
<string name="re_broadcast">Re-broadcast</string>
|
||||
<string name="asked_again">Asked the members who have not answered to take another look</string>
|
||||
<string name="everyone_has_answered_this_session">Everyone has answered. There is nobody left to ask.</string>
|
||||
<string name="one_member_has_not_answered">One member has not answered. They may never have received it.</string>
|
||||
<string name="members_have_not_answered">%1$s members have not answered. They may never have received it.</string>
|
||||
<string name="asked_again_recently">Asked again just now. You can ask again in a few minutes.</string>
|
||||
<string name="read_to_the_end_of_the_list_to_sign">Read to the end of the list to sign.</string>
|
||||
<string name="recovery_phrase">Recovery phrase</string>
|
||||
<string name="ready_to_sign">Ready to sign</string>
|
||||
|
||||
+67
@@ -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.
|
||||
|
||||
+5
@@ -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
|
||||
|
||||
+29
@@ -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
|
||||
|
||||
+50
@@ -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<HexKey> 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(
|
||||
|
||||
Reference in new issue
Block a user