3 community::send_activity_in_community,
5 verify_add_remove_moderator_target,
8 verify_person_in_community,
10 activity_lists::AnnouncableActivities,
11 generate_moderators_url,
13 objects::{community::ApubCommunity, person::ApubPerson},
14 protocol::{activities::community::remove_mod::RemoveMod, InCommunity},
17 use activitypub_federation::{
18 core::object_id::ObjectId,
20 traits::{ActivityHandler, Actor},
22 use activitystreams_kinds::{activity::RemoveType, public};
23 use lemmy_api_common::LemmyContext;
24 use lemmy_db_schema::{
26 community::{CommunityModerator, CommunityModeratorForm},
27 moderator::{ModAddCommunity, ModAddCommunityForm},
29 traits::{Crud, Joinable},
31 use lemmy_utils::error::LemmyError;
35 #[tracing::instrument(skip_all)]
37 community: &ApubCommunity,
38 removed_mod: &ApubPerson,
40 context: &LemmyContext,
41 ) -> Result<(), LemmyError> {
42 let id = generate_activity_id(
44 &context.settings().get_protocol_and_hostname(),
46 let remove = RemoveMod {
47 actor: ObjectId::new(actor.actor_id()),
49 object: ObjectId::new(removed_mod.actor_id()),
50 target: generate_moderators_url(&community.actor_id)?.into(),
52 cc: vec![community.actor_id()],
53 kind: RemoveType::Remove,
54 audience: Some(ObjectId::new(community.actor_id())),
57 let activity = AnnouncableActivities::RemoveMod(remove);
58 let inboxes = vec![removed_mod.shared_inbox_or_inbox()];
59 send_activity_in_community(activity, actor, community, inboxes, true, context).await
63 #[async_trait::async_trait(?Send)]
64 impl ActivityHandler for RemoveMod {
65 type DataType = LemmyContext;
66 type Error = LemmyError;
68 fn id(&self) -> &Url {
72 fn actor(&self) -> &Url {
76 #[tracing::instrument(skip_all)]
79 context: &Data<LemmyContext>,
80 request_counter: &mut i32,
81 ) -> Result<(), LemmyError> {
82 verify_is_public(&self.to, &self.cc)?;
83 let community = self.community(context, request_counter).await?;
84 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
93 verify_add_remove_moderator_target(&self.target, &community)?;
97 #[tracing::instrument(skip_all)]
100 context: &Data<LemmyContext>,
101 request_counter: &mut i32,
102 ) -> Result<(), LemmyError> {
103 let community = self.community(context, request_counter).await?;
104 let remove_mod = self
106 .dereference(context, local_instance(context).await, request_counter)
109 let form = CommunityModeratorForm {
110 community_id: community.id,
111 person_id: remove_mod.id,
113 CommunityModerator::leave(context.pool(), &form).await?;
118 .dereference(context, local_instance(context).await, request_counter)
120 let form = ModAddCommunityForm {
121 mod_person_id: actor.id,
122 other_person_id: remove_mod.id,
123 community_id: community.id,
126 ModAddCommunity::create(context.pool(), &form).await?;
128 // TODO: send websocket notification about removed mod