2022-06-02 16:47:12 +05:30
|
|
|
use crate::{
|
2023-02-11 18:02:35 +05:30
|
|
|
instance::DatabaseHandle,
|
2023-02-19 17:56:01 +05:30
|
|
|
objects::{person::DbUser, post::Note},
|
|
|
|
DbPost,
|
2022-06-02 16:47:12 +05:30
|
|
|
};
|
|
|
|
use activitypub_federation::{
|
2023-03-16 06:41:48 +05:30
|
|
|
config::Data,
|
2023-03-06 06:47:34 +05:30
|
|
|
fetch::object_id::ObjectId,
|
2023-02-19 17:56:01 +05:30
|
|
|
kinds::activity::CreateType,
|
|
|
|
protocol::helpers::deserialize_one_or_many,
|
2023-03-17 02:11:29 +05:30
|
|
|
traits::{ActivityHandler, Object},
|
2022-06-02 16:47:12 +05:30
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2023-03-08 03:31:36 +05:30
|
|
|
pub struct CreatePost {
|
2023-02-19 17:56:01 +05:30
|
|
|
pub(crate) actor: ObjectId<DbUser>,
|
2022-06-02 16:47:12 +05:30
|
|
|
#[serde(deserialize_with = "deserialize_one_or_many")]
|
|
|
|
pub(crate) to: Vec<Url>,
|
|
|
|
pub(crate) object: Note,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub(crate) kind: CreateType,
|
|
|
|
pub(crate) id: Url,
|
|
|
|
}
|
|
|
|
|
2023-03-08 03:31:36 +05:30
|
|
|
impl CreatePost {
|
|
|
|
pub fn new(note: Note, id: Url) -> CreatePost {
|
|
|
|
CreatePost {
|
2022-06-02 16:47:12 +05:30
|
|
|
actor: note.attributed_to.clone(),
|
|
|
|
to: note.to.clone(),
|
|
|
|
object: note,
|
|
|
|
kind: CreateType::Create,
|
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 02:49:56 +05:30
|
|
|
#[async_trait::async_trait]
|
2023-03-08 03:31:36 +05:30
|
|
|
impl ActivityHandler for CreatePost {
|
2023-02-11 18:02:35 +05:30
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2023-03-16 06:41:48 +05:30
|
|
|
async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
2023-03-10 02:39:44 +05:30
|
|
|
DbPost::verify(&self.object, &self.id, data).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-03-16 06:41:48 +05:30
|
|
|
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
2023-03-17 02:11:29 +05:30
|
|
|
DbPost::from_json(self.object, data).await?;
|
2022-06-02 16:47:12 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|