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

@ -587,28 +587,28 @@ impl Db {
}
/// Append a memo to an account's mailbox.
pub fn memo_send(&mut self, account: &str, from: &str, text: &str) -> Result<(), RegError> {
pub fn memo_send(&mut self, account: &str, from: &str, text: &str, receipt: bool) -> Result<(), RegError> {
let k = key(account);
if !self.accounts.contains_key(&k) {
return Err(RegError::Internal);
}
let ts = now();
self.log.append(Event::MemoSent { account: account.to_string(), from: from.to_string(), text: text.to_string(), ts }).map_err(|_| RegError::Internal)?;
self.accounts.get_mut(&k).unwrap().memos.push(Memo { from: from.to_string(), text: text.to_string(), ts, read: false });
self.log.append(Event::MemoSent { account: account.to_string(), from: from.to_string(), text: text.to_string(), ts, receipt }).map_err(|_| RegError::Internal)?;
self.accounts.get_mut(&k).unwrap().memos.push(Memo { from: from.to_string(), text: text.to_string(), ts, read: false, receipt });
Ok(())
}
/// An account's memos, oldest first.
pub fn memo_list(&self, account: &str) -> Vec<MemoView> {
self.accounts.get(&key(account)).map_or(Vec::new(), |a| {
a.memos.iter().map(|m| MemoView { from: m.from.clone(), text: m.text.clone(), ts: m.ts, read: m.read }).collect()
a.memos.iter().map(|m| MemoView { from: m.from.clone(), text: m.text.clone(), ts: m.ts, read: m.read, receipt: m.receipt }).collect()
})
}
/// Read one memo by index (marks it read), returning its contents.
pub fn memo_read(&mut self, account: &str, index: usize) -> Option<MemoView> {
let k = key(account);
let view = self.accounts.get(&k).and_then(|a| a.memos.get(index)).map(|m| MemoView { from: m.from.clone(), text: m.text.clone(), ts: m.ts, read: m.read })?;
let view = self.accounts.get(&k).and_then(|a| a.memos.get(index)).map(|m| MemoView { from: m.from.clone(), text: m.text.clone(), ts: m.ts, read: m.read, receipt: m.receipt })?;
if !view.read {
let _ = self.log.append(Event::MemoRead { account: account.to_string(), index });
if let Some(m) = self.accounts.get_mut(&k).and_then(|a| a.memos.get_mut(index)) {

View file

@ -26,7 +26,7 @@ pub enum Event {
VhostRequestCleared { account: String },
AccountSuspended { account: String, by: String, reason: String, ts: u64, expires: Option<u64> },
AccountUnsuspended { account: String },
MemoSent { account: String, from: String, text: String, ts: u64 },
MemoSent { account: String, from: String, text: String, ts: u64, #[serde(default)] receipt: bool },
MemoRead { account: String, index: usize },
MemoDeleted { account: String, index: usize },
MemoIgnoreAdd { account: String, target: String },
@ -327,9 +327,9 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
a.suspension = None;
}
}
Event::MemoSent { account, from, text, ts } => {
Event::MemoSent { account, from, text, ts, receipt } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.memos.push(Memo { from, text, ts, read: false });
a.memos.push(Memo { from, text, ts, read: false, receipt });
}
}
Event::MemoRead { account, index } => {

View file

@ -313,6 +313,9 @@ pub struct Memo {
pub ts: u64,
#[serde(default)]
pub read: bool,
// The sender asked to be told when it's read (MemoServ RSEND).
#[serde(default)]
pub receipt: bool,
}
// A service bot: a pseudo-client BotServ can assign to sit in channels.

View file

@ -441,8 +441,8 @@ impl Store for Db {
fn unassign_bot(&mut self, channel: &str) -> Result<bool, ChanError> {
Db::unassign_bot(self, channel)
}
fn memo_send(&mut self, account: &str, from: &str, text: &str) -> Result<(), RegError> {
Db::memo_send(self, account, from, text)
fn memo_send(&mut self, account: &str, from: &str, text: &str, receipt: bool) -> Result<(), RegError> {
Db::memo_send(self, account, from, text, receipt)
}
fn memo_list(&self, account: &str) -> Vec<MemoView> {
Db::memo_list(self, account)

View file

@ -219,8 +219,8 @@
db.scram_iterations = 4096;
db.register("alice", "password1", None).unwrap();
assert_eq!(db.unread_memos("alice"), 0);
db.memo_send("alice", "bob", "hello there").unwrap();
db.memo_send("alice", "carol", "second").unwrap();
db.memo_send("alice", "bob", "hello there", false).unwrap();
db.memo_send("alice", "carol", "second", false).unwrap();
assert_eq!(db.unread_memos("alice"), 2);
let m = db.memo_read("alice", 0).unwrap();
assert_eq!(m.from, "bob");
@ -240,8 +240,8 @@
let mut db = Db::open(tmp("memo-cc"), "N1");
db.scram_iterations = 4096;
db.register("alice", "pw", None).unwrap();
db.memo_send("alice", "bob", "hi").unwrap();
db.memo_send("alice", "bob", "you there?").unwrap();
db.memo_send("alice", "bob", "hi", false).unwrap();
db.memo_send("alice", "bob", "you there?", false).unwrap();
assert_eq!(db.memo_check("alice", "bob").map(|(read, _)| read), Some(false), "unread so far");
assert!(db.memo_cancel("alice", "bob"), "recalls the most recent unread");