]> Untitled Git - lemmy.git/commitdiff
Add `to` field for follow, undo follow
authorFelix Ableitner <me@nutomic.com>
Mon, 12 Oct 2020 14:45:40 +0000 (16:45 +0200)
committerFelix Ableitner <me@nutomic.com>
Mon, 12 Oct 2020 14:45:40 +0000 (16:45 +0200)
lemmy_apub/src/activities/send/community.rs
lemmy_apub/src/activities/send/user.rs

index ab34f33670453a1f23a07681b580220d750bdaec..0d16d6361e9beb6dafeffa7f1825fd03a3944f5b 100644 (file)
@@ -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(())
   }
 
index 08f74d9432e096c1f8b4e4466e8a6e8777a4f6b4..6055a17866a29d29afb21fb821e2ab4835df5e83 100644 (file)
@@ -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(())
   }