add helper method for setting actor_name_max_length

This commit is contained in:
Felix Ableitner 2021-07-22 22:04:45 +02:00
parent faf7623574
commit 22ce499096
2 changed files with 11 additions and 8 deletions

View file

@ -21,6 +21,14 @@ pub struct Settings {
pub(crate) actor_name_max_length: Option<usize>,
}
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,

View file

@ -116,21 +116,16 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec<MentionData> {
}
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 {