4 announce::GetCommunity,
5 get_community_from_moderators_url,
6 send_activity_in_community,
10 verify_add_remove_moderator_target,
13 verify_person_in_community,
15 activity_lists::AnnouncableActivities,
16 generate_moderators_url,
17 objects::{community::ApubCommunity, person::ApubPerson},
18 protocol::activities::community::remove_mod::RemoveMod,
20 use activitystreams_kinds::{activity::RemoveType, public};
21 use lemmy_api_common::blocking;
25 traits::{ActivityHandler, ActorType},
27 use lemmy_db_schema::{
28 source::community::{CommunityModerator, CommunityModeratorForm},
31 use lemmy_utils::LemmyError;
32 use lemmy_websocket::LemmyContext;
36 community: &ApubCommunity,
37 removed_mod: &ApubPerson,
39 context: &LemmyContext,
40 ) -> Result<(), LemmyError> {
41 let id = generate_activity_id(
43 &context.settings().get_protocol_and_hostname(),
45 let remove = RemoveMod {
46 actor: ObjectId::new(actor.actor_id()),
48 object: ObjectId::new(removed_mod.actor_id()),
49 target: generate_moderators_url(&community.actor_id)?.into(),
51 cc: vec![community.actor_id()],
52 kind: RemoveType::Remove,
53 unparsed: Default::default(),
56 let activity = AnnouncableActivities::RemoveMod(remove);
57 let inboxes = vec![removed_mod.shared_inbox_or_inbox_url()];
58 send_activity_in_community(activity, &id, actor, community, inboxes, context).await
62 #[async_trait::async_trait(?Send)]
63 impl ActivityHandler for RemoveMod {
64 type DataType = LemmyContext;
67 context: &Data<LemmyContext>,
68 request_counter: &mut i32,
69 ) -> Result<(), LemmyError> {
70 verify_is_public(&self.to, &self.cc)?;
71 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
72 let community = self.get_community(context, request_counter).await?;
73 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
74 verify_mod_action(&self.actor, &community, context, request_counter).await?;
75 verify_add_remove_moderator_target(&self.target, &community)?;
81 context: &Data<LemmyContext>,
82 request_counter: &mut i32,
83 ) -> Result<(), LemmyError> {
84 let community = self.get_community(context, request_counter).await?;
85 let remove_mod = self.object.dereference(context, request_counter).await?;
87 let form = CommunityModeratorForm {
88 community_id: community.id,
89 person_id: remove_mod.id,
91 blocking(context.pool(), move |conn| {
92 CommunityModerator::leave(conn, &form)
95 // TODO: send websocket notification about removed mod
100 #[async_trait::async_trait(?Send)]
101 impl GetCommunity for RemoveMod {
102 async fn get_community(
104 context: &LemmyContext,
105 request_counter: &mut i32,
106 ) -> Result<ApubCommunity, LemmyError> {
107 get_community_from_moderators_url(&self.target, context, request_counter).await