summaryrefslogtreecommitdiffstats
path: root/src/server/activities/follow.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/activities/follow.rs')
-rw-r--r--src/server/activities/follow.rs65
1 files changed, 65 insertions, 0 deletions
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<User>,
+ pub object: ObjectId<User>,
+ #[serde(rename = "type")]
+ kind: FollowType,
+ id: Url,
+}
+
+impl Follow {
+ pub fn new(actor: ObjectId<User>, object: ObjectId<User>, 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<Self::DataType>) -> 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<Self::DataType>) -> Result<(), Self::Error> {
+ todo!()
+ }
+}