Deserialize actor tag to Vec<Value>

This commit is contained in:
silverpill 2023-03-03 22:08:38 +00:00
parent 6335e216a9
commit 4204350375
3 changed files with 13 additions and 16 deletions

View file

@ -1,13 +1,11 @@
use std::path::Path; use std::path::Path;
use serde_json::{Value as JsonValue};
use mitra_config::Instance; use mitra_config::Instance;
use crate::activitypub::{ use crate::activitypub::{
actors::types::Actor, actors::types::Actor,
fetcher::fetchers::fetch_file, fetcher::fetchers::fetch_file,
receiver::{parse_property_value, HandlerError}, receiver::HandlerError,
}; };
use crate::database::DatabaseClient; use crate::database::DatabaseClient;
use crate::models::{ use crate::models::{
@ -81,14 +79,8 @@ async fn fetch_actor_images(
} }
fn parse_tags(actor: &Actor) -> () { fn parse_tags(actor: &Actor) -> () {
if let Some(ref tag_list_value) = actor.tag { for tag_value in &actor.tag {
let maybe_tag_list: Option<Vec<JsonValue>> = log::debug!("found actor tag: {}", tag_value);
parse_property_value(tag_list_value).ok();
if let Some(tag_list) = maybe_tag_list {
for tag_value in tag_list {
log::debug!("found actor tag: {}", tag_value);
};
};
}; };
} }

View file

@ -29,6 +29,7 @@ use crate::activitypub::{
LocalActorCollection, LocalActorCollection,
}, },
receiver::parse_property_value, receiver::parse_property_value,
types::deserialize_value_array,
vocabulary::{IDENTITY_PROOF, IMAGE, LINK, PERSON, PROPERTY_VALUE, SERVICE}, vocabulary::{IDENTITY_PROOF, IMAGE, LINK, PERSON, PROPERTY_VALUE, SERVICE},
}; };
use crate::errors::ValidationError; use crate::errors::ValidationError;
@ -185,8 +186,12 @@ pub struct Actor {
#[serde(default)] #[serde(default)]
pub manually_approves_followers: bool, pub manually_approves_followers: bool,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(
pub tag: Option<Value>, default,
deserialize_with = "deserialize_value_array",
skip_serializing_if = "Vec::is_empty",
)]
pub tag: Vec<Value>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<String>,
@ -351,7 +356,7 @@ pub fn get_local_actor(
also_known_as: None, also_known_as: None,
attachment: attachments, attachment: attachments,
manually_approves_followers: false, manually_approves_followers: false,
tag: None, tag: vec![],
url: Some(actor_id), url: Some(actor_id),
}; };
Ok(actor) Ok(actor)
@ -387,7 +392,7 @@ pub fn get_instance_actor(
also_known_as: None, also_known_as: None,
attachment: vec![], attachment: vec![],
manually_approves_followers: false, manually_approves_followers: false,
tag: None, tag: vec![],
url: None, url: None,
}; };
Ok(actor) Ok(actor)

View file

@ -88,7 +88,7 @@ pub struct EmojiTag {
pub updated: DateTime<Utc>, pub updated: DateTime<Utc>,
} }
fn deserialize_value_array<'de, D>( pub fn deserialize_value_array<'de, D>(
deserializer: D, deserializer: D,
) -> Result<Vec<Value>, D::Error> ) -> Result<Vec<Value>, D::Error>
where D: Deserializer<'de> where D: Deserializer<'de>