diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 1046bd147..ede1ce88c 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -21,6 +21,14 @@ pub struct Settings { pub(crate) actor_name_max_length: Option, } +impl Settings { + pub(crate) fn actor_name_max_length(&self) -> usize { + self + .actor_name_max_length + .unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap()) + } +} + #[derive(Debug, Deserialize, Clone)] pub struct CaptchaConfig { pub enabled: bool, diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs index d063359ba..d6e1f25d4 100644 --- a/crates/utils/src/utils.rs +++ b/crates/utils/src/utils.rs @@ -116,21 +116,16 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec { } pub fn is_valid_actor_name(name: &str) -> bool { - let max_length = Settings::get() - .actor_name_max_length - .unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap()); - name.chars().count() <= max_length && VALID_ACTOR_NAME_REGEX.is_match(name) + name.chars().count() <= Settings::get().actor_name_max_length() + && VALID_ACTOR_NAME_REGEX.is_match(name) } // Can't do a regex here, reverse lookarounds not supported pub fn is_valid_display_name(name: &str) -> bool { - let max_length = Settings::get() - .actor_name_max_length - .unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap()); !name.starts_with('@') && !name.starts_with('\u{200b}') && name.chars().count() >= 3 - && name.chars().count() <= max_length + && name.chars().count() <= Settings::get().actor_name_max_length() } pub fn is_valid_matrix_id(matrix_id: &str) -> bool {