|
|
|
@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; |
|
|
|
|
use elefren::AppData; |
|
|
|
|
|
|
|
|
|
use crate::error::GroupError; |
|
|
|
|
use crate::store::{CommonConfig, DEFAULT_LOCALE_NAME}; |
|
|
|
|
use crate::store::{DEFAULT_LOCALE_NAME, CommonConfig}; |
|
|
|
|
use crate::tr::TranslationTable; |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)] |
|
|
|
@ -259,11 +259,7 @@ impl GroupConfig { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// (re)init using new authorization
|
|
|
|
|
pub(crate) async fn initialize_by_appdata( |
|
|
|
|
acct: String, |
|
|
|
|
appdata: AppData, |
|
|
|
|
group_dir: PathBuf, |
|
|
|
|
) -> Result<(), GroupError> { |
|
|
|
|
pub(crate) async fn initialize_by_appdata(acct: String, appdata: AppData, group_dir: PathBuf) -> Result<(), GroupError> { |
|
|
|
|
if !group_dir.is_dir() { |
|
|
|
|
debug!("Creating group directory"); |
|
|
|
|
tokio::fs::create_dir_all(&group_dir).await?; |
|
|
|
@ -310,12 +306,7 @@ impl GroupConfig { |
|
|
|
|
/* state */ |
|
|
|
|
let state = load_or_create_state_file(state_path).await?; |
|
|
|
|
|
|
|
|
|
let g = GroupConfig { |
|
|
|
|
config, |
|
|
|
|
control, |
|
|
|
|
state, |
|
|
|
|
_group_tr: TranslationTable::new(), |
|
|
|
|
}; |
|
|
|
|
let g = GroupConfig { config, control, state, _group_tr: TranslationTable::new() }; |
|
|
|
|
g.warn_of_bad_config(); |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
@ -347,12 +338,7 @@ impl GroupConfig { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let g = GroupConfig { |
|
|
|
|
config, |
|
|
|
|
control, |
|
|
|
|
state, |
|
|
|
|
_group_tr: tr, |
|
|
|
|
}; |
|
|
|
|
let g = GroupConfig { config, control, state, _group_tr: tr }; |
|
|
|
|
g.warn_of_bad_config(); |
|
|
|
|
Ok(g) |
|
|
|
|
} |
|
|
|
@ -472,7 +458,7 @@ impl GroupConfig { |
|
|
|
|
/// Check if the user's server is banned
|
|
|
|
|
fn is_users_server_banned(&self, acct: &str) -> bool { |
|
|
|
|
let server = acct_to_server(acct); |
|
|
|
|
self.is_server_banned(&server) |
|
|
|
|
self.is_server_banned(server) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub(crate) fn can_write(&self, acct: &str) -> bool { |
|
|
|
@ -588,8 +574,8 @@ impl GroupConfig { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn acct_to_server(acct: &str) -> String { |
|
|
|
|
crate::utils::acct_to_server(acct).unwrap_or_default() |
|
|
|
|
fn acct_to_server(acct: &str) -> &str { |
|
|
|
|
acct.split('@').nth(1).unwrap_or_default() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
@ -602,15 +588,15 @@ mod tests { |
|
|
|
|
config: Default::default(), |
|
|
|
|
control: Default::default(), |
|
|
|
|
state: Default::default(), |
|
|
|
|
_group_tr: Default::default(), |
|
|
|
|
_group_tr: Default::default() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_acct_to_server() { |
|
|
|
|
assert_eq!("pikachu.rocks".to_string(), acct_to_server("raichu@pikachu.rocks")); |
|
|
|
|
assert_eq!("pikachu.rocks".to_string(), acct_to_server("m@pikachu.rocks")); |
|
|
|
|
assert_eq!("".to_string(), acct_to_server("what")); |
|
|
|
|
assert_eq!("pikachu.rocks", acct_to_server("raichu@pikachu.rocks")); |
|
|
|
|
assert_eq!("pikachu.rocks", acct_to_server("m@pikachu.rocks")); |
|
|
|
|
assert_eq!("", acct_to_server("what")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|