-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use tracing::info;
-
-#[async_trait::async_trait(?Send)]
-pub(crate) trait GetCommunity {
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError>;
+use lemmy_api_common::context::LemmyContext;
+use lemmy_utils::error::{LemmyError, LemmyErrorType};
+use serde_json::Value;
+use url::Url;
+
+#[async_trait::async_trait]
+impl ActivityHandler for RawAnnouncableActivities {
+ type DataType = LemmyContext;
+ type Error = LemmyError;
+
+ fn id(&self) -> &Url {
+ &self.id
+ }
+
+ fn actor(&self) -> &Url {
+ &self.actor
+ }
+
+ #[tracing::instrument(skip_all)]
+ async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
+ Ok(())
+ }
+
+ #[tracing::instrument(skip_all)]
+ async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
+ let activity: AnnouncableActivities = self.clone().try_into()?;
+ // This is only for sending, not receiving so we reject it.
+ if let AnnouncableActivities::Page(_) = activity {
+ return Err(LemmyErrorType::CannotReceivePage)?;
+ }
+ let community = activity.community(data).await?;
+ let actor_id = activity.actor().clone().into();
+
+ // verify and receive activity
+ activity.verify(data).await?;
+ activity.receive(data).await?;
+
+ // send to community followers
+ if community.local {
+ verify_person_in_community(&actor_id, &community, data).await?;
+ AnnounceActivity::send(self, &community, data).await?;
+ }
+ Ok(())
+ }