Accept actor objects where value of "attachment" property is not an array
This commit is contained in:
parent
6ba8434f40
commit
10c38400e4
2 changed files with 25 additions and 2 deletions
|
@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- Don't ignore `Delete(Person)` verification errors if database error subtype is not `NotFound`.
|
- Don't ignore `Delete(Person)` verification errors if database error subtype is not `NotFound`.
|
||||||
- Don't stop activity processing on invalid local mentions.
|
- Don't stop activity processing on invalid local mentions.
|
||||||
|
- Accept actor objects where `attachment` property value is not an array.
|
||||||
|
|
||||||
## [1.9.0] - 2023-01-08
|
## [1.9.0] - 2023-01-08
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use serde_json::{json, Value};
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
constants::{ACTOR_KEY_SUFFIX, AP_CONTEXT},
|
constants::{ACTOR_KEY_SUFFIX, AP_CONTEXT},
|
||||||
identifiers::{local_actor_id, LocalActorCollection},
|
identifiers::{local_actor_id, LocalActorCollection},
|
||||||
|
receiver::parse_property_value,
|
||||||
vocabulary::{IDENTITY_PROOF, IMAGE, LINK, PERSON, PROPERTY_VALUE, SERVICE},
|
vocabulary::{IDENTITY_PROOF, IMAGE, LINK, PERSON, PROPERTY_VALUE, SERVICE},
|
||||||
};
|
};
|
||||||
use crate::config::Instance;
|
use crate::config::Instance;
|
||||||
|
@ -74,7 +75,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>(
|
fn deserialize_image_opt<'de, D>(
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
) -> Result<Option<ActorImage>, D::Error>
|
) -> Result<Option<ActorImage>, D::Error>
|
||||||
where D: Deserializer<'de>
|
where D: Deserializer<'de>
|
||||||
|
@ -97,6 +98,23 @@ pub fn deserialize_image_opt<'de, D>(
|
||||||
Ok(maybe_image)
|
Ok(maybe_image)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some implementations use single object instead of array
|
||||||
|
fn deserialize_attachments_opt<'de, D>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> Result<Option<Vec<ActorAttachment>>, D::Error>
|
||||||
|
where D: Deserializer<'de>
|
||||||
|
{
|
||||||
|
let maybe_value: Option<Value> = Option::deserialize(deserializer)?;
|
||||||
|
let maybe_attachments = if let Some(value) = maybe_value {
|
||||||
|
let attachments: Vec<ActorAttachment> = parse_property_value(&value)
|
||||||
|
.map_err(DeserializerError::custom)?;
|
||||||
|
Some(attachments)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
Ok(maybe_attachments)
|
||||||
|
}
|
||||||
|
|
||||||
// Clone and Debug traits are required by FromSql
|
// Clone and Debug traits are required by FromSql
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(test, derive(Default))]
|
#[cfg_attr(test, derive(Default))]
|
||||||
|
@ -143,7 +161,11 @@ pub struct Actor {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub also_known_as: Option<Value>,
|
pub also_known_as: Option<Value>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "deserialize_attachments_opt",
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
)]
|
||||||
pub attachment: Option<Vec<ActorAttachment>>,
|
pub attachment: Option<Vec<ActorAttachment>>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
Loading…
Reference in a new issue