1 use crate::{activities::receive::verify_activity_domains_valid, inbox::is_addressed_to_public};
3 activity::{ActorAndObjectRefExt, Delete, Remove, Undo},
4 base::{AnyBase, ExtendsExt},
7 use lemmy_db_queries::{source::community::Community_, ApubObject};
8 use lemmy_db_schema::source::community::Community;
9 use lemmy_db_views_actor::community_view::CommunityView;
10 use lemmy_structs::{blocking, community::CommunityResponse};
11 use lemmy_utils::{location_info, LemmyError};
12 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
15 pub(crate) async fn receive_delete_community(
16 context: &LemmyContext,
18 ) -> Result<(), LemmyError> {
19 let deleted_community = blocking(context.pool(), move |conn| {
20 Community::update_deleted(conn, community.id, true)
24 let community_id = deleted_community.id;
25 let res = CommunityResponse {
26 community_view: blocking(context.pool(), move |conn| {
27 CommunityView::read(conn, community_id, None)
32 let community_id = res.community_view.community.id;
33 context.chat_server().do_send(SendCommunityRoomMessage {
34 op: UserOperation::EditCommunity,
43 pub(crate) async fn receive_remove_community(
44 context: &LemmyContext,
46 expected_domain: &Url,
47 ) -> Result<(), LemmyError> {
48 let remove = Remove::from_any_base(activity)?.context(location_info!())?;
49 verify_activity_domains_valid(&remove, expected_domain, true)?;
50 is_addressed_to_public(&remove)?;
52 let community_uri = remove
56 .context(location_info!())?;
57 let community = blocking(context.pool(), move |conn| {
58 Community::read_from_apub_id(conn, community_uri.as_str())
62 let removed_community = blocking(context.pool(), move |conn| {
63 Community::update_removed(conn, community.id, true)
67 let community_id = removed_community.id;
68 let res = CommunityResponse {
69 community_view: blocking(context.pool(), move |conn| {
70 CommunityView::read(conn, community_id, None)
75 let community_id = res.community_view.community.id;
76 context.chat_server().do_send(SendCommunityRoomMessage {
77 op: UserOperation::EditCommunity,
86 pub(crate) async fn receive_undo_delete_community(
87 context: &LemmyContext,
90 expected_domain: &Url,
91 ) -> Result<(), LemmyError> {
92 is_addressed_to_public(&undo)?;
93 let inner = undo.object().to_owned().one().context(location_info!())?;
94 let delete = Delete::from_any_base(inner)?.context(location_info!())?;
95 verify_activity_domains_valid(&delete, expected_domain, true)?;
96 is_addressed_to_public(&delete)?;
98 let deleted_community = blocking(context.pool(), move |conn| {
99 Community::update_deleted(conn, community.id, false)
103 let community_id = deleted_community.id;
104 let res = CommunityResponse {
105 community_view: blocking(context.pool(), move |conn| {
106 CommunityView::read(conn, community_id, None)
111 let community_id = res.community_view.community.id;
112 context.chat_server().do_send(SendCommunityRoomMessage {
113 op: UserOperation::EditCommunity,
122 pub(crate) async fn receive_undo_remove_community(
123 context: &LemmyContext,
125 expected_domain: &Url,
126 ) -> Result<(), LemmyError> {
127 is_addressed_to_public(&undo)?;
129 let inner = undo.object().to_owned().one().context(location_info!())?;
130 let remove = Remove::from_any_base(inner)?.context(location_info!())?;
131 verify_activity_domains_valid(&remove, &expected_domain, true)?;
132 is_addressed_to_public(&remove)?;
134 let community_uri = remove
137 .single_xsd_any_uri()
138 .context(location_info!())?;
139 let community = blocking(context.pool(), move |conn| {
140 Community::read_from_apub_id(conn, community_uri.as_str())
144 let removed_community = blocking(context.pool(), move |conn| {
145 Community::update_removed(conn, community.id, false)
149 let community_id = removed_community.id;
150 let res = CommunityResponse {
151 community_view: blocking(context.pool(), move |conn| {
152 CommunityView::read(conn, community_id, None)
157 let community_id = res.community_view.community.id;
159 context.chat_server().do_send(SendCommunityRoomMessage {
160 op: UserOperation::EditCommunity,