1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 community::{CommunityResponse, DeleteCommunity},
6 utils::{is_top_mod, local_user_view_from_jwt},
7 websocket::UserOperationCrud,
10 source::community::{Community, CommunityUpdateForm},
13 use lemmy_db_views_actor::structs::CommunityModeratorView;
14 use lemmy_utils::{error::LemmyError, ConnectionId};
16 #[async_trait::async_trait(?Send)]
17 impl PerformCrud for DeleteCommunity {
18 type Response = CommunityResponse;
20 #[tracing::instrument(skip(context, websocket_id))]
23 context: &Data<LemmyContext>,
24 websocket_id: Option<ConnectionId>,
25 ) -> Result<CommunityResponse, LemmyError> {
26 let data: &DeleteCommunity = self;
27 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
29 // Fetch the community mods
30 let community_id = data.community_id;
32 CommunityModeratorView::for_community(context.pool(), community_id).await?;
34 // Make sure deleter is the top mod
35 is_top_mod(&local_user_view, &community_mods)?;
38 let community_id = data.community_id;
39 let deleted = data.deleted;
43 &CommunityUpdateForm::builder()
44 .deleted(Some(deleted))
48 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
51 .send_community_ws_message(
52 &UserOperationCrud::DeleteCommunity,
55 Some(local_user_view.person.id),