]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/voting/vote.rs
Implement federated user following (fixes #752) (#2577)
[lemmy.git] / crates / apub / src / activities / voting / vote.rs
index e33c956761b9c416ce292a9cfe42166da467a487..2b60206a1c02a6f938347b4b0014b249c8d37f1b 100644 (file)
@@ -14,7 +14,6 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
 use anyhow::anyhow;
-use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
   newtypes::CommunityId,
   source::{community::Community, local_site::LocalSite, post::Post},
@@ -38,7 +37,6 @@ impl Vote {
       object: ObjectId::new(object.ap_id()),
       kind: kind.clone(),
       id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
-      unparsed: Default::default(),
     })
   }
 
@@ -50,15 +48,11 @@ impl Vote {
     kind: VoteType,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
-    let community = blocking(context.pool(), move |conn| {
-      Community::read(conn, community_id)
-    })
-    .await??
-    .into();
+    let community = Community::read(context.pool(), community_id).await?.into();
     let vote = Vote::new(object, actor, kind, context)?;
 
     let activity = AnnouncableActivities::Vote(vote);
-    send_activity_in_community(activity, actor, &community, vec![], context).await
+    send_activity_in_community(activity, actor, &community, vec![], false, context).await
   }
 }
 
@@ -83,8 +77,8 @@ impl ActivityHandler for Vote {
   ) -> Result<(), LemmyError> {
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    let enable_downvotes = blocking(context.pool(), LocalSite::read)
-      .await?
+    let enable_downvotes = LocalSite::read(context.pool())
+      .await
       .map(|l| l.enable_downvotes)
       .unwrap_or(true);
     if self.kind == VoteType::Dislike && !enable_downvotes {
@@ -101,11 +95,11 @@ impl ActivityHandler for Vote {
   ) -> Result<(), LemmyError> {
     let actor = self
       .actor
-      .dereference(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context).await, request_counter)
       .await?;
     let object = self
       .object
-      .dereference(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context).await, request_counter)
       .await?;
     match object {
       PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
@@ -124,17 +118,13 @@ impl GetCommunity for Vote {
   ) -> Result<ApubCommunity, LemmyError> {
     let object = self
       .object
-      .dereference(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context).await, request_counter)
       .await?;
     let cid = match object {
       PostOrComment::Post(p) => p.community_id,
-      PostOrComment::Comment(c) => {
-        blocking(context.pool(), move |conn| Post::read(conn, c.post_id))
-          .await??
-          .community_id
-      }
+      PostOrComment::Comment(c) => Post::read(context.pool(), c.post_id).await?.community_id,
     };
-    let community = blocking(context.pool(), move |conn| Community::read(conn, cid)).await??;
+    let community = Community::read(context.pool(), cid).await?;
     Ok(community.into())
   }
 }