3 community::send_activity_in_community,
7 verify_person_in_community,
9 activity_lists::AnnouncableActivities,
10 objects::{community::ApubCommunity, person::ApubPerson},
11 protocol::{activities::community::update::UpdateCommunity, InCommunity},
14 use activitypub_federation::{
15 core::object_id::ObjectId,
17 traits::{ActivityHandler, ApubObject},
19 use activitystreams_kinds::{activity::UpdateType, public};
20 use lemmy_db_schema::{source::community::Community, traits::Crud};
21 use lemmy_utils::error::LemmyError;
22 use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
25 impl UpdateCommunity {
26 #[tracing::instrument(skip_all)]
28 community: ApubCommunity,
30 context: &LemmyContext,
31 ) -> Result<(), LemmyError> {
32 let id = generate_activity_id(
34 &context.settings().get_protocol_and_hostname(),
36 let update = UpdateCommunity {
37 actor: ObjectId::new(actor.actor_id()),
39 object: Box::new(community.clone().into_apub(context).await?),
40 cc: vec![community.actor_id()],
41 kind: UpdateType::Update,
43 audience: Some(ObjectId::new(community.actor_id())),
46 let activity = AnnouncableActivities::UpdateCommunity(update);
47 send_activity_in_community(activity, actor, &community, vec![], true, context).await
51 #[async_trait::async_trait(?Send)]
52 impl ActivityHandler for UpdateCommunity {
53 type DataType = LemmyContext;
54 type Error = LemmyError;
56 fn id(&self) -> &Url {
60 fn actor(&self) -> &Url {
64 #[tracing::instrument(skip_all)]
67 context: &Data<LemmyContext>,
68 request_counter: &mut i32,
69 ) -> Result<(), LemmyError> {
70 verify_is_public(&self.to, &self.cc)?;
71 let community = self.community(context, request_counter).await?;
72 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
75 self.object.id.inner(),
81 ApubCommunity::verify(
83 &community.actor_id.clone().into(),
91 #[tracing::instrument(skip_all)]
94 context: &Data<LemmyContext>,
95 request_counter: &mut i32,
96 ) -> Result<(), LemmyError> {
97 let community = self.community(context, request_counter).await?;
99 let community_update_form = self.object.into_update_form();
101 let updated_community =
102 Community::update(context.pool(), community.id, &community_update_form).await?;
104 send_community_ws_message(
105 updated_community.id,
106 UserOperationCrud::EditCommunity,