use activitypub_federation::{ config::Data, fetch::object_id::ObjectId, kinds::activity::FollowType, traits::Activity, }; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use url::Url; use crate::{entity::user::User, error::AppError, state::AppHandle}; #[derive(Deserialize, Serialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct Follow { pub actor: ObjectId, pub object: ObjectId, #[serde(rename = "type")] kind: FollowType, id: Url, } impl Follow { pub fn new(actor: ObjectId, object: ObjectId, id: Url) -> Follow { Follow { actor, object, kind: Default::default(), id, } } } #[async_trait] impl Activity for Follow { #[doc = " App data type passed to handlers. Must be identical to"] #[doc = " [crate::config::FederationConfigBuilder::app_data] type."] type DataType = AppHandle; #[doc = " Error type returned by handler methods"] type Error = AppError; #[doc = " `id` field of the activity"] fn id(&self) -> &Url { todo!() } #[doc = " `actor` field of activity"] fn actor(&self) -> &Url { todo!() } #[doc = " Verifies that the received activity is valid."] #[doc = ""] #[doc = " This needs to be a separate method, because it might be used for activities"] #[doc = " like `Undo/Follow`, which shouldn\'t perform any database write for the inner `Follow`."] async fn verify(&self, data: &Data) -> Result<(), Self::Error> { todo!() } #[doc = " Called when an activity is received."] #[doc = ""] #[doc = " Should perform validation and possibly write action to the database. In case the activity"] #[doc = " has a nested `object` field, must call `object.from_json` handler."] async fn receive(self, data: &Data) -> Result<(), Self::Error> { todo!() } }