From 709f29b7f83da04b88e26c8de56a80664d598477 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 20 Dec 2023 11:21:33 +0100 Subject: [PATCH] Context doesnt have to be an array (#90) --- src/protocol/context.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/protocol/context.rs b/src/protocol/context.rs index 433f8f3..027ff15 100644 --- a/src/protocol/context.rs +++ b/src/protocol/context.rs @@ -15,11 +15,11 @@ //! }; //! let note_with_context = WithContext::new_default(note); //! let serialized = serde_json::to_string(¬e_with_context)?; -//! assert_eq!(serialized, r#"{"@context":["https://www.w3.org/ns/activitystreams"],"content":"Hello world"}"#); +//! assert_eq!(serialized, r#"{"@context":"https://www.w3.org/ns/activitystreams","content":"Hello world"}"#); //! Ok::<(), serde_json::error::Error>(()) //! ``` -use crate::{config::Data, protocol::helpers::deserialize_one_or_many, traits::ActivityHandler}; +use crate::{config::Data, traits::ActivityHandler}; use serde::{Deserialize, Serialize}; use serde_json::Value; use url::Url; @@ -31,8 +31,7 @@ const DEFAULT_CONTEXT: &str = "https://www.w3.org/ns/activitystreams"; #[derive(Serialize, Deserialize, Debug)] pub struct WithContext { #[serde(rename = "@context")] - #[serde(deserialize_with = "deserialize_one_or_many")] - context: Vec, + context: Value, #[serde(flatten)] inner: T, } @@ -40,12 +39,12 @@ pub struct WithContext { impl WithContext { /// Create a new wrapper with the default Activitypub context. pub fn new_default(inner: T) -> WithContext { - let context = vec![Value::String(DEFAULT_CONTEXT.to_string())]; + let context = Value::String(DEFAULT_CONTEXT.to_string()); WithContext::new(inner, context) } /// Create new wrapper with custom context. Use this in case you are implementing extensions. - pub fn new(inner: T, context: Vec) -> WithContext { + pub fn new(inner: T, context: Value) -> WithContext { WithContext { context, inner } }