add: followers/following ui

This commit is contained in:
trisua 2025-03-31 22:35:11 -04:00
parent 17564ede49
commit e183a01887
13 changed files with 469 additions and 86 deletions

View file

@ -137,6 +137,9 @@ pub struct Config {
/// version built with the server binary.
#[serde(default = "default_no_track")]
pub no_track: Vec<String>,
/// A list of usernames which cannot be used.
#[serde(default = "default_banned_usernames")]
pub banned_usernames: Vec<String>,
}
fn default_name() -> String {
@ -170,6 +173,19 @@ fn default_no_track() -> Vec<String> {
Vec::new()
}
fn default_banned_usernames() -> Vec<String> {
vec![
"admin".to_string(),
"owner".to_string(),
"moderator".to_string(),
"api".to_string(),
"communities".to_string(),
"notifs".to_string(),
"notification".to_string(),
"post".to_string(),
]
}
impl Default for Config {
fn default() -> Self {
Self {
@ -181,6 +197,7 @@ impl Default for Config {
security: default_security(),
dirs: default_dirs(),
no_track: default_no_track(),
banned_usernames: default_banned_usernames(),
}
}
}

View file

@ -84,6 +84,10 @@ impl DataManager {
return Err(Error::DataTooShort("password".to_string()));
}
if self.0.banned_usernames.contains(&data.username) {
return Err(Error::MiscError("This username cannot be used".to_string()));
}
// make sure username isn't taken
if self.get_user_by_username(&data.username).await.is_ok() {
return Err(Error::UsernameInUse);

View file

@ -145,6 +145,36 @@ impl DataManager {
Ok(res.unwrap())
}
/// Complete a vector of just userfollows with their receiver as well.
pub async fn fill_userfollows_with_receiver(
&self,
userfollows: Vec<UserFollow>,
) -> Result<Vec<(UserFollow, User)>> {
let mut out: Vec<(UserFollow, User)> = Vec::new();
for userfollow in userfollows {
let receiver = userfollow.receiver.clone();
out.push((userfollow, self.get_user_by_id(receiver).await?));
}
Ok(out)
}
/// Complete a vector of just userfollows with their initiator as well.
pub async fn fill_userfollows_with_initiator(
&self,
userfollows: Vec<UserFollow>,
) -> Result<Vec<(UserFollow, User)>> {
let mut out: Vec<(UserFollow, User)> = Vec::new();
for userfollow in userfollows {
let initiator = userfollow.initiator.clone();
out.push((userfollow, self.get_user_by_id(initiator).await?));
}
Ok(out)
}
/// Create a new user follow in the database.
///
/// # Arguments