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::{community::Community, views::community_view::CommunityView, ApubObject};
8 use lemmy_structs::{blocking, community::CommunityResponse};
9 use lemmy_utils::{location_info, LemmyError};
10 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
13 pub(crate) async fn receive_delete_community(
14 context: &LemmyContext,
16 ) -> Result<(), LemmyError> {
17 let deleted_community = blocking(context.pool(), move |conn| {
18 Community::update_deleted(conn, community.id, true)
22 let community_id = deleted_community.id;
23 let res = CommunityResponse {
24 community_view: blocking(context.pool(), move |conn| {
25 CommunityView::read(conn, community_id, None)
30 let community_id = res.community_view.community.id;
31 context.chat_server().do_send(SendCommunityRoomMessage {
32 op: UserOperation::EditCommunity,
41 pub(crate) async fn receive_remove_community(
42 context: &LemmyContext,
44 expected_domain: &Url,
45 ) -> Result<(), LemmyError> {
46 let remove = Remove::from_any_base(activity)?.context(location_info!())?;
47 verify_activity_domains_valid(&remove, expected_domain, true)?;
48 is_addressed_to_public(&remove)?;
50 let community_uri = remove
54 .context(location_info!())?;
55 let community = blocking(context.pool(), move |conn| {
56 Community::read_from_apub_id(conn, community_uri.as_str())
60 let removed_community = blocking(context.pool(), move |conn| {
61 Community::update_removed(conn, community.id, true)
65 let community_id = removed_community.id;
66 let res = CommunityResponse {
67 community_view: blocking(context.pool(), move |conn| {
68 CommunityView::read(conn, community_id, None)
73 let community_id = res.community_view.community.id;
74 context.chat_server().do_send(SendCommunityRoomMessage {
75 op: UserOperation::EditCommunity,
84 pub(crate) async fn receive_undo_delete_community(
85 context: &LemmyContext,
88 expected_domain: &Url,
89 ) -> Result<(), LemmyError> {
90 is_addressed_to_public(&undo)?;
91 let inner = undo.object().to_owned().one().context(location_info!())?;
92 let delete = Delete::from_any_base(inner)?.context(location_info!())?;
93 verify_activity_domains_valid(&delete, expected_domain, true)?;
94 is_addressed_to_public(&delete)?;
96 let deleted_community = blocking(context.pool(), move |conn| {
97 Community::update_deleted(conn, community.id, false)
101 let community_id = deleted_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;
110 context.chat_server().do_send(SendCommunityRoomMessage {
111 op: UserOperation::EditCommunity,
120 pub(crate) async fn receive_undo_remove_community(
121 context: &LemmyContext,
123 expected_domain: &Url,
124 ) -> Result<(), LemmyError> {
125 is_addressed_to_public(&undo)?;
127 let inner = undo.object().to_owned().one().context(location_info!())?;
128 let remove = Remove::from_any_base(inner)?.context(location_info!())?;
129 verify_activity_domains_valid(&remove, &expected_domain, true)?;
130 is_addressed_to_public(&remove)?;
132 let community_uri = remove
135 .single_xsd_any_uri()
136 .context(location_info!())?;
137 let community = blocking(context.pool(), move |conn| {
138 Community::read_from_apub_id(conn, community_uri.as_str())
142 let removed_community = blocking(context.pool(), move |conn| {
143 Community::update_removed(conn, community.id, false)
147 let community_id = removed_community.id;
148 let res = CommunityResponse {
149 community_view: blocking(context.pool(), move |conn| {
150 CommunityView::read(conn, community_id, None)
155 let community_id = res.community_view.community.id;
157 context.chat_server().do_send(SendCommunityRoomMessage {
158 op: UserOperation::EditCommunity,