feat(tui): join outbox rows to chat rows by message id
All checks were successful
ci / test (pull_request) Successful in 4m12s
All checks were successful
ci / test (pull_request) Successful in 4m12s
`chat_with_delivery` matched pending outbox rows to chat rows by body because `store::Message` carried no id, so an older send that was still queued showed a delivered mark whenever a newer send of the same text had already crossed the circuit. `store::Message` now carries its `messages.id`, and the TUI joins `OutboxEntry::message_id` == `Message::id`. The body match and its newest-first fallback are gone. `list_messages()` keeps its signature; callers that do not need the id are untouched.
This commit is contained in:
parent
02b531625f
commit
2cbe7d41e5
4 changed files with 89 additions and 41 deletions
26
src/tui.rs
26
src/tui.rs
|
|
@ -243,9 +243,10 @@ impl OutboxSummary {
|
|||
|
||||
/// Chat transcript with per-message delivery state, plus the footer summary.
|
||||
///
|
||||
/// Pending rows are matched to messages by body, newest send first: an
|
||||
/// outstanding retry is the most recent send of that text, and the outbox holds
|
||||
/// no message id the UI could join on.
|
||||
/// Pending rows are joined to messages on `Message::id` /
|
||||
/// `OutboxEntry::message_id` — never on the body. Two identical bodies are
|
||||
/// distinct rows with distinct ids, so the marker always lands on the row that
|
||||
/// actually owns the outbox entry.
|
||||
pub fn chat_with_delivery(
|
||||
msgs: &[Message],
|
||||
pending: &[OutboxEntry],
|
||||
|
|
@ -271,21 +272,18 @@ pub fn chat_with_delivery(
|
|||
);
|
||||
}
|
||||
|
||||
let mut by_body: HashMap<&[u8], Vec<&OutboxEntry>> = HashMap::new();
|
||||
for entry in pending {
|
||||
by_body
|
||||
.entry(entry.body.as_slice())
|
||||
.or_default()
|
||||
.push(entry);
|
||||
}
|
||||
// One row per message in practice (a retry updates its row, not inserts a
|
||||
// second), and `pending` is ordered by row id, so a hypothetical duplicate
|
||||
// resolves to the newest — the same rule the store's own
|
||||
// `outbox_status_of_message` uses.
|
||||
let by_id: HashMap<i64, &OutboxEntry> =
|
||||
pending.iter().map(|entry| (entry.message_id, entry)).collect();
|
||||
let mut tags: Vec<Option<String>> = vec![None; msgs.len()];
|
||||
for (i, msg) in msgs.iter().enumerate().rev() {
|
||||
for (i, msg) in msgs.iter().enumerate() {
|
||||
if msg.dir != "out" {
|
||||
continue;
|
||||
}
|
||||
if let Some(rows) = by_body.get_mut(msg.plaintext.as_slice())
|
||||
&& let Some(entry) = rows.pop()
|
||||
{
|
||||
if let Some(entry) = by_id.get(&msg.id) {
|
||||
tags[i] = Some(delivery_tag(
|
||||
&entry.status,
|
||||
entry.attempts,
|
||||
|
|
|
|||
Loading…
Reference in a new issue