MemoServ: add IGNORE
All checks were successful
CI / check (push) Successful in 3m34s

IGNORE ADD/DEL/LIST manages a per-account memo-ignore list; a memo from
an ignored account is silently dropped, and the sender is still told it
was sent so the ignore isn't revealed. New memo_ignore account field +
events, and a check in SEND.
This commit is contained in:
Jean Chevronnet 2026-07-16 00:10:34 +00:00
parent ccbbb91fda
commit b5e08c33cf
No known key found for this signature in database
13 changed files with 167 additions and 5 deletions

View file

@ -20,7 +20,7 @@ impl Db {
verified,
ajoin: Vec::new(),
suspension: None,
memos: Vec::new(),
memos: Vec::new(), memo_ignore: Vec::new(),
greet: String::new(),
vhost: None,
vhost_request: None,
@ -59,7 +59,7 @@ impl Db {
verified: true, // the external authority vouches for it
ajoin: Vec::new(),
suspension: None,
memos: Vec::new(),
memos: Vec::new(), memo_ignore: Vec::new(),
greet: String::new(),
vhost: None,
vhost_request: None,

View file

@ -654,6 +654,40 @@ impl Db {
})
}
/// Add `target` to `account`'s memo-ignore list. Returns whether it was new.
pub fn memo_ignore_add(&mut self, account: &str, target: &str) -> bool {
let k = key(account);
let Some(a) = self.accounts.get(&k) else { return false };
if a.memo_ignore.iter().any(|t| t.eq_ignore_ascii_case(target)) {
return false;
}
let _ = self.log.append(Event::MemoIgnoreAdd { account: account.to_string(), target: target.to_string() });
self.accounts.get_mut(&k).unwrap().memo_ignore.push(target.to_string());
true
}
/// Remove `target` from `account`'s memo-ignore list. Returns whether it existed.
pub fn memo_ignore_del(&mut self, account: &str, target: &str) -> bool {
let k = key(account);
let Some(a) = self.accounts.get(&k) else { return false };
if !a.memo_ignore.iter().any(|t| t.eq_ignore_ascii_case(target)) {
return false;
}
let _ = self.log.append(Event::MemoIgnoreDel { account: account.to_string(), target: target.to_string() });
self.accounts.get_mut(&k).unwrap().memo_ignore.retain(|t| !t.eq_ignore_ascii_case(target));
true
}
/// `account`'s memo-ignore list.
pub fn memo_ignores(&self, account: &str) -> Vec<String> {
self.accounts.get(&key(account)).map_or(Vec::new(), |a| a.memo_ignore.clone())
}
/// Whether `account` is ignoring memos from `sender`.
pub fn memo_is_ignored(&self, account: &str, sender: &str) -> bool {
self.accounts.get(&key(account)).is_some_and(|a| a.memo_ignore.iter().any(|t| t.eq_ignore_ascii_case(sender)))
}
/// 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())

View file

@ -29,6 +29,8 @@ pub enum Event {
MemoSent { account: String, from: String, text: String, ts: u64 },
MemoRead { account: String, index: usize },
MemoDeleted { account: String, index: usize },
MemoIgnoreAdd { account: String, target: String },
MemoIgnoreDel { account: String, target: String },
NickGrouped { nick: String, account: String },
NickUngrouped { nick: String },
ChannelRegistered { name: String, founder: String, ts: u64 },
@ -156,6 +158,8 @@ impl Event {
| Event::MemoSent { .. }
| Event::MemoRead { .. }
| Event::MemoDeleted { .. }
| Event::MemoIgnoreAdd { .. }
| Event::MemoIgnoreDel { .. }
| Event::NickGrouped { .. }
| Event::NickUngrouped { .. }
| Event::AccountSeen { .. }
@ -338,6 +342,18 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
}
}
}
Event::MemoIgnoreAdd { account, target } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
if !a.memo_ignore.iter().any(|t| t.eq_ignore_ascii_case(&target)) {
a.memo_ignore.push(target);
}
}
}
Event::MemoIgnoreDel { account, target } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.memo_ignore.retain(|t| !t.eq_ignore_ascii_case(&target));
}
}
Event::NickGrouped { nick, account } => {
grouped.insert(key(&nick), account);
}

View file

@ -79,6 +79,9 @@ pub struct Account {
// Memos left for this account (MemoServ), oldest first.
#[serde(default)]
pub memos: Vec<Memo>,
// Accounts this user won't receive memos from (MemoServ IGNORE).
#[serde(default)]
pub memo_ignore: Vec<String>,
// Personal greet a bot shows when this account joins a greet-enabled channel.
#[serde(default)]
pub greet: String,

View file

@ -456,6 +456,18 @@ impl Store for Db {
fn memo_cancel(&mut self, account: &str, sender: &str) -> bool {
Db::memo_cancel(self, account, sender)
}
fn memo_ignore_add(&mut self, account: &str, target: &str) -> bool {
Db::memo_ignore_add(self, account, target)
}
fn memo_ignore_del(&mut self, account: &str, target: &str) -> bool {
Db::memo_ignore_del(self, account, target)
}
fn memo_ignores(&self, account: &str) -> Vec<String> {
Db::memo_ignores(self, account)
}
fn memo_is_ignored(&self, account: &str, sender: &str) -> bool {
Db::memo_is_ignored(self, account, sender)
}
fn memo_check(&self, account: &str, sender: &str) -> Option<(bool, u64)> {
Db::memo_check(self, account, sender)
}

View file

@ -32,7 +32,7 @@
// which of the two competing registrations we're looking at.
let alice = |tag: &str, ts: u64, home: &str| Account {
name: "alice".into(), email: Some(tag.into()),
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
};
let converge = |first: &Account, second: &Account| {
let (mut acc, mut ch, mut gr, mut bo, mut hc, mut nd) = (HashMap::new(), HashMap::new(), HashMap::new(), HashMap::new(), HostConfig::default(), NetData::default());
@ -329,7 +329,7 @@
db.register("alice", "pw", None).unwrap();
let bob = Account {
name: "bob".into(), email: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
};
let entry = LogEntry { origin: "peer".into(), seq: 0, lamport: 1, event: Event::AccountRegistered(Box::new(bob)) };
db.ingest(entry).unwrap();