From 0a3040fba40d42c62ea70b7ccbade28e43ebaad5 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Wed, 16 Jul 2025 18:04:10 +0200 Subject: feat: follow activity --- src/server/activities.rs | 1 + src/server/activities/follow.rs | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/server/activities.rs create mode 100644 src/server/activities/follow.rs diff --git a/src/server/activities.rs b/src/server/activities.rs new file mode 100644 index 0000000..62d6fa2 --- /dev/null +++ b/src/server/activities.rs @@ -0,0 +1 @@ +pub mod follow; diff --git a/src/server/activities/follow.rs b/src/server/activities/follow.rs new file mode 100644 index 0000000..9148f02 --- /dev/null +++ b/src/server/activities/follow.rs @@ -0,0 +1,65 @@ +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!() + } +} -- cgit v1.2.3