From: Felix Ableitner Date: Tue, 16 Nov 2021 16:27:43 +0000 (+0100) Subject: Remove to field from follow activities X-Git-Url: http://these/git/%22https:/nerdica.net/%7B%24%7B%60data:application/static/git-favicon.png?a=commitdiff_plain;h=3249060f671c5a6a300a19b157e95047a2ef9cbc;p=lemmy.git Remove to field from follow activities --- diff --git a/crates/apub/assets/lemmy/activities/following/accept.json b/crates/apub/assets/lemmy/activities/following/accept.json index d5bcfaf4..4097b367 100644 --- a/crates/apub/assets/lemmy/activities/following/accept.json +++ b/crates/apub/assets/lemmy/activities/following/accept.json @@ -1,13 +1,7 @@ { "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" diff --git a/crates/apub/assets/lemmy/activities/following/follow.json b/crates/apub/assets/lemmy/activities/following/follow.json index 50cc77dc..48f3fef8 100644 --- a/crates/apub/assets/lemmy/activities/following/follow.json +++ b/crates/apub/assets/lemmy/activities/following/follow.json @@ -1,8 +1,5 @@ { "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" diff --git a/crates/apub/assets/lemmy/activities/following/undo_follow.json b/crates/apub/assets/lemmy/activities/following/undo_follow.json index d27bec0a..5311bd99 100644 --- a/crates/apub/assets/lemmy/activities/following/undo_follow.json +++ b/crates/apub/assets/lemmy/activities/following/undo_follow.json @@ -1,13 +1,7 @@ { "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" diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index 44d6009a..15e1f2b4 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -28,7 +28,6 @@ impl AcceptFollowCommunity { .await?; let accept = AcceptFollowCommunity { actor: ObjectId::new(community.actor_id()), - to: [ObjectId::new(person.actor_id())], object: follow, kind: AcceptType::Accept, id: generate_activity_id( @@ -52,8 +51,7 @@ impl ActivityHandler for AcceptFollowCommunity { request_counter: &mut i32, ) -> Result<(), LemmyError> { verify_activity(&self.id, self.actor.inner(), &context.settings())?; - verify_urls_match(self.to[0].inner(), self.object.actor.inner())?; - verify_urls_match(self.actor.inner(), self.object.to[0].inner())?; + verify_urls_match(self.actor.inner(), self.object.object.inner())?; self.object.verify(context, request_counter).await?; Ok(()) } @@ -63,11 +61,15 @@ impl ActivityHandler for AcceptFollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let actor = self.actor.dereference(context, request_counter).await?; - let to = self.to[0].dereference(context, request_counter).await?; + let person = self.actor.dereference(context, request_counter).await?; + let community = self + .object + .actor + .dereference(context, request_counter) + .await?; // This will throw an error if no follow was requested blocking(context.pool(), move |conn| { - CommunityFollower::follow_accepted(conn, actor.id, to.id) + CommunityFollower::follow_accepted(conn, person.id, community.id) }) .await??; diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 22f3db4b..43c60028 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -15,7 +15,6 @@ use lemmy_apub_lib::{ data::Data, object_id::ObjectId, traits::{ActivityHandler, ActorType}, - verify::verify_urls_match, }; use lemmy_db_schema::{ source::community::{CommunityFollower, CommunityFollowerForm}, @@ -32,7 +31,6 @@ impl FollowCommunity { ) -> Result { Ok(FollowCommunity { actor: ObjectId::new(actor.actor_id()), - to: [ObjectId::new(community.actor_id())], object: ObjectId::new(community.actor_id()), kind: FollowType::Follow, id: generate_activity_id( @@ -72,9 +70,8 @@ impl ActivityHandler for FollowCommunity { request_counter: &mut i32, ) -> Result<(), LemmyError> { verify_activity(&self.id, self.actor.inner(), &context.settings())?; - verify_urls_match(self.to[0].inner(), self.object.inner())?; verify_person(&self.actor, context, request_counter).await?; - let community = self.to[0].dereference(context, request_counter).await?; + let community = self.object.dereference(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; Ok(()) } @@ -84,11 +81,11 @@ impl ActivityHandler for FollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let actor = self.actor.dereference(context, request_counter).await?; - let community = self.to[0].dereference(context, request_counter).await?; + let person = self.actor.dereference(context, request_counter).await?; + let community = self.object.dereference(context, request_counter).await?; let community_follower_form = CommunityFollowerForm { community_id: community.id, - person_id: actor.id, + person_id: person.id, pending: false, }; diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index ac25fcd5..2a3483d4 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -27,7 +27,6 @@ impl UndoFollowCommunity { let object = FollowCommunity::new(actor, community, context)?; let undo = UndoFollowCommunity { actor: ObjectId::new(actor.actor_id()), - to: [ObjectId::new(community.actor_id())], object, kind: UndoType::Undo, id: generate_activity_id( @@ -50,7 +49,6 @@ impl ActivityHandler for UndoFollowCommunity { request_counter: &mut i32, ) -> Result<(), LemmyError> { verify_activity(&self.id, self.actor.inner(), &context.settings())?; - verify_urls_match(self.to[0].inner(), self.object.object.inner())?; verify_urls_match(self.actor.inner(), self.object.actor.inner())?; verify_person(&self.actor, context, request_counter).await?; self.object.verify(context, request_counter).await?; @@ -62,12 +60,16 @@ impl ActivityHandler for UndoFollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let actor = self.actor.dereference(context, request_counter).await?; - let community = self.to[0].dereference(context, request_counter).await?; + let person = self.actor.dereference(context, request_counter).await?; + let community = self + .object + .object + .dereference(context, request_counter) + .await?; let community_follower_form = CommunityFollowerForm { community_id: community.id, - person_id: actor.id, + person_id: person.id, pending: false, }; diff --git a/crates/apub/src/protocol/activities/following/accept.rs b/crates/apub/src/protocol/activities/following/accept.rs index 0c5988bc..2d5acb3b 100644 --- a/crates/apub/src/protocol/activities/following/accept.rs +++ b/crates/apub/src/protocol/activities/following/accept.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{community::ApubCommunity, person::ApubPerson}, + objects::community::ApubCommunity, protocol::activities::following::follow::FollowCommunity, }; use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed}; @@ -11,7 +11,6 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct AcceptFollowCommunity { pub(crate) actor: ObjectId, - pub(crate) to: [ObjectId; 1], pub(crate) object: FollowCommunity, #[serde(rename = "type")] pub(crate) kind: AcceptType, diff --git a/crates/apub/src/protocol/activities/following/follow.rs b/crates/apub/src/protocol/activities/following/follow.rs index 9d3f6a82..fe4e4e7b 100644 --- a/crates/apub/src/protocol/activities/following/follow.rs +++ b/crates/apub/src/protocol/activities/following/follow.rs @@ -8,7 +8,6 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct FollowCommunity { pub(crate) actor: ObjectId, - pub(crate) to: [ObjectId; 1], pub(crate) object: ObjectId, #[serde(rename = "type")] pub(crate) kind: FollowType, diff --git a/crates/apub/src/protocol/activities/following/undo_follow.rs b/crates/apub/src/protocol/activities/following/undo_follow.rs index 5e9c5894..f2feba14 100644 --- a/crates/apub/src/protocol/activities/following/undo_follow.rs +++ b/crates/apub/src/protocol/activities/following/undo_follow.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{community::ApubCommunity, person::ApubPerson}, + objects::person::ApubPerson, protocol::activities::following::follow::FollowCommunity, }; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; @@ -11,7 +11,6 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UndoFollowCommunity { pub(crate) actor: ObjectId, - pub(crate) to: [ObjectId; 1], pub(crate) object: FollowCommunity, #[serde(rename = "type")] pub(crate) kind: UndoType,