X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapub%2Fsrc%2Factivities%2Fcreate_or_update%2Fpost.rs;h=77199056d53f044c236f9d74aac1b569daeb1568;hb=e9e76549a88cfbdab36f00d302cceabcaaa24f4c;hp=f2923bfbdcbb0d4d125a2ecef33b1345a8b1d301;hpb=2423b89ced5c2d110c1284777407682f748a068f;p=lemmy.git diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index f2923bfb..77199056 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -8,7 +8,7 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - insert_activity, + insert_received_activity, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::{ activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType}, @@ -27,6 +27,7 @@ use lemmy_api_common::{ post::{CreatePost, EditPost, PostResponse}, }; use lemmy_db_schema::{ + aggregates::structs::PostAggregates, newtypes::PersonId, source::{ community::Community, @@ -35,7 +36,7 @@ use lemmy_db_schema::{ }, traits::{Crud, Likeable}, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyErrorType}; use url::Url; #[async_trait::async_trait] @@ -108,8 +109,10 @@ impl CreateOrUpdatePage { ) -> Result<(), LemmyError> { let post = ApubPost(post.clone()); let community_id = post.community_id; - let person: ApubPerson = Person::read(context.pool(), person_id).await?.into(); - let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into(); + let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into(); + let community: ApubCommunity = Community::read(&mut context.pool(), community_id) + .await? + .into(); let create_or_update = CreateOrUpdatePage::new(post, &person, &community, kind, context).await?; @@ -143,6 +146,7 @@ impl ActivityHandler for CreateOrUpdatePage { #[tracing::instrument(skip_all)] async fn verify(&self, context: &Data) -> Result<(), LemmyError> { + insert_received_activity(&self.id, context).await?; verify_is_public(&self.to, &self.cc)?; let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; @@ -158,7 +162,7 @@ impl ActivityHandler for CreateOrUpdatePage { // because then we will definitely receive all create and update activities separately. let is_locked = self.object.comments_enabled == Some(false); if community.local && is_locked { - return Err(LemmyError::from_message("New post cannot be locked")); + return Err(LemmyErrorType::NewPostCannotBeLocked)?; } } CreateOrUpdateType::Update => { @@ -177,7 +181,6 @@ impl ActivityHandler for CreateOrUpdatePage { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> Result<(), LemmyError> { - insert_activity(&self.id, &self, false, false, context).await?; let post = ApubPost::from_json(self.object, context).await?; // author likes their own post by default @@ -186,7 +189,11 @@ impl ActivityHandler for CreateOrUpdatePage { person_id: post.creator_id, score: 1, }; - PostLike::like(context.pool(), &like_form).await?; + PostLike::like(&mut context.pool(), &like_form).await?; + + // Calculate initial hot_rank for post + PostAggregates::update_hot_rank(&mut context.pool(), post.id).await?; + Ok(()) } }