]> Untitled Git - lemmy.git/commitdiff
Add `to` field in follow activities for better compatibility (#2829)
authorNutomic <me@nutomic.com>
Mon, 24 Apr 2023 21:19:08 +0000 (23:19 +0200)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 21:19:08 +0000 (17:19 -0400)
* Add `to` field in follow activities for better compatibility (fixes #2744)

* fix tests

crates/apub/assets/lemmy/activities/following/accept.json
crates/apub/assets/lemmy/activities/following/follow.json
crates/apub/assets/lemmy/activities/following/undo_follow.json
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo_follow.rs
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

index 4097b36754698a48529f4b298243da4a1b6b9115..b524a56ec5a5de84ef48e08aecdeb8551cad63a9 100644 (file)
@@ -1,7 +1,9 @@
 {
   "actor": "http://enterprise.lemmy.ml/c/main",
+  "to": ["http://ds9.lemmy.ml/u/lemmy_alpha"],
   "object": {
     "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
+    "to": ["http://enterprise.lemmy.ml/c/main"],
     "object": "http://enterprise.lemmy.ml/c/main",
     "type": "Follow",
     "id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"
index 48f3fef8b74cb69aec127abd1cc97d430cf236a4..fe797233c1c1ca85385c7d05da751f52f363bca0 100644 (file)
@@ -1,5 +1,6 @@
 {
   "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
+  "to": ["http://enterprise.lemmy.ml/c/main"],
   "object": "http://enterprise.lemmy.ml/c/main",
   "type": "Follow",
   "id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"
index 5311bd990b2808a3e76a16ef802fecf5d8f3b574..255823d8d60c193476d7a387af7304808c4614ef 100644 (file)
@@ -1,7 +1,9 @@
 {
   "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
+  "to": ["http://enterprise.lemmy.ml/c/main"],
   "object": {
     "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
+    "to": ["http://enterprise.lemmy.ml/c/main"],
     "object": "http://enterprise.lemmy.ml/c/main",
     "type": "Follow",
     "id": "http://ds9.lemmy.ml/activities/follow/dc2f1bc5-f3a0-4daa-a46b-428cbfbd023c"
index c57ec0b53054b315837ba0d98419691d7ffa5da1..34dc976ded2db5fd148d631eb31d94852203e842 100644 (file)
@@ -34,6 +34,7 @@ impl AcceptFollow {
     let person = follow.actor.clone().dereference(context).await?;
     let accept = AcceptFollow {
       actor: user_or_community.id().into(),
+      to: Some([person.id().into()]),
       object: follow,
       kind: AcceptType::Accept,
       id: generate_activity_id(
@@ -64,6 +65,9 @@ impl ActivityHandler for AcceptFollow {
   async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
     verify_urls_match(self.actor.inner(), self.object.object.inner())?;
     self.object.verify(context).await?;
+    if let Some(to) = &self.to {
+      verify_urls_match(to[0].inner(), self.object.actor.inner())?;
+    }
     Ok(())
   }
 
index 41d2e71ed7beffa4d29ce1eaa6792df30e4c5147..4e2acd518f530c02f9a5679d101674801b07e9a8 100644 (file)
@@ -18,6 +18,7 @@ use crate::{
 use activitypub_federation::{
   config::Data,
   kinds::activity::FollowType,
+  protocol::verification::verify_urls_match,
   traits::{ActivityHandler, Actor},
 };
 use lemmy_api_common::{
@@ -44,6 +45,7 @@ impl Follow {
     Ok(Follow {
       actor: actor.id().into(),
       object: community.id().into(),
+      to: Some([community.id().into()]),
       kind: FollowType::Follow,
       id: generate_activity_id(
         FollowType::Follow,
@@ -93,6 +95,9 @@ impl ActivityHandler for Follow {
     if let UserOrCommunity::Community(c) = object {
       verify_person_in_community(&self.actor, &c, context).await?;
     }
+    if let Some(to) = &self.to {
+      verify_urls_match(to[0].inner(), self.object.inner())?;
+    }
     Ok(())
   }
 
index 9f1b89dc1a4f9f6c2ad6d7e0027dc72560560974..279054d53d4501761898a71fd24156c10f069217 100644 (file)
@@ -32,6 +32,7 @@ impl UndoFollow {
     let object = Follow::new(actor, community, context)?;
     let undo = UndoFollow {
       actor: actor.id().into(),
+      to: Some([community.id().into()]),
       object,
       kind: UndoType::Undo,
       id: generate_activity_id(
@@ -62,6 +63,9 @@ impl ActivityHandler for UndoFollow {
     verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
     verify_person(&self.actor, context).await?;
     self.object.verify(context).await?;
+    if let Some(to) = &self.to {
+      verify_urls_match(to[0].inner(), self.object.object.inner())?;
+    }
     Ok(())
   }
 
index 786827ed9bfccb701dd7e5c3a2512457ae71f51c..09e2cfda96da87e13109f59f0c736e2bb5f4afb3 100644 (file)
@@ -1,4 +1,7 @@
-use crate::{objects::community::ApubCommunity, protocol::activities::following::follow::Follow};
+use crate::{
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::follow::Follow,
+};
 use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::AcceptType};
 use serde::{Deserialize, Serialize};
 use url::Url;
@@ -7,6 +10,8 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct AcceptFollow {
   pub(crate) actor: ObjectId<ApubCommunity>,
+  /// Optional, for compatibility with platforms that always expect recipient field
+  pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
   pub(crate) object: Follow,
   #[serde(rename = "type")]
   pub(crate) kind: AcceptType,
index 27a3ba4be66d22b99d11e1b7ff881a0c69b1d302..064a36055d3259aebc4b12478cc9080eb87be789 100644 (file)
@@ -7,6 +7,8 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct Follow {
   pub(crate) actor: ObjectId<ApubPerson>,
+  /// Optional, for compatibility with platforms that always expect recipient field
+  pub(crate) to: Option<[ObjectId<UserOrCommunity>; 1]>,
   pub(crate) object: ObjectId<UserOrCommunity>,
   #[serde(rename = "type")]
   pub(crate) kind: FollowType,
index 4660db40a8d234adf6a7e59488fecba279f99f0a..f94a9b797cce549671ebff1165ddcff2cbf5d517 100644 (file)
@@ -7,6 +7,8 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct UndoFollow {
   pub(crate) actor: ObjectId<ApubPerson>,
+  /// Optional, for compatibility with platforms that always expect recipient field
+  pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
   pub(crate) object: Follow,
   #[serde(rename = "type")]
   pub(crate) kind: UndoType,