feat(proposals): ask the quiet members again from the row

The offer the signing screen already makes, reached from the list. A
coordinator whose room has stalled should not have to open each proposal in
turn to find the button, and filtering to "being signed" now puts every stalled
one in front of them at once.

It is on the row and not on the chip, which is where it was asked for, for
three reasons. A chip is a selection control, and giving it a second action
would make the control that publishes the one you cannot undo. A chip stands
for several proposals while `resend` takes one session, so a chip-level button
means resending all of them -- and the manager caps itself at two messages per
resend precisely because "publishing in bursts is what the skipped-keys bug
feeds on", which three proposals at six messages would re-create. And the offer
is the coordinator's alone and only exists while somebody owes, so on a chip
standing for a mixed set it would be enabled for proposals it cannot act on.

It is called "ask again" rather than "re-broadcast" for the same reason the
list calls a review a review: somebody who found the button on the signing
screen and then found this one should not have to work out that two labels are
one button.

Whether to offer it is asked of `membersOwing`, not derived from the signature
count. Past the nonces a signer who refused has answered and is owed nothing
while the count is still short by one, so a row reading `have < need` would
offer to knock on a door that has already been shut. That is one query per row
and the only one on this screen, so it is asked for as few rows as possible:
not ours to send, nothing to send, and already ended all answer without
touching the database. An ended session is left out although the manager would
take it -- re-sending a completed one delivers the signature to a member who
never applied it, which is worth a button on the one proposal's screen rather
than a query per row on a list that only grows. The signing screen still offers
it.

Guarded per session rather than by one flag for the screen, because these rooms
have several proposals open at once and a coordinator working down the list
should not be locked out of the second by the first still publishing. The
cooldown disables rather than hides, as it does on the signing screen: a
control that vanishes after a tap reads as one that failed.

1396 jvm tests pass, the Android target compiles, all audit budgets met.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-10-08 15:45:58 -05:00
1 parent 1f82d66f57
commit 4330d718be
6 files changed
+754 -22

No files matched your search

