2 activities::{verify_activity, verify_mod_action, verify_person_in_community},
3 objects::community::Group,
5 use activitystreams::activity::kind::UpdateType;
6 use lemmy_api_common::blocking;
7 use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
8 use lemmy_db_queries::{ApubObject, Crud};
9 use lemmy_db_schema::source::community::{Community, CommunityForm};
10 use lemmy_utils::LemmyError;
11 use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
14 /// This activity is received from a remote community mod, and updates the description or other
15 /// fields of a local community.
16 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
17 #[serde(rename_all = "camelCase")]
18 pub struct UpdateCommunity {
22 #[serde(rename = "type")]
25 common: ActivityCommonFields,
28 #[async_trait::async_trait(?Send)]
29 impl ActivityHandler for UpdateCommunity {
32 context: &LemmyContext,
33 request_counter: &mut i32,
34 ) -> Result<(), LemmyError> {
35 verify_activity(self.common())?;
36 verify_person_in_community(&self.common.actor, &self.cc[0], context, request_counter).await?;
37 verify_mod_action(&self.common.actor, self.cc[0].clone(), context).await?;
43 context: &LemmyContext,
44 _request_counter: &mut i32,
45 ) -> Result<(), LemmyError> {
46 let cc = self.cc[0].clone().into();
47 let community = blocking(context.pool(), move |conn| {
48 Community::read_from_apub_id(conn, &cc)
52 let updated_community =
53 Group::from_apub_to_form(&self.object, &community.actor_id.clone().into()).await?;
54 let cf = CommunityForm {
55 name: updated_community.name,
56 title: updated_community.title,
57 description: updated_community.description,
58 nsfw: updated_community.nsfw,
59 // TODO: icon and banner would be hosted on the other instance, ideally we would copy it to ours
60 icon: updated_community.icon,
61 banner: updated_community.banner,
62 ..CommunityForm::default()
64 let updated_community = blocking(context.pool(), move |conn| {
65 Community::update(conn, community.id, &cf)
69 send_community_ws_message(
71 UserOperationCrud::EditCommunity,
80 fn common(&self) -> &ActivityCommonFields {