3 community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
6 verify_add_remove_moderator_target,
9 verify_person_in_community,
11 activity_lists::AnnouncableActivities,
12 generate_moderators_url,
13 objects::{community::ApubCommunity, person::ApubPerson},
14 protocol::activities::community::remove_mod::RemoveMod,
16 use activitystreams::{activity::kind::RemoveType, public};
17 use lemmy_api_common::blocking;
21 traits::{ActivityHandler, ActorType},
23 use lemmy_db_schema::{
24 source::community::{CommunityModerator, CommunityModeratorForm},
27 use lemmy_utils::LemmyError;
28 use lemmy_websocket::LemmyContext;
32 community: &ApubCommunity,
33 removed_mod: &ApubPerson,
35 context: &LemmyContext,
36 ) -> Result<(), LemmyError> {
37 let id = generate_activity_id(
39 &context.settings().get_protocol_and_hostname(),
41 let remove = RemoveMod {
42 actor: ObjectId::new(actor.actor_id()),
44 object: ObjectId::new(removed_mod.actor_id()),
45 target: generate_moderators_url(&community.actor_id)?.into(),
47 cc: vec![community.actor_id()],
48 kind: RemoveType::Remove,
49 unparsed: Default::default(),
52 let activity = AnnouncableActivities::RemoveMod(remove);
53 let inboxes = vec![removed_mod.shared_inbox_or_inbox_url()];
54 send_to_community(activity, &id, actor, community, inboxes, context).await
58 #[async_trait::async_trait(?Send)]
59 impl ActivityHandler for RemoveMod {
60 type DataType = LemmyContext;
63 context: &Data<LemmyContext>,
64 request_counter: &mut i32,
65 ) -> Result<(), LemmyError> {
66 verify_is_public(&self.to)?;
67 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
68 let community = self.get_community(context, request_counter).await?;
69 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
70 verify_mod_action(&self.actor, &community, context, request_counter).await?;
71 verify_add_remove_moderator_target(&self.target, &community)?;
77 context: &Data<LemmyContext>,
78 request_counter: &mut i32,
79 ) -> Result<(), LemmyError> {
80 let community = self.get_community(context, request_counter).await?;
81 let remove_mod = self.object.dereference(context, request_counter).await?;
83 let form = CommunityModeratorForm {
84 community_id: community.id,
85 person_id: remove_mod.id,
87 blocking(context.pool(), move |conn| {
88 CommunityModerator::leave(conn, &form)
91 // TODO: send websocket notification about removed mod
96 #[async_trait::async_trait(?Send)]
97 impl GetCommunity for RemoveMod {
98 async fn get_community(
100 context: &LemmyContext,
101 request_counter: &mut i32,
102 ) -> Result<ApubCommunity, LemmyError> {
103 get_community_from_moderators_url(&self.target, context, request_counter).await