3 community::send_activity_in_community,
5 verify_add_remove_moderator_target,
8 verify_person_in_community,
10 activity_lists::AnnouncableActivities,
12 objects::{community::ApubCommunity, person::ApubPerson},
13 protocol::{activities::community::remove_mod::RemoveMod, InCommunity},
16 use activitypub_federation::{
17 core::object_id::ObjectId,
19 traits::{ActivityHandler, Actor},
21 use activitystreams_kinds::{activity::RemoveType, public};
22 use lemmy_api_common::{generate_moderators_url, LemmyContext};
23 use lemmy_db_schema::{
25 community::{CommunityModerator, CommunityModeratorForm},
26 moderator::{ModAddCommunity, ModAddCommunityForm},
28 traits::{Crud, Joinable},
30 use lemmy_utils::error::LemmyError;
34 #[tracing::instrument(skip_all)]
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 audience: Some(ObjectId::new(community.actor_id())),
56 let activity = AnnouncableActivities::RemoveMod(remove);
57 let inboxes = vec![removed_mod.shared_inbox_or_inbox()];
58 send_activity_in_community(activity, actor, community, inboxes, true, context).await
62 #[async_trait::async_trait(?Send)]
63 impl ActivityHandler for RemoveMod {
64 type DataType = LemmyContext;
65 type Error = LemmyError;
67 fn id(&self) -> &Url {
71 fn actor(&self) -> &Url {
75 #[tracing::instrument(skip_all)]
78 context: &Data<LemmyContext>,
79 request_counter: &mut i32,
80 ) -> Result<(), LemmyError> {
81 verify_is_public(&self.to, &self.cc)?;
82 let community = self.community(context, request_counter).await?;
83 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
92 verify_add_remove_moderator_target(&self.target, &community)?;
96 #[tracing::instrument(skip_all)]
99 context: &Data<LemmyContext>,
100 request_counter: &mut i32,
101 ) -> Result<(), LemmyError> {
102 let community = self.community(context, request_counter).await?;
103 let remove_mod = self
105 .dereference(context, local_instance(context).await, request_counter)
108 let form = CommunityModeratorForm {
109 community_id: community.id,
110 person_id: remove_mod.id,
112 CommunityModerator::leave(context.pool(), &form).await?;
117 .dereference(context, local_instance(context).await, request_counter)
119 let form = ModAddCommunityForm {
120 mod_person_id: actor.id,
121 other_person_id: remove_mod.id,
122 community_id: community.id,
125 ModAddCommunity::create(context.pool(), &form).await?;
127 // TODO: send websocket notification about removed mod