MemoServ: add SET NOTIFY and SET LIMIT
All checks were successful
CI / check (push) Successful in 3m35s
All checks were successful
CI / check (push) Successful in 3m35s
SET NOTIFY {ON|OFF} controls whether you're told about new memos on login;
SET LIMIT <n>|NONE sets your mailbox cap (honoured on SEND, NONE = the
network default). New memo_notify/memo_limit account fields + one
MemoPrefsSet event.
This commit is contained in:
parent
125b8c7701
commit
2c282d036f
14 changed files with 152 additions and 8 deletions
|
|
@ -20,7 +20,7 @@ impl Db {
|
|||
verified,
|
||||
ajoin: Vec::new(),
|
||||
suspension: None,
|
||||
memos: Vec::new(), memo_ignore: Vec::new(),
|
||||
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
|
||||
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(), memo_ignore: Vec::new(),
|
||||
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
|
||||
greet: String::new(),
|
||||
vhost: None,
|
||||
vhost_request: None,
|
||||
|
|
|
|||
|
|
@ -688,6 +688,36 @@ impl Db {
|
|||
self.accounts.get(&key(account)).is_some_and(|a| a.memo_ignore.iter().any(|t| t.eq_ignore_ascii_case(sender)))
|
||||
}
|
||||
|
||||
/// Set whether `account` is notified about new memos on login.
|
||||
pub fn set_memo_notify(&mut self, account: &str, on: bool) -> bool {
|
||||
let k = key(account);
|
||||
let Some(a) = self.accounts.get(&k) else { return false };
|
||||
let limit = a.memo_limit;
|
||||
let _ = self.log.append(Event::MemoPrefsSet { account: account.to_string(), notify: on, limit });
|
||||
self.accounts.get_mut(&k).unwrap().memo_notify = on;
|
||||
true
|
||||
}
|
||||
|
||||
/// Set `account`'s mailbox cap (None = the network default).
|
||||
pub fn set_memo_limit(&mut self, account: &str, limit: Option<u32>) -> bool {
|
||||
let k = key(account);
|
||||
let Some(a) = self.accounts.get(&k) else { return false };
|
||||
let notify = a.memo_notify;
|
||||
let _ = self.log.append(Event::MemoPrefsSet { account: account.to_string(), notify, limit });
|
||||
self.accounts.get_mut(&k).unwrap().memo_limit = limit;
|
||||
true
|
||||
}
|
||||
|
||||
/// Whether `account` wants new-memo notifications (default on / unknown = on).
|
||||
pub fn memo_notify_on(&self, account: &str) -> bool {
|
||||
self.accounts.get(&key(account)).is_none_or(|a| a.memo_notify)
|
||||
}
|
||||
|
||||
/// `account`'s configured mailbox cap, if any.
|
||||
pub fn memo_limit_of(&self, account: &str) -> Option<u32> {
|
||||
self.accounts.get(&key(account)).and_then(|a| a.memo_limit)
|
||||
}
|
||||
|
||||
/// 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())
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ pub enum Event {
|
|||
MemoDeleted { account: String, index: usize },
|
||||
MemoIgnoreAdd { account: String, target: String },
|
||||
MemoIgnoreDel { account: String, target: String },
|
||||
MemoPrefsSet { account: String, notify: bool, limit: Option<u32> },
|
||||
NickGrouped { nick: String, account: String },
|
||||
NickUngrouped { nick: String },
|
||||
ChannelRegistered { name: String, founder: String, ts: u64 },
|
||||
|
|
@ -160,6 +161,7 @@ impl Event {
|
|||
| Event::MemoDeleted { .. }
|
||||
| Event::MemoIgnoreAdd { .. }
|
||||
| Event::MemoIgnoreDel { .. }
|
||||
| Event::MemoPrefsSet { .. }
|
||||
| Event::NickGrouped { .. }
|
||||
| Event::NickUngrouped { .. }
|
||||
| Event::AccountSeen { .. }
|
||||
|
|
@ -354,6 +356,12 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
|
|||
a.memo_ignore.retain(|t| !t.eq_ignore_ascii_case(&target));
|
||||
}
|
||||
}
|
||||
Event::MemoPrefsSet { account, notify, limit } => {
|
||||
if let Some(a) = accounts.get_mut(&key(&account)) {
|
||||
a.memo_notify = notify;
|
||||
a.memo_limit = limit;
|
||||
}
|
||||
}
|
||||
Event::NickGrouped { nick, account } => {
|
||||
grouped.insert(key(&nick), account);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,12 @@ pub struct Account {
|
|||
// Accounts this user won't receive memos from (MemoServ IGNORE).
|
||||
#[serde(default)]
|
||||
pub memo_ignore: Vec<String>,
|
||||
// MemoServ SET NOTIFY: be told about new memos on login (default on).
|
||||
#[serde(default = "verified_default")]
|
||||
pub memo_notify: bool,
|
||||
// MemoServ SET LIMIT: mailbox cap (None = the network default).
|
||||
#[serde(default)]
|
||||
pub memo_limit: Option<u32>,
|
||||
// Personal greet a bot shows when this account joins a greet-enabled channel.
|
||||
#[serde(default)]
|
||||
pub greet: String,
|
||||
|
|
|
|||
|
|
@ -468,6 +468,18 @@ impl Store for Db {
|
|||
fn memo_is_ignored(&self, account: &str, sender: &str) -> bool {
|
||||
Db::memo_is_ignored(self, account, sender)
|
||||
}
|
||||
fn set_memo_notify(&mut self, account: &str, on: bool) -> bool {
|
||||
Db::set_memo_notify(self, account, on)
|
||||
}
|
||||
fn set_memo_limit(&mut self, account: &str, limit: Option<u32>) -> bool {
|
||||
Db::set_memo_limit(self, account, limit)
|
||||
}
|
||||
fn memo_notify_on(&self, account: &str) -> bool {
|
||||
Db::memo_notify_on(self, account)
|
||||
}
|
||||
fn memo_limit_of(&self, account: &str) -> Option<u32> {
|
||||
Db::memo_limit_of(self, account)
|
||||
}
|
||||
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![], memo_ignore: 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![], memo_notify: true, memo_limit: None, 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![], memo_ignore: 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![], memo_notify: true, memo_limit: None, 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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue