From: vpzomtrrfrt Date: Tue, 6 Jun 2023 22:33:38 +0000 (-0600) Subject: Fix handling of follows addressed to single value (#2920) X-Git-Url: http://these/git/%22https:/nerdica.net/%7B%24%7B%60data:application/static/%7BelementUrl%7D?a=commitdiff_plain;h=09099e7b90ec505772bcdeb1c7756047b8a6078d;p=lemmy.git Fix handling of follows addressed to single value (#2920) * Fix handling of follows addressed to single value * Switch to deserialize_skip_error for Follow to * Also use deserialize_skip_error for AcceptFollow and UndoFollow * actually import deserialize_skip_error --- diff --git a/crates/apub/assets/lotide/activities/follow.json b/crates/apub/assets/lotide/activities/follow.json new file mode 100644 index 00000000..2c3006dd --- /dev/null +++ b/crates/apub/assets/lotide/activities/follow.json @@ -0,0 +1,8 @@ +{ + "actor": "https://dev.narwhal.city/users/1", + "object": "https://beehaw.org/c/foss", + "to": "https://beehaw.org/c/foss", + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://dev.narwhal.city/communities/90/followers/1", + "type": "Follow" +} diff --git a/crates/apub/src/protocol/activities/following/accept.rs b/crates/apub/src/protocol/activities/following/accept.rs index 09e2cfda..181ea718 100644 --- a/crates/apub/src/protocol/activities/following/accept.rs +++ b/crates/apub/src/protocol/activities/following/accept.rs @@ -2,7 +2,11 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::follow::Follow, }; -use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::AcceptType}; +use activitypub_federation::{ + fetch::object_id::ObjectId, + kinds::activity::AcceptType, + protocol::helpers::deserialize_skip_error, +}; use serde::{Deserialize, Serialize}; use url::Url; @@ -11,6 +15,7 @@ use url::Url; pub struct AcceptFollow { pub(crate) actor: ObjectId, /// Optional, for compatibility with platforms that always expect recipient field + #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) to: Option<[ObjectId; 1]>, pub(crate) object: Follow, #[serde(rename = "type")] diff --git a/crates/apub/src/protocol/activities/following/follow.rs b/crates/apub/src/protocol/activities/following/follow.rs index 064a3605..5d5104ea 100644 --- a/crates/apub/src/protocol/activities/following/follow.rs +++ b/crates/apub/src/protocol/activities/following/follow.rs @@ -1,5 +1,9 @@ use crate::{fetcher::user_or_community::UserOrCommunity, objects::person::ApubPerson}; -use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::FollowType}; +use activitypub_federation::{ + fetch::object_id::ObjectId, + kinds::activity::FollowType, + protocol::helpers::deserialize_skip_error, +}; use serde::{Deserialize, Serialize}; use url::Url; @@ -8,6 +12,7 @@ use url::Url; pub struct Follow { pub(crate) actor: ObjectId, /// Optional, for compatibility with platforms that always expect recipient field + #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) to: Option<[ObjectId; 1]>, pub(crate) object: ObjectId, #[serde(rename = "type")] diff --git a/crates/apub/src/protocol/activities/following/undo_follow.rs b/crates/apub/src/protocol/activities/following/undo_follow.rs index f94a9b79..aa582e99 100644 --- a/crates/apub/src/protocol/activities/following/undo_follow.rs +++ b/crates/apub/src/protocol/activities/following/undo_follow.rs @@ -1,5 +1,9 @@ use crate::{objects::person::ApubPerson, protocol::activities::following::follow::Follow}; -use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::UndoType}; +use activitypub_federation::{ + fetch::object_id::ObjectId, + kinds::activity::UndoType, + protocol::helpers::deserialize_skip_error, +}; use serde::{Deserialize, Serialize}; use url::Url; @@ -8,6 +12,7 @@ use url::Url; pub struct UndoFollow { pub(crate) actor: ObjectId, /// Optional, for compatibility with platforms that always expect recipient field + #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) to: Option<[ObjectId; 1]>, pub(crate) object: Follow, #[serde(rename = "type")] diff --git a/crates/apub/src/protocol/activities/mod.rs b/crates/apub/src/protocol/activities/mod.rs index 670c4466..a7ce3701 100644 --- a/crates/apub/src/protocol/activities/mod.rs +++ b/crates/apub/src/protocol/activities/mod.rs @@ -51,6 +51,7 @@ mod tests { #[test] fn test_parse_lotide_activities() { + test_json::("assets/lotide/activities/follow.json").unwrap(); test_json::("assets/lotide/activities/create_page.json").unwrap(); test_json::("assets/lotide/activities/create_page_image.json").unwrap(); test_json::("assets/lotide/activities/create_note_reply.json").unwrap();