diff --git a/src/activitypub/actor.rs b/src/activitypub/actor.rs index 7829ece..6a602e3 100644 --- a/src/activitypub/actor.rs +++ b/src/activitypub/actor.rs @@ -92,6 +92,7 @@ impl Actor { .map(|prop| ExtraField { name: prop.name.clone(), value: prop.value.clone(), + value_source: None, }) .collect() }, diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index 0b139d5..b6d14af 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -11,11 +11,17 @@ use crate::models::profiles::types::{ }; use crate::utils::files::{FileError, save_validated_b64_file, get_file_url}; +#[derive(Serialize)] +pub struct AccountField { + pub name: String, + pub value: String, +} + /// https://docs.joinmastodon.org/entities/source/ #[derive(Serialize)] pub struct Source { pub note: Option, - pub fields: Vec, + pub fields: Vec, } /// https://docs.joinmastodon.org/entities/account/ @@ -29,7 +35,7 @@ pub struct Account { pub note: Option, pub avatar: Option, pub header: Option, - pub fields: Vec, + pub fields: Vec, pub followers_count: i32, pub following_count: i32, pub statuses_count: i32, @@ -45,12 +51,22 @@ impl Account { // Remote actor None } else { + let fields_sources = profile.extra_fields.clone() + .unpack().into_iter() + .map(|field| AccountField { + name: field.name, + value: field.value_source.unwrap_or(field.value), + }) + .collect(); let source = Source { note: profile.bio_source, - fields: profile.extra_fields.clone().unpack(), + fields: fields_sources, }; Some(source) }; + let fields = profile.extra_fields.unpack().into_iter() + .map(|field| AccountField { name: field.name, value: field.value }) + .collect(); Self { id: profile.id, username: profile.username, @@ -60,7 +76,7 @@ impl Account { note: profile.bio, avatar: avatar_url, header: header_url, - fields: profile.extra_fields.unpack(), + fields, followers_count: profile.follower_count, following_count: profile.following_count, statuses_count: profile.post_count, diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index eed6bed..0c8aa1e 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -15,6 +15,7 @@ use crate::utils::html::clean_html; pub struct ExtraField { pub name: String, pub value: String, + pub value_source: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -91,9 +92,14 @@ impl ProfileUpdateData { pub fn clean(&mut self) -> Result<(), ValidationError> { // Validate and clean bio self.bio = self.bio.as_ref().map(|val| clean_html(val)); - // Remove fields with empty labels + // Clean extra fields and remove fields with empty labels self.extra_fields = self.extra_fields.iter().cloned() - .filter(|field| field.name.trim().len() > 0) + .map(|mut field| { + field.name = field.name.trim().to_string(); + field.value = clean_html(&field.value); + field + }) + .filter(|field| field.name.len() > 0) .collect(); // Validate extra fields if self.extra_fields.len() >= 10 {