1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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!()
}
}
|