From: Nutomic Date: Thu, 7 Apr 2022 20:46:10 +0000 (+0000) Subject: Dont federate initial upvote (#2196) X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/README.md?a=commitdiff_plain;h=9ac1f46a2b10c7d38d4f3684ad33a26c810a5f62;p=lemmy.git Dont federate initial upvote (#2196) --- diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index bb3b8c04..ac374466 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -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; diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index b732cb13..47396660 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -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, diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index 7d6d8904..603a19a9 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -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, diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index 907e2390..ddbe0981 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -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,