Rename Image type to ActorImage

This commit is contained in:
silverpill 2023-01-06 22:34:50 +00:00
parent 6c850b0197
commit 65072ca3c5

View file

@ -48,7 +48,7 @@ pub struct PublicKey {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Image { pub struct ActorImage {
#[serde(rename = "type")] #[serde(rename = "type")]
object_type: String, object_type: String,
pub url: String, pub url: String,
@ -78,7 +78,7 @@ pub struct ActorAttachment {
// Some implementations use empty object instead of null // Some implementations use empty object instead of null
pub fn deserialize_image_opt<'de, D>( pub fn deserialize_image_opt<'de, D>(
deserializer: D, deserializer: D,
) -> Result<Option<Image>, D::Error> ) -> Result<Option<ActorImage>, D::Error>
where D: Deserializer<'de> where D: Deserializer<'de>
{ {
let maybe_value: Option<Value> = Option::deserialize(deserializer)?; let maybe_value: Option<Value> = Option::deserialize(deserializer)?;
@ -89,7 +89,7 @@ pub fn deserialize_image_opt<'de, D>(
if is_empty_object { if is_empty_object {
None None
} else { } else {
let image = Image::deserialize(value) let image = ActorImage::deserialize(value)
.map_err(DeserializerError::custom)?; .map_err(DeserializerError::custom)?;
Some(image) Some(image)
} }
@ -134,10 +134,10 @@ pub struct Actor {
deserialize_with = "deserialize_image_opt", deserialize_with = "deserialize_image_opt",
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
)] )]
pub icon: Option<Image>, pub icon: Option<ActorImage>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<Image>, pub image: Option<ActorImage>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub summary: Option<String>, pub summary: Option<String>,
@ -277,21 +277,21 @@ pub fn get_local_actor(
}; };
let avatar = match &user.profile.avatar_file_name { let avatar = match &user.profile.avatar_file_name {
Some(file_name) => { Some(file_name) => {
let image = Image { let actor_image = ActorImage {
object_type: IMAGE.to_string(), object_type: IMAGE.to_string(),
url: get_file_url(instance_url, file_name), url: get_file_url(instance_url, file_name),
}; };
Some(image) Some(actor_image)
}, },
None => None, None => None,
}; };
let banner = match &user.profile.banner_file_name { let banner = match &user.profile.banner_file_name {
Some(file_name) => { Some(file_name) => {
let image = Image { let actor_image = ActorImage {
object_type: IMAGE.to_string(), object_type: IMAGE.to_string(),
url: get_file_url(instance_url, file_name), url: get_file_url(instance_url, file_name),
}; };
Some(image) Some(actor_image)
}, },
None => None, None => None,
}; };