1 use activitypub_federation::config::Data;
2 use actix_web::web::Json;
3 use lemmy_api_common::{
4 build_response::build_community_response,
5 community::{CommunityResponse, DeleteCommunity},
7 send_activity::{ActivityChannel, SendActivityData},
8 utils::{is_top_mod, local_user_view_from_jwt},
10 use lemmy_db_schema::{
11 source::community::{Community, CommunityUpdateForm},
14 use lemmy_db_views_actor::structs::CommunityModeratorView;
15 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
17 #[tracing::instrument(skip(context))]
18 pub async fn delete_community(
19 data: Json<DeleteCommunity>,
20 context: Data<LemmyContext>,
21 ) -> Result<Json<CommunityResponse>, LemmyError> {
22 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
24 // Fetch the community mods
25 let community_id = data.community_id;
27 CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
29 // Make sure deleter is the top mod
30 is_top_mod(&local_user_view, &community_mods)?;
33 let community_id = data.community_id;
34 let deleted = data.deleted;
35 let community = Community::update(
38 &CommunityUpdateForm {
39 deleted: Some(deleted),
44 .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
46 ActivityChannel::submit_activity(
47 SendActivityData::DeleteCommunity(local_user_view.person.clone(), community, data.deleted),
52 build_community_response(&context, local_user_view, community_id).await