@@ -3,7 +3,10 @@ package to.curare.compose.ui.composable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@@ -11,6 +14,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Campaign
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.filled.Draw
@@ -22,6 +26,7 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.TextButton
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
@@ -32,6 +37,7 @@ import androidx.compose.material3.Text
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.graphics.Color
@@ -59,6 +65,11 @@ import to.curare.compose.ui.theme.spacing
import curare.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
import curare.composeapp.generated.resources.abandoned
import curare.composeapp.generated.resources.everyone_has_signed_this_session
import curare.composeapp.generated.resources.asked_again_to_sign
import curare.composeapp.generated.resources.asked_again_recently
import curare.composeapp.generated.resources.asked_again
import curare.composeapp.generated.resources.ask_again
import curare.composeapp.generated.resources.you_declined
import curare.composeapp.generated.resources.you_are_signing
import curare.composeapp.generated.resources.you_agreed
@@ -91,7 +102,9 @@ import to.curare.compose.ui.composable.widgets.ErrorState
import to.curare.compose.ui.composable.widgets.LoadingDataIndicator
import to.curare.compose.ui.composable.widgets.LocalSnackbarHostState
import to.curare.compose.ui.composable.widgets.ScreenStateTransition
import to.curare.compose.ui.composable.widgets.Decorative
import to.curare.compose.ui.composable.widgets.NavigateBackButton
import to.curare.compose.ui.composable.widgets.rememberNotifier
import to.curare.compose.ui.theme.readableContent
import to.curare.compose.ui.theme.ConformancePreviews
@@ -168,6 +181,32 @@ fun ProposalListScreen(
)
is ProposalListUIState.Loaded -> {
// Read above the handlers, because `rememberNotifier` and
// `stringResource` are composable and an onClick is not. The
// notifier takes this screen's scope on purpose: a resend is
// often the last thing a coordinator does before leaving.
val notify = rememberNotifier(rememberCoroutineScope())
val asked = stringResource(Res.string.asked_again)
val askedToSign = stringResource(Res.string.asked_again_to_sign)
val nobodyLeft = stringResource(Res.string.everyone_has_signed_this_session)
val askAgain: (ProposalListUIState.Proposal) -> Unit = { proposal ->
val signing = proposal.state == ProposalState.BEING_SIGNED
proposalListViewModel.askAgain(proposal.session.id) { sent ->
notify(
when {
sent && signing -> askedToSign
sent -> asked
// Nothing went out. The row cannot tell a
// cooldown from an empty queue, so it says
// the one the button is only offered under.
else -> nobodyLeft
}
)
}
}
val open: (ProposalListUIState.Proposal) -> Unit = { proposal ->
onNavigateToRoute.invoke(
FrostSigningRoute(
@@ -200,6 +239,8 @@ fun ProposalListScreen(
ProposalList(
state = state,
onOpen = open,
onAskAgain = askAgain,
isAsking = proposalListViewModel::isAsking,
modifier = Modifier.weight(1f)
)
}
@@ -224,6 +265,8 @@ fun ProposalListScreen(
private fun ProposalList(
state: ProposalListUIState.Loaded,
onOpen: (ProposalListUIState.Proposal) -> Unit,
onAskAgain: (ProposalListUIState.Proposal) -> Unit,
isAsking: (String) -> Boolean,
modifier: Modifier = Modifier,
) {
// Said rather than defaulted, because five different absences used to say one
@@ -259,7 +302,12 @@ private fun ProposalList(
) {
if (state.filter != ProposalFilter.ALL) {
items(items = state.visible, key = { it.session.id }) { proposal ->
ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
ProposalCard(
proposal = proposal,
onClick = { onOpen(proposal) },
onAskAgain = { onAskAgain(proposal) },
asking = isAsking(proposal.session.id)
)
}
return@LazyColumn
@@ -278,7 +326,12 @@ private fun ProposalList(
items = state.waitingForYou,
key = { it.session.id }
) { proposal ->
ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
ProposalCard(
proposal = proposal,
onClick = { onOpen(proposal) },
onAskAgain = { onAskAgain(proposal) },
asking = isAsking(proposal.session.id)
)
}
}
@@ -299,7 +352,12 @@ private fun ProposalList(
items = state.rest,
key = { it.session.id }
) { proposal ->
ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
ProposalCard(
proposal = proposal,
onClick = { onOpen(proposal) },
onAskAgain = { onAskAgain(proposal) },
asking = isAsking(proposal.session.id)
)
}
}
}
@@ -381,6 +439,8 @@ private fun labelOf(filter: ProposalFilter): String = when (filter) {
private fun ProposalCard(
proposal: ProposalListUIState.Proposal,
onClick: () -> Unit,
onAskAgain: (() -> Unit)? = null,
asking: Boolean = false,
) {
val lead = proposal.signs.firstOrNull()
@@ -529,12 +589,64 @@ private fun ProposalCard(
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
if (onAskAgain != null && proposal.canAskAgain) {
AskAgainButton(
proposal = proposal,
asking = asking,
onAskAgain = onAskAgain
)
}
}
}
)
}
}
/**
* Asks the members a proposal is still waiting on to take another look.
*
* The same offer the signing screen makes, and deliberately the same words: a
* coordinator who went looking for it there and found it here should not have
* to work out that "re-broadcast" and "ask again" are one button. What the list
* adds is reach -- the one proposal that has stalled is found by filtering to
* it, rather than by opening each in turn.
*
* 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.
*/
@Composable
private fun AskAgainButton(
proposal: ProposalListUIState.Proposal,
asking: Boolean,
onAskAgain: () -> Unit,
) {
val waiting = proposal.askAgainAt != null
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space25)) {
if (waiting) {
Text(
text = stringResource(Res.string.asked_again_recently),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
TextButton(
enabled = !waiting && !asking,
onClick = onAskAgain,
contentPadding = PaddingValues(
horizontal = MaterialTheme.spacing.compactPadding,
vertical = MaterialTheme.spacing.space25,
)
) {
Icon(Icons.Default.Campaign, contentDescription = Decorative)
Spacer(modifier = Modifier.width(MaterialTheme.spacing.itemGap))
Text(stringResource(Res.string.ask_again))
}
}
}
/**
* Who the reader is in this proposal, in a line.
*
@@ -2,6 +2,7 @@ package to.curare.compose.ui.view.model
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableStateSetOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
@@ -17,6 +18,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import to.curare.compose.database.model.intermdiate.FrostSignerTally
import to.curare.compose.database.model.intermdiate.LocalFrostSigningSession
import to.curare.compose.database.model.types.FrostSigningStage
import to.curare.compose.extensions.shortened
import to.curare.compose.managers.FrostSigningManager
import to.curare.compose.nostr.frost.FrostSigningEvents
@@ -61,6 +63,12 @@ class ProposalListViewModel(
*/
private var filter: ProposalFilter = initialFilter
/**
* The sessions whose "ask again" is in flight, so a second tap on one row
* does not publish twice while the first is still going out.
*/
private val pending = mutableStateSetOf<String>()
private val logger = Logger.withTag(TAG)
init {
@@ -135,7 +143,7 @@ class ProposalListViewModel(
* worked out here, so the list and the signing screen cannot disagree about
* which proposals still have a decision in them.
*/
private fun asProposal(
private suspend fun asProposal(
local: LocalFrostSigningSession,
tallies: List<FrostSignerTally>,
): ProposalListUIState.Proposal {
@@ -157,10 +165,72 @@ class ProposalListViewModel(
unreadable = items.size - events.size,
awaitsYou = FrostSigningManager.isAwaitingApproval(local.session, items),
noncesOffered = counted(FrostSigningEvents.NONCE),
partialSignatures = counted(FrostSigningEvents.PARTIAL_SIGNATURE)
partialSignatures = counted(FrostSigningEvents.PARTIAL_SIGNATURE),
owing = owingFor(local)
)
}
/**
* How many members a session is still waiting on, when asking them again is
* this device's to offer.
*
* A query per row, and the only one on this screen -- so it is asked for as
* few rows as possible. Not ours to send, nothing to send, or already ended:
* all three answer null without touching the database.
*
* An ended session is left out although `FrostSigningManager.resend` would
* take it: a completed one can be re-sent to deliver the signature to a
* member who never applied it, and that is worth a button on the one
* proposal's screen rather than on every row of a list that only grows. The
* signing screen still offers it.
*/
private suspend fun owingFor(local: LocalFrostSigningSession): Int? {
val session = local.session
if (!session.isCoordinator() || local.items.isEmpty()) return null
return when (session.stage) {
FrostSigningStage.COLLECTING_NONCES,
FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES ->
frostSigningRepository.membersOwing(session).size
FrostSigningStage.COMPLETE, FrostSigningStage.FAILED -> null
}
}
/**
* Asks the members a proposal is still waiting on to take another look.
*
* Guarded per session rather than by one flag for the screen, because the
* rooms this screen is for have several proposals open at once and a
* coordinator working down the list should not be locked out of the second
* by the first still publishing.
*
* [onResult] is told whether anything went out. `resend` answers false for
* a cooldown that has not run out, a session waiting on nobody and a stage
* that cannot be resent, and the row that offered the button has no way to
* know which -- so what it says afterwards comes from here.
*/
fun askAgain(sessionId: String, onResult: (sent: Boolean) -> Unit) {
val state = proposalListUIState as? ProposalListUIState.Loaded ?: return
if (!pending.add(sessionId)) return
viewModelScope.launch(Dispatchers.IO) {
val sent = frostSigningRepository.resend(
localChatRoom = state.localChatRoom,
sessionId = sessionId
)
pending.remove(sessionId)
viewModelScope.launch(Dispatchers.Main) { onResult.invoke(sent) }
}
}
/** Whether an ask for this session is still in flight. */
fun isAsking(sessionId: String): Boolean = sessionId in pending
companion object {
private const val TAG = "ProposalListViewModel"
@@ -1,8 +1,11 @@
package to.curare.compose.ui.view.state
import kotlin.time.Clock
import kotlin.time.Instant
import to.curare.compose.database.model.FrostSigningSession
import to.curare.compose.database.model.intermdiate.LocalChatRoom
import to.curare.compose.database.model.types.FrostSigningStage
import to.curare.compose.managers.FrostSigningManager
import to.curare.compose.text.ProposedEvent
sealed interface ProposalListUIState {
@@ -104,6 +107,24 @@ sealed interface ProposalListUIState {
*/
val noncesOffered: Int = 0,
val partialSignatures: Int = 0,
/**
* How many share holders the session is still waiting on, or null when
* asking them again is not this device's to offer.
*
* Asked of `FrostSigningManager.membersOwing` rather than worked out
* from the counts above, because the two are not the same question and
* the difference is a button that does nothing. Past the nonces a signer
* who refused has answered and is owed nothing, while the signature
* count is still short by one -- so a row reading `have < need` would
* offer to knock on a door that has already been shut.
*
* Null rather than zero for a session this device did not propose: a
* resend from anybody else would have a member who was missing the
* session believe the resender coordinates. Zero means it is ours to
* send and there is nobody left to send it to.
*/
val owing: Int? = null,
) {
/** The batch's size, readable or not. */
val eventCount: Int get() = signs.size + unreadable
@@ -172,6 +193,30 @@ sealed interface ProposalListUIState {
FrostSigningStage.COMPLETE, FrostSigningStage.FAILED -> null
}
/**
* Whether to offer asking the quiet members to take another look.
*
* The same offer the signing screen makes, reached from the row rather
* than from a tap into it -- a coordinator scanning a list for the one
* that has stalled should not have to open each to find the button. It
* is offered only when there is somebody to ask, because a control that
* publishes nothing is worse than no control.
*/
val canAskAgain: Boolean get() = (owing ?: 0) > 0
/**
* When the next ask may go out, or null when one may go out now.
*
* Read at composition rather than ticked, exactly as the signing screen
* reads it. The cooldown is five minutes and every message the room
* exchanges recomposes this screen, so a button left disabled a little
* past its time is the worst this costs -- and that is the safe
* direction for a control that publishes.
*/
val askAgainAt: Instant? get() = session.resentAt
?.plus(FrostSigningManager.RESEND_COOLDOWN)
?.takeIf { it > Clock.System.now() }
}
/**