acks
This commit is contained in:
1 parent
10af480218
commit
47b73e6935
11 files changed
+470
-28
No files matched your search
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use meow_client::{Content, Event, MeowClient, DEFAULT_INVITATION_TTL};
|
||||
use meow_client::{Content, Event, MeowClient, ReceiptKind, Status, DEFAULT_INVITATION_TTL};
|
||||
use meow_crypto::password::KdfParams;
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -73,7 +73,7 @@ enum Cmd {
|
||||
Longpoll {
|
||||
#[arg(short, long, default_value_t = 30)]
|
||||
wait: u64,
|
||||
/// Exit after the first batch of events (or the first timeout).
|
||||
/// Exit after the first batch of events other than receipts (or the first timeout).
|
||||
#[arg(short, long)]
|
||||
exit: bool,
|
||||
},
|
||||
@@ -83,6 +83,8 @@ enum Cmd {
|
||||
#[arg(long)]
|
||||
flush: bool,
|
||||
},
|
||||
/// Mark a conversation as read (sends a read receipt unless disabled).
|
||||
Read { contact: String },
|
||||
/// Show the conversation with a contact.
|
||||
History { contact: String },
|
||||
}
|
||||
@@ -97,6 +99,15 @@ enum IdentityCmd {
|
||||
},
|
||||
/// Show the identity summary.
|
||||
Show,
|
||||
/// Show or change receipt preferences.
|
||||
Receipts {
|
||||
/// Tell contacts when their messages reach this device.
|
||||
#[arg(long)]
|
||||
delivered: Option<bool>,
|
||||
/// Tell contacts when their messages are read.
|
||||
#[arg(long)]
|
||||
read: Option<bool>,
|
||||
},
|
||||
/// Change the main password.
|
||||
Password {
|
||||
#[arg(long)]
|
||||
@@ -281,6 +292,17 @@ async fn run() -> Result<()> {
|
||||
println!("servers: {}", c.servers().len());
|
||||
println!("contacts: {}", c.contacts().len());
|
||||
}
|
||||
Cmd::Identity(IdentityCmd::Receipts { delivered, read }) => {
|
||||
let mut c = ctx.open().await?;
|
||||
let mut s = c.settings();
|
||||
if delivered.is_some() || read.is_some() {
|
||||
s.delivered_receipts = delivered.unwrap_or(s.delivered_receipts);
|
||||
s.read_receipts = read.unwrap_or(s.read_receipts);
|
||||
c.set_settings(s).await?;
|
||||
}
|
||||
println!("delivered receipts: {}", s.delivered_receipts);
|
||||
println!("read receipts: {}", s.read_receipts);
|
||||
}
|
||||
Cmd::Identity(IdentityCmd::Password { new_password }) => {
|
||||
ctx.open().await?.change_password(&new_password).await?;
|
||||
println!("password changed");
|
||||
@@ -398,7 +420,9 @@ async fn run() -> Result<()> {
|
||||
loop {
|
||||
let ev = c.sync(Duration::from_secs(wait)).await?;
|
||||
print_events(&ctx, &ev)?;
|
||||
if exit {
|
||||
// Receipts are background traffic: keep waiting for something else.
|
||||
let only_receipts = !ev.is_empty() && ev.iter().all(|e| matches!(e, Event::Receipt { .. }));
|
||||
if exit && !only_receipts {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -425,6 +449,10 @@ async fn run() -> Result<()> {
|
||||
);
|
||||
}
|
||||
}
|
||||
Cmd::Read { contact } => {
|
||||
let n = ctx.open().await?.mark_read(&contact).await?;
|
||||
println!("{n} message(s) marked as read");
|
||||
}
|
||||
Cmd::History { contact } => {
|
||||
let c = ctx.open().await?;
|
||||
for h in c.history(&contact)? {
|
||||
@@ -433,9 +461,19 @@ async fn run() -> Result<()> {
|
||||
} else {
|
||||
contact.clone()
|
||||
};
|
||||
let status = if h.outbound {
|
||||
match h.status {
|
||||
Status::Queued => " [queued]",
|
||||
Status::Sent => " [sent]",
|
||||
Status::Delivered => " [delivered]",
|
||||
Status::Read => " [read]",
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
match &h.content {
|
||||
Content::Text(t) => println!("[{who}] {t}"),
|
||||
Content::File { name, size } => println!("[{who}] <file {name}, {size} bytes>"),
|
||||
Content::Text(t) => println!("[{who}] {t}{status}"),
|
||||
Content::File { name, size } => println!("[{who}] <file {name}, {size} bytes>{status}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,6 +583,17 @@ 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::Receipt {
|
||||
contact,
|
||||
kind,
|
||||
message_ids,
|
||||
} => {
|
||||
let verb = match kind {
|
||||
ReceiptKind::Delivered => "received",
|
||||
ReceiptKind::Read => "read",
|
||||
};
|
||||
println!("{contact} {verb} {} message(s)", message_ids.len());
|
||||
}
|
||||
Event::SendFailed { contact, .. } => println!("a message to {contact} could not be delivered (expired)"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user