X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapub%2Fsrc%2Factivities%2Fcommunity%2Fcollection_add.rs;h=c36a8f0dafc0a3f75dec9596af783bead92cd743;hb=e9e76549a88cfbdab36f00d302cceabcaaa24f4c;hp=dfab0baf6637c18f4325f29b4cb00d2969af2454;hpb=6f513793cbd8e7427812638335b55dbb0547ffec;p=lemmy.git diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index dfab0baf..c36a8f0d 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -7,14 +7,10 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - insert_activity, + insert_received_activity, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::{ - activities::{ - community::{collection_add::CollectionAdd, collection_remove::CollectionRemove}, - create_or_update::page::CreateOrUpdatePage, - CreateOrUpdateType, - }, + activities::community::{collection_add::CollectionAdd, collection_remove::CollectionRemove}, InCommunity, }, SendActivity, @@ -29,7 +25,7 @@ use lemmy_api_common::{ community::{AddModToCommunity, AddModToCommunityResponse}, context::LemmyContext, post::{FeaturePost, PostResponse}, - utils::{generate_featured_url, generate_moderators_url, get_local_user_view_from_jwt}, + utils::{generate_featured_url, generate_moderators_url, local_user_view_from_jwt}, }; use lemmy_db_schema::{ impls::community::CollectionType, @@ -112,6 +108,7 @@ impl ActivityHandler for CollectionAdd { #[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?; @@ -121,9 +118,8 @@ impl ActivityHandler for CollectionAdd { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> Result<(), LemmyError> { - insert_activity(&self.id, &self, false, false, context).await?; let (community, collection_type) = - Community::get_by_collection_url(context.pool(), &self.target.into()).await?; + Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?; match collection_type { CollectionType::Moderators => { let new_mod = ObjectId::::from(self.object) @@ -134,13 +130,14 @@ impl ActivityHandler for CollectionAdd { // been added. Skip it here as it would result in a duplicate key error. let new_mod_id = new_mod.id; let moderated_communities = - CommunityModerator::get_person_moderated_communities(context.pool(), new_mod_id).await?; + CommunityModerator::get_person_moderated_communities(&mut context.pool(), new_mod_id) + .await?; if !moderated_communities.contains(&community.id) { let form = CommunityModeratorForm { community_id: community.id, person_id: new_mod.id, }; - CommunityModerator::join(context.pool(), &form).await?; + CommunityModerator::join(&mut context.pool(), &form).await?; // write mod log let actor = self.actor.dereference(context).await?; @@ -150,7 +147,7 @@ impl ActivityHandler for CollectionAdd { community_id: community.id, removed: Some(false), }; - ModAddCommunity::create(context.pool(), &form).await?; + ModAddCommunity::create(&mut context.pool(), &form).await?; } // TODO: send websocket notification about added mod } @@ -161,7 +158,7 @@ impl ActivityHandler for CollectionAdd { let form = PostUpdateForm::builder() .featured_community(Some(true)) .build(); - Post::update(context.pool(), post.id, &form).await?; + Post::update(&mut context.pool(), post.id, &form).await?; } } Ok(()) @@ -177,12 +174,11 @@ impl SendActivity for AddModToCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; - let community: ApubCommunity = Community::read(context.pool(), request.community_id) + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; + let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id) .await? .into(); - let updated_mod: ApubPerson = Person::read(context.pool(), request.person_id) + let updated_mod: ApubPerson = Person::read(&mut context.pool(), request.person_id) .await? .into(); if request.added { @@ -214,17 +210,8 @@ impl SendActivity for FeaturePost { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; - // Deprecated, for backwards compatibility with 0.17 - CreateOrUpdatePage::send( - &response.post_view.post, - local_user_view.person.id, - CreateOrUpdateType::Update, - context, - ) - .await?; - let community = Community::read(context.pool(), response.post_view.community.id) + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; + let community = Community::read(&mut context.pool(), response.post_view.community.id) .await? .into(); let post = response.post_view.post.clone().into();