2018-12-29 09:36:07 +01:00
|
|
|
use activitypub::{activity::Create, Error as ApError, Object};
|
2018-06-23 18:36:11 +02:00
|
|
|
|
|
|
|
use activity_pub::Id;
|
|
|
|
|
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
pub enum InboxError {
|
|
|
|
#[fail(display = "The `type` property is required, but was not present")]
|
|
|
|
NoType,
|
|
|
|
#[fail(display = "Invalid activity type")]
|
|
|
|
InvalidType,
|
|
|
|
#[fail(display = "Couldn't undo activity")]
|
2018-11-24 12:44:17 +01:00
|
|
|
CantUndo,
|
2018-06-23 18:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait FromActivity<T: Object, C>: Sized {
|
2018-12-29 09:36:07 +01:00
|
|
|
type Error: From<ApError>;
|
|
|
|
|
|
|
|
fn from_activity(conn: &C, obj: T, actor: Id) -> Result<Self, Self::Error>;
|
|
|
|
|
|
|
|
fn try_from_activity(conn: &C, act: Create) -> Result<Self, Self::Error> {
|
|
|
|
Self::from_activity(
|
|
|
|
conn,
|
|
|
|
act.create_props.object_object()?,
|
|
|
|
act.create_props.actor_link::<Id>()?,
|
|
|
|
)
|
2018-06-23 18:36:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Notify<C> {
|
2018-12-29 09:36:07 +01:00
|
|
|
type Error;
|
|
|
|
|
|
|
|
fn notify(&self, conn: &C) -> Result<(), Self::Error>;
|
2018-06-23 18:36:11 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 17:28:47 +02:00
|
|
|
pub trait Deletable<C, A> {
|
2018-12-29 09:36:07 +01:00
|
|
|
type Error;
|
|
|
|
|
|
|
|
fn delete(&self, conn: &C) -> Result<A, Self::Error>;
|
|
|
|
fn delete_id(id: &str, actor_id: &str, conn: &C) -> Result<A, Self::Error>;
|
2018-06-23 18:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait WithInbox {
|
|
|
|
fn get_inbox_url(&self) -> String;
|
|
|
|
|
|
|
|
fn get_shared_inbox_url(&self) -> Option<String>;
|
2018-07-18 15:49:13 +02:00
|
|
|
|
|
|
|
fn is_local(&self) -> bool;
|
2018-06-23 18:36:11 +02:00
|
|
|
}
|