]> Untitled Git - lemmy.git/commitdiff
Dont federate initial upvote (#2196)
authorNutomic <me@nutomic.com>
Thu, 7 Apr 2022 20:46:10 +0000 (20:46 +0000)
committerGitHub <noreply@github.com>
Thu, 7 Apr 2022 20:46:10 +0000 (20:46 +0000)
crates/api_crud/src/comment/create.rs
crates/api_crud/src/post/create.rs
crates/apub/src/activities/create_or_update/comment.rs
crates/apub/src/activities/create_or_update/post.rs

index bb3b8c04801c9adbd2fd94a130ee7fcaf706a663..ac3744661ab993eda692eba154adc512320b5c32 100644 (file)
@@ -10,14 +10,9 @@ use lemmy_api_common::{
   get_post,
 };
 use lemmy_apub::{
-  fetcher::post_or_comment::PostOrComment,
   generate_local_apub_endpoint,
   objects::comment::ApubComment,
-  protocol::activities::{
-    create_or_update::comment::CreateOrUpdateComment,
-    voting::vote::{Vote, VoteType},
-    CreateOrUpdateType,
-  },
+  protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
   EndpointType,
 };
 use lemmy_db_schema::{
@@ -150,15 +145,6 @@ impl PerformCrud for CreateComment {
       &mut 0,
     )
     .await?;
-    let object = PostOrComment::Comment(Box::new(apub_comment));
-    Vote::send(
-      &object,
-      &local_user_view.person.clone().into(),
-      community_id,
-      VoteType::Like,
-      context,
-    )
-    .await?;
 
     let person_id = local_user_view.person.id;
     let comment_id = inserted_comment.id;
index b732cb13b62e870ae9905787caed02411ea7b1dd..4739666067fff93b0d7d6b2c78d467a1ae93bd11 100644 (file)
@@ -10,14 +10,9 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::{
-  fetcher::post_or_comment::PostOrComment,
   generate_local_apub_endpoint,
   objects::post::ApubPost,
-  protocol::activities::{
-    create_or_update::post::CreateOrUpdatePost,
-    voting::vote::{Vote, VoteType},
-    CreateOrUpdateType,
-  },
+  protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
   EndpointType,
 };
 use lemmy_db_schema::{
@@ -156,15 +151,6 @@ impl PerformCrud for CreatePost {
       context,
     )
     .await?;
-    let object = PostOrComment::Post(Box::new(apub_post));
-    Vote::send(
-      &object,
-      &local_user_view.person.clone().into(),
-      inserted_post.community_id,
-      VoteType::Like,
-      context,
-    )
-    .await?;
 
     send_post_ws_message(
       inserted_post.id,
index 7d6d89048369fb9627523fec82d3c6fd0c957565..603a19a9eb4e30fac36a67ffacfc2fe376fe1958 100644 (file)
@@ -21,8 +21,12 @@ use lemmy_apub_lib::{
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
-  source::{community::Community, post::Post},
-  traits::Crud,
+  source::{
+    comment::{CommentLike, CommentLikeForm},
+    community::Community,
+    post::Post,
+  },
+  traits::{Crud, Likeable},
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
@@ -113,6 +117,19 @@ impl ActivityHandler for CreateOrUpdateComment {
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
     let comment = ApubComment::from_apub(self.object, context, request_counter).await?;
+
+    // author likes their own comment by default
+    let like_form = CommentLikeForm {
+      comment_id: comment.id,
+      post_id: comment.post_id,
+      person_id: comment.creator_id,
+      score: 1,
+    };
+    blocking(context.pool(), move |conn: &'_ _| {
+      CommentLike::like(conn, &like_form)
+    })
+    .await??;
+
     let do_send_email = self.kind == CreateOrUpdateType::Create;
     let recipients = get_comment_notif_recipients(
       &self.actor,
index 907e23907890499715748a9fa4f26fc8079919a0..ddbe0981b03415241e877e3055ccdd36c78766fb 100644 (file)
@@ -20,7 +20,13 @@ use lemmy_apub_lib::{
   traits::{ActivityHandler, ActorType, ApubObject},
   verify::{verify_domains_match, verify_urls_match},
 };
-use lemmy_db_schema::{source::community::Community, traits::Crud};
+use lemmy_db_schema::{
+  source::{
+    community::Community,
+    post::{PostLike, PostLikeForm},
+  },
+  traits::{Crud, Likeable},
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
 
@@ -129,6 +135,17 @@ impl ActivityHandler for CreateOrUpdatePost {
   ) -> Result<(), LemmyError> {
     let post = ApubPost::from_apub(self.object, context, request_counter).await?;
 
+    // author likes their own post by default
+    let like_form = PostLikeForm {
+      post_id: post.id,
+      person_id: post.creator_id,
+      score: 1,
+    };
+    blocking(context.pool(), move |conn: &'_ _| {
+      PostLike::like(conn, &like_form)
+    })
+    .await??;
+
     let notif_type = match self.kind {
       CreateOrUpdateType::Create => UserOperationCrud::CreatePost,
       CreateOrUpdateType::Update => UserOperationCrud::EditPost,