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},
post::{CreatePost, EditPost, PostResponse},
};
use lemmy_db_schema::{
+ aggregates::structs::PostAggregates,
newtypes::PersonId,
source::{
community::Community,
},
traits::{Crud, Likeable},
};
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorType};
use url::Url;
#[async_trait::async_trait]
) -> 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?;
#[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<LemmyContext>) -> 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?;
// 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 => {
#[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> 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
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(())
}
}