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:
parent
ccbbb91fda
commit
b5e08c33cf
13 changed files with 167 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1171,6 +1171,7 @@ fn audit_summary(event: &db::Event) -> Option<String> {
|
|||
// Private, self-service, or cosmetic — not surfaced.
|
||||
AjoinAdded { .. } | AjoinRemoved { .. } | AccountGreetSet { .. } | VhostRequested { .. }
|
||||
| VhostRequestCleared { .. } | MemoSent { .. } | MemoRead { .. } | MemoDeleted { .. }
|
||||
| MemoIgnoreAdd { .. } | MemoIgnoreDel { .. }
|
||||
| ChannelMlock { .. } | ChannelDescSet { .. } | ChannelEntryMsgSet { .. } | ChannelSettingsSet { .. }
|
||||
| ChannelKickerSet { .. } | ChannelBadwordsSet { .. } | ChannelTriggersSet { .. }
|
||||
| ChannelTopicSet { .. } | AccountSeen { .. } | ChannelUsed { .. }
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@
|
|||
// An earlier claim from another node wins and takes the name over.
|
||||
let winner = db::Account {
|
||||
name: "alice".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::for_test("peer", 0, 1, db::Event::AccountRegistered(Box::new(winner)));
|
||||
e.gossip_ingest(entry).unwrap();
|
||||
|
|
@ -837,6 +837,44 @@
|
|||
assert_eq!(e.db.unread_memos("bob"), 1);
|
||||
}
|
||||
|
||||
// MemoServ IGNORE: a memo from an ignored sender is silently dropped, and the
|
||||
// sender is still told it was sent (so the ignore isn't revealed).
|
||||
#[test]
|
||||
fn memoserv_ignore_drops_memo() {
|
||||
use echo_memoserv::MemoServ;
|
||||
use echo_nickserv::NickServ;
|
||||
let path = std::env::temp_dir().join("echo-msignore.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut db = Db::open(&path, "42S");
|
||||
db.scram_iterations = 4096;
|
||||
db.register("alice", "pw", None).unwrap();
|
||||
db.register("bob", "pw", None).unwrap();
|
||||
let mut e = Engine::new(
|
||||
vec![
|
||||
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
|
||||
Box::new(MemoServ { uid: "42SAAAAAE".into() }),
|
||||
],
|
||||
db,
|
||||
);
|
||||
let ms = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAE".into(), text: t.into() });
|
||||
let notice = |out: &[NetAction], n: &str| out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains(n)));
|
||||
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "alice".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||
e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() });
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAC".into(), nick: "bob".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||
e.handle(NetEvent::Privmsg { from: "000AAAAAC".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() });
|
||||
|
||||
// alice ignores bob.
|
||||
assert!(notice(&ms(&mut e, "000AAAAAB", "IGNORE ADD bob"), "ignoring"), "ignore added");
|
||||
// bob's memo is accepted-looking but dropped.
|
||||
assert!(notice(&ms(&mut e, "000AAAAAC", "SEND alice hey"), "Memo sent"), "sender told it was sent");
|
||||
assert_eq!(e.db.unread_memos("alice"), 0, "the memo was dropped");
|
||||
// After un-ignoring, delivery resumes.
|
||||
ms(&mut e, "000AAAAAB", "IGNORE DEL bob");
|
||||
ms(&mut e, "000AAAAAC", "SEND alice hey again");
|
||||
assert_eq!(e.db.unread_memos("alice"), 1, "delivered once no longer ignored");
|
||||
}
|
||||
|
||||
// ChanServ AKICK CLEAR empties the auto-kick list.
|
||||
#[test]
|
||||
fn chanserv_akick_clear() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue