MemoServ: add RSEND read receipts
Some checks failed
CI / check (push) Has been cancelled

This commit is contained in:
Jean Chevronnet 2026-07-16 00:43:01 +00:00
parent 2850620be1
commit d819b2c75f
No known key found for this signature in database
11 changed files with 80 additions and 22 deletions

View file

@ -34,6 +34,7 @@ pub(crate) const MAX_MEMOS: usize = 30;
const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "SEND", summary: "leave a memo for an account", detail: "Syntax: \x02SEND <nick> <text>\x02\nLeaves a memo on a registered account's mailbox." },
HelpEntry { cmd: "RSEND", summary: "leave a memo and get a read receipt", detail: "Syntax: \x02RSEND <nick> <text>\x02\nLike SEND, but memos you back when the recipient reads it." },
HelpEntry { cmd: "LIST", summary: "list your memos", detail: "Syntax: \x02LIST\x02\nLists the memos in your mailbox." },
HelpEntry { cmd: "READ", summary: "read a memo", detail: "Syntax: \x02READ <num>|NEW|ALL\x02\nReads a memo by number, your unread ones, or all of them." },
HelpEntry { cmd: "DEL", summary: "delete a memo", detail: "Syntax: \x02DEL <num>|ALL\x02\nDeletes a memo by number, or your whole mailbox." },
@ -77,7 +78,8 @@ impl Service for MemoServ {
return;
};
match cmd.as_deref() {
Some("SEND") => send::handle(me, from, account, args, ctx, db),
Some("SEND") => send::handle(me, from, account, args, ctx, db, false),
Some("RSEND") => send::handle(me, from, account, args, ctx, db, true),
Some("LIST") => list::handle(me, from, account, ctx, db),
Some("READ") => read::handle(me, from, account, args, ctx, db),
Some("DEL") | Some("DELETE") => del::handle(me, from, account, args, ctx, db),

View file

@ -19,6 +19,7 @@ pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut S
for i in targets {
if let Some(m) = db.memo_read(account, i) {
show(me, from, i, &m, ctx);
send_receipt(account, &m, db);
}
}
}
@ -28,7 +29,10 @@ pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut S
return;
};
match db.memo_read(account, n - 1) {
Some(m) => show(me, from, n - 1, &m, ctx),
Some(m) => {
show(me, from, n - 1, &m, ctx);
send_receipt(account, &m, db);
}
None => ctx.notice(me, from.uid, format!("You have no memo #\x02{n}\x02.")),
}
}
@ -40,3 +44,12 @@ fn show(me: &str, from: &Sender, index: usize, m: &MemoView, ctx: &mut ServiceCt
ctx.notice(me, from.uid, format!("Memo #\x02{}\x02 from \x02{}\x02 ({}):", index + 1, m.from, human_time(m.ts)));
ctx.notice(me, from.uid, format!(" {}", m.text));
}
// If this was an unread RSEND memo, memo the sender that it's now been read.
// `m.read` is the pre-read state, so we only fire once, on first read.
fn send_receipt(reader: &str, m: &MemoView, db: &mut dyn Store) {
if m.receipt && !m.read {
let text = format!("{reader} has read the memo you sent them of {}.", human_time(m.ts));
let _ = db.memo_send(&m.from, "MemoServ", &text, false);
}
}

View file

@ -2,10 +2,12 @@ use echo_api::{Sender, ServiceCtx, Store};
use super::MAX_MEMOS;
// SEND <nick> <text>: leave a memo on a registered account's mailbox.
pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
// SEND/RSEND <nick> <text>: leave a memo on a registered account's mailbox.
// With `receipt`, the sender is told when the recipient reads it (RSEND).
pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store, receipt: bool) {
let cmd = if receipt { "RSEND" } else { "SEND" };
if args.len() < 3 {
ctx.notice(me, from.uid, "Syntax: SEND <nick> <text>");
ctx.notice(me, from.uid, format!("Syntax: {cmd} <nick> <text>"));
return;
}
let target = args[1];
@ -25,7 +27,7 @@ pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut S
ctx.notice(me, from.uid, format!("Memo sent to \x02{target}\x02."));
return;
}
match db.memo_send(&dest, account, &text) {
match db.memo_send(&dest, account, &text, receipt) {
Ok(()) => ctx.notice(me, from.uid, format!("Memo sent to \x02{target}\x02.")),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}

View file

@ -16,7 +16,7 @@ pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut S
let names: Vec<String> = db.accounts_matching("*").into_iter().map(|a| a.name).collect();
let mut sent = 0usize;
for name in &names {
if db.memo_send(name, account, &text).is_ok() {
if db.memo_send(name, account, &text, false).is_ok() {
sent += 1;
}
}