From 09099e7b90ec505772bcdeb1c7756047b8a6078d Mon Sep 17 00:00:00 2001 From: vpzomtrrfrt Date: Tue, 6 Jun 2023 16:33:38 -0600 Subject: [PATCH] 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 --- crates/apub/assets/lotide/activities/follow.json | 8 ++++++++ crates/apub/src/protocol/activities/following/accept.rs | 7 ++++++- crates/apub/src/protocol/activities/following/follow.rs | 7 ++++++- .../apub/src/protocol/activities/following/undo_follow.rs | 7 ++++++- crates/apub/src/protocol/activities/mod.rs | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 crates/apub/assets/lotide/activities/follow.json diff --git a/crates/apub/assets/lotide/activities/follow.json b/crates/apub/assets/lotide/activities/follow.json new file mode 100644 index 000000000..2c3006ddb --- /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 09e2cfda9..181ea7188 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 064a36055..5d5104ea6 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 f94a9b797..aa582e99a 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 670c4466f..a7ce37015 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();