use crate::{
- activities::{verify_activity, verify_mod_action, verify_person_in_community},
- objects::community::Group,
+ activities::{
+ community::announce::AnnouncableActivities,
+ generate_activity_id,
+ verify_activity,
+ verify_mod_action,
+ verify_person_in_community,
+ },
+ activity_queue::send_to_community_new,
+ extensions::context::lemmy_context,
+ objects::{community::Group, ToApub},
+ ActorType,
+};
+use activitystreams::{
+ activity::kind::UpdateType,
+ base::AnyBase,
+ primitives::OneOrMany,
+ unparsed::Unparsed,
};
-use activitystreams::activity::kind::UpdateType;
use lemmy_api_common::blocking;
-use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
+use lemmy_apub_lib::{values::PublicUrl, ActivityFields, ActivityHandler};
use lemmy_db_queries::{ApubObject, Crud};
-use lemmy_db_schema::source::community::{Community, CommunityForm};
+use lemmy_db_schema::source::{
+ community::{Community, CommunityForm},
+ person::Person,
+};
use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
+use serde::{Deserialize, Serialize};
use url::Url;
/// This activity is received from a remote community mod, and updates the description or other
/// fields of a local community.
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UpdateCommunity {
+ actor: Url,
to: PublicUrl,
+ // TODO: would be nice to use a separate struct here, which only contains the fields updated here
object: Group,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UpdateType,
+ id: Url,
+ #[serde(rename = "@context")]
+ context: OneOrMany<AnyBase>,
#[serde(flatten)]
- common: ActivityCommonFields,
+ unparsed: Unparsed,
+}
+
+impl UpdateCommunity {
+ pub async fn send(
+ community: &Community,
+ actor: &Person,
+ context: &LemmyContext,
+ ) -> Result<(), LemmyError> {
+ let id = generate_activity_id(UpdateType::Update)?;
+ let update = UpdateCommunity {
+ actor: actor.actor_id(),
+ to: PublicUrl::Public,
+ object: community.to_apub(context.pool()).await?,
+ cc: [community.actor_id()],
+ kind: UpdateType::Update,
+ id: id.clone(),
+ context: lemmy_context(),
+ unparsed: Default::default(),
+ };
+
+ let activity = AnnouncableActivities::UpdateCommunity(Box::new(update));
+ send_to_community_new(activity, &id, actor, community, vec![], context).await
+ }
}
#[async_trait::async_trait(?Send)]
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- verify_activity(self.common())?;
- verify_person_in_community(&self.common.actor, &self.cc[0], context, request_counter).await?;
- verify_mod_action(&self.common.actor, self.cc[0].clone(), context).await?;
+ verify_activity(self)?;
+ verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
+ verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
Ok(())
}
.await?;
Ok(())
}
-
- fn common(&self) -> &ActivityCommonFields {
- &self.common
- }
}