feat(tui): join outbox rows to chat rows by message id
`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 `✓` whenever a newer send of the same text had already crossed the circuit. `store::Message` now carries its `messages.id` and the TUI joins on `Message::id != OutboxEntry::message_id`... strictly equal, that is. 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
ebd3a306e8
commit
93e05e2fef
4 changed files with 89 additions and 41 deletions
|
|
@ -388,21 +388,24 @@ fn ascii_switch_80x24_frame_is_pure_ascii() {
|
|||
// prefix, no parallel state model.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
fn out_msg(body: &str) -> Message {
|
||||
fn out_msg(id: i64, body: &str) -> Message {
|
||||
Message {
|
||||
id,
|
||||
dir: "out".into(),
|
||||
plaintext: body.as_bytes().to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
fn in_msg(body: &str) -> Message {
|
||||
fn in_msg(id: i64, body: &str) -> Message {
|
||||
Message {
|
||||
id,
|
||||
dir: "in".into(),
|
||||
plaintext: body.as_bytes().to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
fn pending_row(
|
||||
message_id: i64,
|
||||
body: &str,
|
||||
status: OutboxStatus,
|
||||
attempts: u32,
|
||||
|
|
@ -412,7 +415,7 @@ fn pending_row(
|
|||
OutboxEntry {
|
||||
id: 1,
|
||||
friend_pk: vec![9u8; 32],
|
||||
message_id: 1,
|
||||
message_id,
|
||||
body: body.as_bytes().to_vec(),
|
||||
attempts,
|
||||
next_attempt_at: now + next_in,
|
||||
|
|
@ -422,16 +425,23 @@ fn pending_row(
|
|||
}
|
||||
}
|
||||
|
||||
fn queued_row(body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
|
||||
pending_row(body, OutboxStatus::Queued, attempts, next_in, now)
|
||||
fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
|
||||
pending_row(message_id, body, OutboxStatus::Queued, attempts, next_in, now)
|
||||
}
|
||||
|
||||
fn sending_row(body: &str, now: i64) -> OutboxEntry {
|
||||
pending_row(body, OutboxStatus::Sending, 1, 0, now)
|
||||
fn sending_row(message_id: i64, body: &str, now: i64) -> OutboxEntry {
|
||||
pending_row(message_id, body, OutboxStatus::Sending, 1, 0, now)
|
||||
}
|
||||
|
||||
fn failed_row(body: &str, why: &str, now: i64) -> OutboxEntry {
|
||||
pending_row(body, OutboxStatus::Failed(why.into()), 8, 0, now)
|
||||
fn failed_row(message_id: i64, body: &str, why: &str, now: i64) -> OutboxEntry {
|
||||
pending_row(
|
||||
message_id,
|
||||
body,
|
||||
OutboxStatus::Failed(why.into()),
|
||||
8,
|
||||
0,
|
||||
now,
|
||||
)
|
||||
}
|
||||
|
||||
/// Marker is everything after the two-space separator the render helper uses.
|
||||
|
|
@ -453,8 +463,8 @@ fn queued_and_delivered_messages_render_different_markers() {
|
|||
force_unicode_mode();
|
||||
let _guard = guard;
|
||||
let now = 1_700_000_000;
|
||||
let msgs = vec![out_msg("ping"), out_msg("pong")];
|
||||
let pending = vec![queued_row("pong", 2, 45, now)];
|
||||
let msgs = vec![out_msg(1, "ping"), out_msg(2, "pong")];
|
||||
let pending = vec![queued_row(2, "pong", 2, 45, now)];
|
||||
|
||||
let (lines, summary) = chat_with_delivery(&msgs, &pending, now);
|
||||
|
||||
|
|
@ -489,6 +499,40 @@ fn queued_and_delivered_messages_render_different_markers() {
|
|||
assert_eq!(summary.failed, 0);
|
||||
}
|
||||
|
||||
/// The case the body match got wrong: the same text sent twice, only the
|
||||
/// *older* send still queued. Joined by body, the (single) pending row lands on
|
||||
/// the newest send and the actually-queued row shows `✓` — which is exactly
|
||||
/// false delivery. The join is on `Message::id` / `OutboxEntry::message_id`.
|
||||
#[test]
|
||||
fn identical_bodies_join_by_message_id_not_body() {
|
||||
let guard = ASCII_ENV.lock().expect("ascii env lock");
|
||||
force_unicode_mode();
|
||||
let _guard = guard;
|
||||
let now = 1_700_000_000;
|
||||
let msgs = vec![out_msg(7, "same text"), out_msg(8, "same text")];
|
||||
let pending = vec![queued_row(7, "same text", 1, 30, now)];
|
||||
|
||||
let (lines, summary) = chat_with_delivery(&msgs, &pending, now);
|
||||
|
||||
assert!(
|
||||
lines[0].contains('◷') && lines[0].contains("queued"),
|
||||
"queued marker must land on the queued row (id 7): {:?}",
|
||||
lines[0]
|
||||
);
|
||||
assert!(
|
||||
!lines[0].contains('✓'),
|
||||
"queued row must not claim delivery: {:?}",
|
||||
lines[0]
|
||||
);
|
||||
assert_eq!(
|
||||
marker_of(&lines[1]),
|
||||
"✓",
|
||||
"delivered row (id 8) must keep its mark: {:?}",
|
||||
lines[1]
|
||||
);
|
||||
assert_eq!(summary.note().as_deref(), Some("1 queued"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delivery_markers_have_exercised_ascii_fallbacks() {
|
||||
let _guard = ASCII_ENV.lock().expect("ascii env lock");
|
||||
|
|
@ -498,16 +542,16 @@ fn delivery_markers_have_exercised_ascii_fallbacks() {
|
|||
}
|
||||
let now = 500;
|
||||
let msgs = vec![
|
||||
out_msg("alpha"),
|
||||
out_msg("beta"),
|
||||
out_msg("gamma"),
|
||||
out_msg("delta"),
|
||||
in_msg("epsilon"),
|
||||
out_msg(1, "alpha"),
|
||||
out_msg(2, "beta"),
|
||||
out_msg(3, "gamma"),
|
||||
out_msg(4, "delta"),
|
||||
in_msg(5, "epsilon"),
|
||||
];
|
||||
let pending = vec![
|
||||
failed_row("alpha", "connect peer.onion:80: connection timed out", now),
|
||||
queued_row("beta", 1, 30, now),
|
||||
sending_row("gamma", now),
|
||||
failed_row(1, "alpha", "connect peer.onion:80: connection timed out", now),
|
||||
queued_row(2, "beta", 1, 30, now),
|
||||
sending_row(3, "gamma", now),
|
||||
];
|
||||
|
||||
let (lines, summary) = chat_with_delivery(&msgs, &pending, now);
|
||||
|
|
@ -629,8 +673,8 @@ fn chat_and_footer_rows_fit_80x24_and_wrap_instead_of_clipping() {
|
|||
let _guard = guard;
|
||||
let now = 1_700_000_000;
|
||||
let long = "this is a very long chat line that should wrap inside the chat pane instead of running off the right edge of an 80-column terminal and colliding with the roster border";
|
||||
let msgs = vec![out_msg("ok"), in_msg("pong"), out_msg(long)];
|
||||
let pending = vec![queued_row(long, 3, 45, now)];
|
||||
let msgs = vec![out_msg(1, "ok"), in_msg(2, "pong"), out_msg(3, long)];
|
||||
let pending = vec![queued_row(3, long, 3, 45, now)];
|
||||
|
||||
let (lines, summary) = chat_with_delivery(&msgs, &pending, now);
|
||||
for line in lines.iter().take(2) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue