activitypub-federation-rust/examples/local_federation/activities/accept.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

use crate::{activities::follow::Follow, instance::DatabaseHandle, objects::person::DbUser};
use activitypub_federation::{
config::Data,
fetch::object_id::ObjectId,
kinds::activity::AcceptType,
traits::ActivityHandler,
};
2022-06-02 16:47:12 +05:30
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Accept {
actor: ObjectId<DbUser>,
2022-06-02 16:47:12 +05:30
object: Follow,
#[serde(rename = "type")]
kind: AcceptType,
id: Url,
}
impl Accept {
pub fn new(actor: ObjectId<DbUser>, object: Follow, id: Url) -> Accept {
2022-06-02 16:47:12 +05:30
Accept {
actor,
object,
kind: Default::default(),
id,
}
}
}
#[async_trait::async_trait]
2022-06-02 16:47:12 +05:30
impl ActivityHandler for Accept {
type DataType = DatabaseHandle;
2022-06-02 16:47:12 +05:30
type Error = crate::error::Error;
fn id(&self) -> &Url {
&self.id
}
fn actor(&self) -> &Url {
self.actor.inner()
}
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
Ok(())
}
async fn receive(self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
2022-06-02 16:47:12 +05:30
Ok(())
}
}