group config files refactored to groups.d and subfolders, WIP common config file

This commit is contained in:
2021-10-05 00:44:39 +02:00
parent 3a4f0ef153
commit 7ea6225ae9
5 changed files with 509 additions and 252 deletions
+14 -25
View File
@@ -15,7 +15,7 @@ use handle_mention::ProcessMention;
use crate::error::GroupError;
use crate::store::ConfigStore;
use crate::store::data::GroupConfig;
use crate::store::data::{CommonConfig, GroupConfig};
use crate::utils::{LogError, normalize_acct, VisExt};
use crate::command::StatusCommand;
use elefren::entities::account::Account;
@@ -25,25 +25,22 @@ mod handle_mention;
/// This is one group's config store capable of persistence
#[derive(Debug)]
pub struct GroupHandle {
pub(crate) group_account: Account,
pub(crate) client: FediClient,
pub(crate) config: GroupConfig,
pub(crate) store: Arc<ConfigStore>,
pub group_account: Account,
pub client: FediClient,
pub config: GroupConfig,
pub common_config: Arc<CommonConfig>,
}
// TODO move other options to common_config!
// const DELAY_BEFORE_ACTION: Duration = Duration::from_millis(250);
const DELAY_REOPEN_STREAM: Duration = Duration::from_millis(500);
const MAX_CATCHUP_NOTIFS: usize = 30;
// also statuses
const MAX_CATCHUP_STATUSES: usize = 50;
// higher because we can expect a lot of non-hashtag statuses here
const PERIODIC_SAVE: Duration = Duration::from_secs(60);
const SOCKET_ALIVE_TIMEOUT: Duration = Duration::from_secs(30);
const SOCKET_RETIRE_TIME: Duration = Duration::from_secs(120);
const PING_INTERVAL: Duration = Duration::from_secs(15); // must be < periodic save!
macro_rules! grp_debug {
($self:ident, $f:expr) => {
::log::debug!(concat!("(@{}) ", $f), $self.config.get_acct());
@@ -94,16 +91,12 @@ macro_rules! grp_error {
impl GroupHandle {
pub async fn save(&mut self) -> Result<(), GroupError> {
grp_debug!(self, "Saving group config & status");
self.store.set_group_config(self.config.clone()).await?;
grp_trace!(self, "Saved");
self.config.clear_dirty_status();
self.config.save(false).await?;
Ok(())
}
pub async fn save_if_needed(&mut self) -> Result<(), GroupError> {
if self.config.is_dirty() {
self.save().await?;
}
self.config.save_if_needed(false).await?;
Ok(())
}
@@ -361,13 +354,9 @@ impl GroupHandle {
account: s.account.clone(),
status: Some(s)
}).await;
} else {
if !private {
grp_debug!(self, "Detected mention status, handle as notif");
} else {
grp_debug!(self, "mention in private without commands, discard, this is nothing");
return Ok(());
}
} else if private {
grp_debug!(self, "mention in private without commands, discard, this is nothing");
return Ok(());
}
}
}
@@ -433,7 +422,7 @@ impl GroupHandle {
grp_debug!(self, "Inspecting notif {}", NotificationDisplay(&n));
notifs_to_handle.push(n);
num += 1;
if num > MAX_CATCHUP_NOTIFS {
if num > self.common_config.max_catchup_notifs {
grp_warn!(self, "Too many notifs missed to catch up!");
break;
}
@@ -486,7 +475,7 @@ impl GroupHandle {
statuses_to_handle.push(s);
num += 1;
if num > MAX_CATCHUP_STATUSES {
if num > self.common_config.max_catchup_statuses {
grp_warn!(self, "Too many statuses missed to catch up!");
break;
}