MemoServ: add CANCEL, CHECK, and INFO
All checks were successful
CI / check (push) Successful in 3m49s
All checks were successful
CI / check (push) Successful in 3m49s
CANCEL recalls the sender's most recent unread memo to a target (one the recipient already read can't be recalled); CHECK reports whether the last memo you sent someone has been read; INFO summarises your mailbox. Adds memo_cancel/memo_check store methods and shares MAX_MEMOS from the module root instead of duplicating it in send.rs.
This commit is contained in:
parent
a26ee722d1
commit
98ecbca414
9 changed files with 118 additions and 2 deletions
|
|
@ -591,6 +591,28 @@ impl Db {
|
|||
true
|
||||
}
|
||||
|
||||
/// Recall the most recent UNREAD memo `sender` left for `account`. Returns
|
||||
/// whether one was cancelled — a memo the recipient already read can't be recalled.
|
||||
pub fn memo_cancel(&mut self, account: &str, sender: &str) -> bool {
|
||||
let sender_lc = sender.to_ascii_lowercase();
|
||||
let idx = self.accounts.get(&key(account)).and_then(|a| {
|
||||
a.memos.iter().enumerate().rev().find(|(_, m)| !m.read && m.from.to_ascii_lowercase() == sender_lc).map(|(i, _)| i)
|
||||
});
|
||||
match idx {
|
||||
Some(i) => self.memo_del(account, i),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The read-status and timestamp of the most recent memo `sender` left for
|
||||
/// `account`, or None if they have none in that mailbox.
|
||||
pub fn memo_check(&self, account: &str, sender: &str) -> Option<(bool, u64)> {
|
||||
let sender_lc = sender.to_ascii_lowercase();
|
||||
self.accounts.get(&key(account)).and_then(|a| {
|
||||
a.memos.iter().rev().find(|m| m.from.to_ascii_lowercase() == sender_lc).map(|m| (m.read, m.ts))
|
||||
})
|
||||
}
|
||||
|
||||
/// How many unread memos an account has.
|
||||
pub fn unread_memos(&self, account: &str) -> usize {
|
||||
self.accounts.get(&key(account)).map_or(0, |a| a.memos.iter().filter(|m| !m.read).count())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue