3 community::{announce::GetCommunity, send_to_community},
8 verify_person_in_community,
10 activity_lists::AnnouncableActivities,
11 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::{activities::community::update::UpdateCommunity, objects::group::Group},
14 use activitystreams::{activity::kind::UpdateType, public};
15 use lemmy_api_common::blocking;
19 traits::{ActivityHandler, ActorType, ApubObject},
21 use lemmy_db_schema::{
22 source::community::{Community, CommunityForm},
25 use lemmy_utils::LemmyError;
26 use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
28 impl UpdateCommunity {
30 community: ApubCommunity,
32 context: &LemmyContext,
33 ) -> Result<(), LemmyError> {
34 let id = generate_activity_id(
36 &context.settings().get_protocol_and_hostname(),
38 let update = UpdateCommunity {
39 actor: ObjectId::new(actor.actor_id()),
41 object: community.clone().into_apub(context).await?,
42 cc: vec![community.actor_id()],
43 kind: UpdateType::Update,
45 unparsed: Default::default(),
48 let activity = AnnouncableActivities::UpdateCommunity(Box::new(update));
49 send_to_community(activity, &id, actor, &community, vec![], context).await
53 #[async_trait::async_trait(?Send)]
54 impl ActivityHandler for UpdateCommunity {
55 type DataType = LemmyContext;
58 context: &Data<LemmyContext>,
59 request_counter: &mut i32,
60 ) -> Result<(), LemmyError> {
61 verify_is_public(&self.to)?;
62 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
63 let community = self.get_community(context, request_counter).await?;
64 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
65 verify_mod_action(&self.actor, &community, context, request_counter).await?;
71 context: &Data<LemmyContext>,
72 request_counter: &mut i32,
73 ) -> Result<(), LemmyError> {
74 let community = self.get_community(context, request_counter).await?;
76 let updated_community = Group::into_form(
78 &community.actor_id.clone().into(),
82 let cf = CommunityForm {
83 name: updated_community.name,
84 title: updated_community.title,
85 description: updated_community.description,
86 nsfw: updated_community.nsfw,
87 // TODO: icon and banner would be hosted on the other instance, ideally we would copy it to ours
88 icon: updated_community.icon,
89 banner: updated_community.banner,
90 ..CommunityForm::default()
92 let updated_community = blocking(context.pool(), move |conn| {
93 Community::update(conn, community.id, &cf)
97 send_community_ws_message(
99 UserOperationCrud::EditCommunity,
109 #[async_trait::async_trait(?Send)]
110 impl GetCommunity for UpdateCommunity {
111 async fn get_community(
113 context: &LemmyContext,
114 request_counter: &mut i32,
115 ) -> Result<ApubCommunity, LemmyError> {
116 let cid = ObjectId::new(self.object.id.clone());
117 cid.dereference(context, request_counter).await