1 use lemmy_api_common::{blocking, community::CommunityResponse};
2 use lemmy_db_queries::source::community::Community_;
3 use lemmy_db_schema::source::community::Community;
4 use lemmy_db_views_actor::community_view::CommunityView;
5 use lemmy_utils::LemmyError;
6 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperationCrud};
8 pub(crate) async fn receive_delete_community(
9 context: &LemmyContext,
11 ) -> Result<(), LemmyError> {
12 let deleted_community = blocking(context.pool(), move |conn| {
13 Community::update_deleted(conn, community.id, true)
17 let community_id = deleted_community.id;
18 let res = CommunityResponse {
19 community_view: blocking(context.pool(), move |conn| {
20 CommunityView::read(conn, community_id, None)
25 let community_id = res.community_view.community.id;
26 context.chat_server().do_send(SendCommunityRoomMessage {
27 op: UserOperationCrud::EditCommunity,
36 pub(crate) async fn receive_remove_community(
37 context: &LemmyContext,
39 ) -> Result<(), LemmyError> {
40 let removed_community = blocking(context.pool(), move |conn| {
41 Community::update_removed(conn, community.id, true)
45 let community_id = removed_community.id;
46 let res = CommunityResponse {
47 community_view: blocking(context.pool(), move |conn| {
48 CommunityView::read(conn, community_id, None)
53 let community_id = res.community_view.community.id;
54 context.chat_server().do_send(SendCommunityRoomMessage {
55 op: UserOperationCrud::EditCommunity,
64 pub(crate) async fn receive_undo_delete_community(
65 context: &LemmyContext,
67 ) -> Result<(), LemmyError> {
68 let deleted_community = blocking(context.pool(), move |conn| {
69 Community::update_deleted(conn, community.id, false)
73 let community_id = deleted_community.id;
74 let res = CommunityResponse {
75 community_view: blocking(context.pool(), move |conn| {
76 CommunityView::read(conn, community_id, None)
81 let community_id = res.community_view.community.id;
82 context.chat_server().do_send(SendCommunityRoomMessage {
83 op: UserOperationCrud::EditCommunity,
92 pub(crate) async fn receive_undo_remove_community(
93 context: &LemmyContext,
95 ) -> Result<(), LemmyError> {
96 let removed_community = blocking(context.pool(), move |conn| {
97 Community::update_removed(conn, community.id, false)
101 let community_id = removed_community.id;
102 let res = CommunityResponse {
103 community_view: blocking(context.pool(), move |conn| {
104 CommunityView::read(conn, community_id, None)
109 let community_id = res.community_view.community.id;
111 context.chat_server().do_send(SendCommunityRoomMessage {
112 op: UserOperationCrud::EditCommunity,