Add application read models and thin TUI command adapter
This commit is contained in:
@@ -39,6 +39,17 @@ enum IssueStage {
|
||||
RetryNeedsManualCleanup,
|
||||
}
|
||||
|
||||
/// Read-only first-file availability with no access to the held private key,
|
||||
/// issue context, or payload.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(super) enum SessionFirstDeliveryAvailability {
|
||||
InitialFile,
|
||||
Retry,
|
||||
RetryNeedsOverwriteConfirmation,
|
||||
RetryNeedsManualCleanup,
|
||||
Unavailable,
|
||||
}
|
||||
|
||||
pub(super) struct FirstIssueAuthorization {
|
||||
identity: PublicKey,
|
||||
context: IssueContext,
|
||||
@@ -64,6 +75,36 @@ impl FirstDeliverySession {
|
||||
self.issues.len()
|
||||
}
|
||||
|
||||
pub(super) fn read_model_availability(
|
||||
&self,
|
||||
identity: PublicKey,
|
||||
document: &ConfigDocument,
|
||||
vault: Option<&VaultBundle>,
|
||||
) -> SessionFirstDeliveryAvailability {
|
||||
let Some(issue) = self.issues.get(&identity) else {
|
||||
return SessionFirstDeliveryAvailability::Unavailable;
|
||||
};
|
||||
let matching = vault
|
||||
.and_then(|vault| context_for(document, vault, identity).ok())
|
||||
.is_some_and(|actual| actual == issue.context);
|
||||
if !matching {
|
||||
return SessionFirstDeliveryAvailability::Unavailable;
|
||||
}
|
||||
match issue.stage {
|
||||
IssueStage::AwaitingFirstFile => SessionFirstDeliveryAvailability::InitialFile,
|
||||
IssueStage::RetryAvailable => SessionFirstDeliveryAvailability::Retry,
|
||||
IssueStage::RetryNeedsOverwriteConfirmation => {
|
||||
SessionFirstDeliveryAvailability::RetryNeedsOverwriteConfirmation
|
||||
}
|
||||
IssueStage::RetryNeedsManualCleanup => {
|
||||
SessionFirstDeliveryAvailability::RetryNeedsManualCleanup
|
||||
}
|
||||
IssueStage::PendingDraft | IssueStage::Authorizing(_) => {
|
||||
SessionFirstDeliveryAvailability::Unavailable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn is_empty(&self) -> bool {
|
||||
self.issues.is_empty()
|
||||
|
||||
Reference in New Issue
Block a user