From 7cfd3945c085b2499492f8295ae35d5f50bb21d7 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 24 Apr 2026 11:32:07 +0900 Subject: [PATCH] Deduplicate deserialized recipients Drop repeated recipient URLs after deserialization so equivalent public aliases such as `Public`, `as:Public`, and the canonical public URL do not produce duplicate entries. Update the helper documentation and tests to match the deduplicated result. --- src/protocol/helpers.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/protocol/helpers.rs b/src/protocol/helpers.rs index 555eb90..c5b3ef8 100644 --- a/src/protocol/helpers.rs +++ b/src/protocol/helpers.rs @@ -1,6 +1,7 @@ //! Serde deserialization functions which help to receive differently shaped data use activitystreams_kinds::public; +use itertools::Itertools; use serde::{de::Error, Deserialize, Deserializer}; use serde_json::Value; use url::Url; @@ -35,7 +36,7 @@ use url::Url; /// assert_eq!(multiple.to.len(), 2); /// /// let note: Note = serde_json::from_str(r#"{"to": ["Public", "as:Public"]}"#)?; -/// assert_eq!(note.to, vec![public(), public()]); +/// assert_eq!(note.to, vec![public()]); /// # Ok::<(), anyhow::Error>(()) /// ``` pub fn deserialize_one_or_many<'de, D>(deserializer: D) -> Result, D::Error> @@ -64,7 +65,8 @@ where Value::String(value) => Url::parse(&value).map_err(D::Error::custom), value => Url::deserialize(value).map_err(D::Error::custom), }) - .collect() + .collect::, _>>() + .map(|values| values.into_iter().unique().collect()) } /// Deserialize JSON single value or single element array into single value. @@ -224,12 +226,7 @@ mod tests { assert_eq!( note.to, - vec![ - Url::parse("https://example.com/c/main")?, - public(), - public(), - public(), - ] + vec![Url::parse("https://example.com/c/main")?, public(),] ); Ok(())