mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 14:45:10 +00:00
Accept single object as to for arrays too (#2048)
This commit is contained in:
parent
19ccaf767c
commit
272dc3e7a6
|
@ -112,6 +112,25 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_one<'de, T, D>(deserializer: D) -> Result<[T; 1], D::Error>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum MaybeArray<T> {
|
||||
Simple(T),
|
||||
Array([T; 1]),
|
||||
}
|
||||
|
||||
let result: MaybeArray<T> = Deserialize::deserialize(deserializer)?;
|
||||
Ok(match result {
|
||||
MaybeArray::Simple(value) => [value],
|
||||
MaybeArray::Array(value) => value,
|
||||
})
|
||||
}
|
||||
|
||||
pub enum EndpointType {
|
||||
Community,
|
||||
Person,
|
||||
|
|
|
@ -12,6 +12,7 @@ use url::Url;
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Report {
|
||||
pub(crate) actor: ObjectId<ApubPerson>,
|
||||
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||
pub(crate) to: [ObjectId<ApubCommunity>; 1],
|
||||
pub(crate) object: ObjectId<PostOrComment>,
|
||||
pub(crate) summary: String,
|
||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
|||
pub struct CreateOrUpdatePrivateMessage {
|
||||
pub(crate) id: Url,
|
||||
pub(crate) actor: ObjectId<ApubPerson>,
|
||||
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||
pub(crate) object: ChatMessage,
|
||||
#[serde(rename = "type")]
|
||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DeletePrivateMessage {
|
||||
pub(crate) actor: ObjectId<ApubPerson>,
|
||||
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||
pub(crate) object: ObjectId<ApubPrivateMessage>,
|
||||
#[serde(rename = "type")]
|
||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UndoDeletePrivateMessage {
|
||||
pub(crate) actor: ObjectId<ApubPerson>,
|
||||
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||
pub(crate) object: DeletePrivateMessage,
|
||||
#[serde(rename = "type")]
|
||||
|
|
|
@ -14,6 +14,7 @@ pub struct ChatMessage {
|
|||
pub(crate) r#type: ChatMessageType,
|
||||
pub(crate) id: ObjectId<ApubPrivateMessage>,
|
||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||
pub(crate) content: String,
|
||||
pub(crate) media_type: Option<MediaTypeHtml>,
|
||||
|
|
Loading…
Reference in a new issue