1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 community::{CommunityResponse, DeleteCommunity},
5 utils::get_local_user_view_from_jwt,
6 websocket::{send::send_community_ws_message, UserOperationCrud},
9 use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
10 use lemmy_db_schema::{
11 source::community::{Community, CommunityUpdateForm},
14 use lemmy_db_views_actor::structs::CommunityModeratorView;
15 use lemmy_utils::{error::LemmyError, ConnectionId};
17 #[async_trait::async_trait(?Send)]
18 impl PerformCrud for DeleteCommunity {
19 type Response = CommunityResponse;
21 #[tracing::instrument(skip(context, websocket_id))]
24 context: &Data<LemmyContext>,
25 websocket_id: Option<ConnectionId>,
26 ) -> Result<CommunityResponse, LemmyError> {
27 let data: &DeleteCommunity = self;
29 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
31 // Fetch the community mods
32 let community_id = data.community_id;
34 CommunityModeratorView::for_community(context.pool(), community_id).await?;
36 // Make sure deleter is the top mod
37 if local_user_view.person.id != community_mods[0].moderator.id {
38 return Err(LemmyError::from_message("no_community_edit_allowed"));
42 let community_id = data.community_id;
43 let deleted = data.deleted;
44 let updated_community = Community::update(
47 &CommunityUpdateForm::builder()
48 .deleted(Some(deleted))
52 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
54 let res = send_community_ws_message(
56 UserOperationCrud::DeleteCommunity,
58 Some(local_user_view.person.id),
64 let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
65 send_apub_delete_in_community(
66 local_user_view.person,