add nobot and optout/optin

This commit is contained in:
2021-08-30 20:03:03 +02:00
parent 37a9f323e6
commit 900132970d
7 changed files with 160 additions and 19 deletions
+18
View File
@@ -41,6 +41,8 @@ pub(crate) struct GroupConfig {
member_users: HashSet<String>,
/// List of users banned from posting to the group
banned_users: HashSet<String>,
/// Users who decided they don't want to be shared to the group (does not apply to members)
optout_users: HashSet<String>,
/// True if only members should be allowed to write
member_only: bool,
/// Banned domain names, e.g. kiwifarms.cc
@@ -69,6 +71,7 @@ impl Default for GroupConfig {
admin_users: Default::default(),
member_users: Default::default(),
banned_users: Default::default(),
optout_users: Default::default(),
member_only: false,
banned_servers: Default::default(),
last_notif_ts: 0,
@@ -147,6 +150,10 @@ impl GroupConfig {
&self.acct
}
pub(crate) fn is_optout(&self, acct: &str) -> bool {
self.optout_users.contains(acct)
}
pub(crate) fn is_admin(&self, acct: &str) -> bool {
self.admin_users.contains(acct)
}
@@ -212,6 +219,17 @@ impl GroupConfig {
Ok(())
}
pub(crate) fn set_optout(&mut self, acct: &str, optout: bool) {
let change = if optout {
self.optout_users.insert(acct.to_owned())
} else {
self.optout_users.remove(acct)
};
if change {
self.mark_dirty();
}
}
pub(crate) fn ban_user(&mut self, acct: &str, ban: bool) -> Result<(), GroupError> {
let mut change = false;
if ban {