From: Felix Ableitner Date: Mon, 12 Oct 2020 14:45:40 +0000 (+0200) Subject: Add `to` field for follow, undo follow X-Git-Url: http://these/git/%7B%60https:/static/gitweb.css?a=commitdiff_plain;h=2ad60379e41b653cc4c841d024e2d9cdf7884f69;p=lemmy.git Add `to` field for follow, undo follow --- diff --git a/lemmy_apub/src/activities/send/community.rs b/lemmy_apub/src/activities/send/community.rs index ab34f336..0d16d636 100644 --- a/lemmy_apub/src/activities/send/community.rs +++ b/lemmy_apub/src/activities/send/community.rs @@ -2,7 +2,7 @@ use crate::{ activities::send::generate_activity_id, activity_queue::{send_activity_single_dest, send_to_community_followers}, check_is_apub_id_valid, - fetcher::get_or_fetch_and_upsert_actor, + fetcher::get_or_fetch_and_upsert_user, ActorType, ToApub, }; @@ -72,16 +72,15 @@ impl ActorType for Community { .actor()? .as_single_xsd_any_uri() .context(location_info!())?; - let actor = get_or_fetch_and_upsert_actor(actor_uri, context).await?; + let user = get_or_fetch_and_upsert_user(actor_uri, context).await?; let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?); - let to = actor.get_inbox_url()?; accept .set_context(activitystreams::context()) .set_id(generate_activity_id(AcceptType::Accept)?) - .set_to(to.clone()); + .set_to(user.actor_id()?); - send_activity_single_dest(accept, self, to, context).await?; + send_activity_single_dest(accept, self, user.get_inbox_url()?, context).await?; Ok(()) } diff --git a/lemmy_apub/src/activities/send/user.rs b/lemmy_apub/src/activities/send/user.rs index 08f74d94..6055a178 100644 --- a/lemmy_apub/src/activities/send/user.rs +++ b/lemmy_apub/src/activities/send/user.rs @@ -1,7 +1,6 @@ use crate::{ activities::send::generate_activity_id, activity_queue::send_activity_single_dest, - fetcher::get_or_fetch_and_upsert_actor, ActorType, }; use activitystreams::{ @@ -11,8 +10,10 @@ use activitystreams::{ Undo, }, base::{AnyBase, BaseExt, ExtendsExt}, + object::ObjectExt, }; -use lemmy_db::{user::User_, DbPool}; +use lemmy_db::{community::Community, user::User_, DbPool}; +use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -41,14 +42,19 @@ impl ActorType for User_ { follow_actor_id: &Url, context: &LemmyContext, ) -> Result<(), LemmyError> { - let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str()); + let follow_actor_id = follow_actor_id.to_string(); + let community = blocking(context.pool(), move |conn| { + Community::read_from_actor_id(conn, &follow_actor_id) + }) + .await??; + + let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?); follow .set_context(activitystreams::context()) - .set_id(generate_activity_id(FollowType::Follow)?); - let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?; - let to = follow_actor.get_inbox_url()?; + .set_id(generate_activity_id(FollowType::Follow)?) + .set_to(community.actor_id()?); - send_activity_single_dest(follow, self, to, context).await?; + send_activity_single_dest(follow, self, community.get_inbox_url()?, context).await?; Ok(()) } @@ -57,21 +63,26 @@ impl ActorType for User_ { follow_actor_id: &Url, context: &LemmyContext, ) -> Result<(), LemmyError> { - let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str()); + let follow_actor_id = follow_actor_id.to_string(); + let community = blocking(context.pool(), move |conn| { + Community::read_from_actor_id(conn, &follow_actor_id) + }) + .await??; + + let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?); follow .set_context(activitystreams::context()) - .set_id(generate_activity_id(FollowType::Follow)?); - let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?; - - let to = follow_actor.get_inbox_url()?; + .set_id(generate_activity_id(FollowType::Follow)?) + .set_to(community.actor_id()?); // Undo that fake activity let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?); undo .set_context(activitystreams::context()) - .set_id(generate_activity_id(UndoType::Undo)?); + .set_id(generate_activity_id(UndoType::Undo)?) + .set_to(community.actor_id()?); - send_activity_single_dest(undo, self, to, context).await?; + send_activity_single_dest(undo, self, community.get_inbox_url()?, context).await?; Ok(()) }