]> Untitled Git - lemmy.git/commitdiff
Fix handling of follows addressed to single value (#2920)
authorvpzomtrrfrt <colin@vpzom.click>
Tue, 6 Jun 2023 22:33:38 +0000 (16:33 -0600)
committerGitHub <noreply@github.com>
Tue, 6 Jun 2023 22:33:38 +0000 (18:33 -0400)
* 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 [new file with mode: 0644]
crates/apub/src/protocol/activities/following/accept.rs
crates/apub/src/protocol/activities/following/follow.rs
crates/apub/src/protocol/activities/following/undo_follow.rs
crates/apub/src/protocol/activities/mod.rs

diff --git a/crates/apub/assets/lotide/activities/follow.json b/crates/apub/assets/lotide/activities/follow.json
new file mode 100644 (file)
index 0000000..2c3006d
--- /dev/null
@@ -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"
+}
index 09e2cfda96da87e13109f59f0c736e2bb5f4afb3..181ea71883e0cf5f72249990a6717a370bc68961 100644 (file)
@@ -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<ApubCommunity>,
   /// Optional, for compatibility with platforms that always expect recipient field
+  #[serde(deserialize_with = "deserialize_skip_error", default)]
   pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
   pub(crate) object: Follow,
   #[serde(rename = "type")]
index 064a36055d3259aebc4b12478cc9080eb87be789..5d5104ea6a466d73cf487f12bfcd0945e1a7e53f 100644 (file)
@@ -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<ApubPerson>,
   /// Optional, for compatibility with platforms that always expect recipient field
+  #[serde(deserialize_with = "deserialize_skip_error", default)]
   pub(crate) to: Option<[ObjectId<UserOrCommunity>; 1]>,
   pub(crate) object: ObjectId<UserOrCommunity>,
   #[serde(rename = "type")]
index f94a9b797cce549671ebff1165ddcff2cbf5d517..aa582e99ab914903fc78910d107a036ecdd6dc61 100644 (file)
@@ -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<ApubPerson>,
   /// Optional, for compatibility with platforms that always expect recipient field
+  #[serde(deserialize_with = "deserialize_skip_error", default)]
   pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
   pub(crate) object: Follow,
   #[serde(rename = "type")]
index 670c4466f4125e8681ec034f63e521c5dc44ca01..a7ce37015adc9f246650f226d6f5a48024c672f0 100644 (file)
@@ -51,6 +51,7 @@ mod tests {
 
   #[test]
   fn test_parse_lotide_activities() {
+    test_json::<Follow>("assets/lotide/activities/follow.json").unwrap();
     test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
     test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
     test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();