send queue

This commit is contained in:
yves committed 2026-11-20 23:09:05 +01:00
1 parent a520ddb557
commit 10af480218
10 files changed
+701 -60

No files matched your search

+40 -2
View File
@@ -77,6 +77,12 @@ enum Cmd {
#[arg(short, long)]
exit: bool,
},
/// Show the send queue (messages not yet accepted by every server).
Outbox {
/// Try to deliver everything now.
#[arg(long)]
flush: bool,
},
/// Show the conversation with a contact.
History { contact: String },
}
@@ -376,11 +382,11 @@ async fn run() -> Result<()> {
}
Cmd::Send { contact, text } => {
let r = ctx.open().await?.send_text(&contact, &text.join(" ")).await?;
println!("sent to {contact} ({} server(s))", r.delivered_to);
print_sent(&contact, None, r.delivered_to);
}
Cmd::SendFile { contact, file } => {
let r = ctx.open().await?.send_file(&contact, &file).await?;
println!("sent {} to {contact} ({} server(s))", file.display(), r.delivered_to);
print_sent(&contact, Some(&file), r.delivered_to);
}
Cmd::Sync { wait } => {
let mut c = ctx.open().await?;
@@ -397,6 +403,28 @@ async fn run() -> Result<()> {
}
}
}
Cmd::Outbox { flush } => {
let mut c = ctx.open().await?;
if flush {
let ev = c.flush_outbox().await?;
print_events(&ctx, &ev)?;
}
let pending = c.pending_sends();
if pending.is_empty() {
println!("outbox empty");
}
for p in pending {
let what = if p.message_id.is_empty() {
"handshake"
} else {
"message"
};
println!(
"{}\t{what}\taccepted by {} server(s)\t{} attempt(s)\tnext at {}",
p.contact, p.accepted, p.attempts, p.next_attempt
);
}
}
Cmd::History { contact } => {
let c = ctx.open().await?;
for h in c.history(&contact)? {
@@ -494,6 +522,15 @@ fn safe_name(name: &str) -> String {
}
}
fn print_sent(contact: &str, file: Option<&Path>, delivered_to: usize) {
let what = file.map(|f| format!("{} ", f.display())).unwrap_or_default();
if delivered_to == 0 {
println!("queued {what}for {contact} (no server reachable, will retry)");
} else {
println!("sent {what}to {contact} ({delivered_to} server(s))");
}
}
fn print_events(ctx: &Ctx, events: &[Event]) -> Result<()> {
for e in events {
match e {
@@ -508,6 +545,7 @@ fn print_events(ctx: &Ctx, events: &[Event]) -> Result<()> {
}
Event::InvitationAccepted { contact } => println!("invitation accepted by {contact}, confirmation sent"),
Event::ContactActivated { contact } => println!("contact {contact} is active"),
Event::SendFailed { contact, .. } => println!("a message to {contact} could not be delivered (expired)"),
}
}
Ok(())