1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Pending composer submission state for TUI rendering.
/// Pending user message not yet confirmed by the session stream.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PendingSubmission {
id: bcode_session_models::SubmissionId,
text: String,
reveal_on_acceptance: bool,
state: PendingSubmissionState,
}
impl PendingSubmission {
/// Create a pending submission in the sending state.
#[must_use]
pub fn new(text: String) -> Self {
Self {
id: bcode_session_models::SubmissionId(
bcode_session_models::SessionId::new().to_string(),
),
text,
reveal_on_acceptance: true,
state: PendingSubmissionState::Sending,
}
}
/// Stable submission identity.
#[must_use]
pub const fn id(&self) -> &bcode_session_models::SubmissionId {
&self.id
}
/// Supersede the positioning associated with this submission, but retain its data.
pub const fn cancel_reveal(&mut self) {
self.reveal_on_acceptance = false;
}
/// Whether acceptance still owns a pending navigation intent.
#[must_use]
pub const fn reveals_on_acceptance(&self) -> bool {
self.reveal_on_acceptance
}
/// Mark the submission as queued.
pub const fn mark_queued(&mut self, queue_position: Option<u32>) {
self.state = PendingSubmissionState::Queued { queue_position };
}
/// Mark the submission as sent.
pub const fn mark_sent(&mut self) {
self.state = PendingSubmissionState::Sent;
}
/// Return pending text.
#[must_use]
pub fn text(&self) -> &str {
&self.text
}
/// Return pending state.
#[must_use]
pub const fn state(&self) -> PendingSubmissionState {
self.state
}
}
/// Pending user message state.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PendingSubmissionState {
/// Client request is in flight.
Sending,
/// Server accepted the request immediately.
Sent,
/// Server queued the request.
Queued {
/// Server-reported queue position.
queue_position: Option<u32>,
},
}