forked from alemi/upub
feat(apb): restructured, added target and server
target is about addressing, and server has traits for barebones outbox and inbox. these come from upub
This commit is contained in:
parent
4c2eb7b990
commit
a9229adec8
22 changed files with 83 additions and 31 deletions
|
@ -18,6 +18,7 @@ chrono = { version = "0.4", features = ["serde"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
async-trait = "0.1"
|
||||||
serde_json = { version = "1", optional = true }
|
serde_json = { version = "1", optional = true }
|
||||||
sea-orm = { version = "0.12", optional = true }
|
sea-orm = { version = "0.12", optional = true }
|
||||||
reqwest = { version = "0.12", features = ["json"], optional = true }
|
reqwest = { version = "0.12", features = ["json"], optional = true }
|
||||||
|
|
|
@ -93,34 +93,35 @@ pub(crate) use macros::{strenum, getter, setter};
|
||||||
mod node;
|
mod node;
|
||||||
pub use node::Node;
|
pub use node::Node;
|
||||||
|
|
||||||
mod link;
|
pub mod server;
|
||||||
pub use link::{Link, LinkMut, LinkType};
|
pub mod target;
|
||||||
|
|
||||||
mod key;
|
mod key;
|
||||||
pub use key::{PublicKey, PublicKeyMut};
|
pub use key::{PublicKey, PublicKeyMut};
|
||||||
|
|
||||||
mod base;
|
mod types;
|
||||||
pub use base::{Base, BaseMut, BaseType};
|
pub use types::{
|
||||||
|
base::{Base, BaseMut, BaseType},
|
||||||
mod object;
|
link::{Link, LinkMut, LinkType},
|
||||||
pub use object::{
|
object::{
|
||||||
Object, ObjectMut, ObjectType,
|
Object, ObjectMut, ObjectType,
|
||||||
activity::{
|
activity::{
|
||||||
Activity, ActivityMut, ActivityType,
|
Activity, ActivityMut, ActivityType,
|
||||||
accept::{Accept, AcceptMut, AcceptType},
|
accept::{Accept, AcceptMut, AcceptType},
|
||||||
ignore::{Ignore, IgnoreMut, IgnoreType},
|
ignore::{Ignore, IgnoreMut, IgnoreType},
|
||||||
intransitive::{IntransitiveActivity, IntransitiveActivityMut, IntransitiveActivityType},
|
intransitive::{IntransitiveActivity, IntransitiveActivityMut, IntransitiveActivityType},
|
||||||
offer::{Offer, OfferMut, OfferType},
|
offer::{Offer, OfferMut, OfferType},
|
||||||
reject::{Reject, RejectMut, RejectType},
|
reject::{Reject, RejectMut, RejectType},
|
||||||
|
},
|
||||||
|
actor::{Actor, ActorMut, ActorType},
|
||||||
|
collection::{
|
||||||
|
Collection, CollectionMut, CollectionType,
|
||||||
|
page::{CollectionPage, CollectionPageMut}
|
||||||
|
},
|
||||||
|
document::{Document, DocumentMut, DocumentType},
|
||||||
|
place::{Place, PlaceMut},
|
||||||
|
// profile::Profile,
|
||||||
|
relationship::{Relationship, RelationshipMut},
|
||||||
|
tombstone::{Tombstone, TombstoneMut},
|
||||||
},
|
},
|
||||||
actor::{Actor, ActorMut, ActorType},
|
|
||||||
collection::{
|
|
||||||
Collection, CollectionMut, CollectionType,
|
|
||||||
page::{CollectionPage, CollectionPageMut}
|
|
||||||
},
|
|
||||||
document::{Document, DocumentMut, DocumentType},
|
|
||||||
place::{Place, PlaceMut},
|
|
||||||
// profile::Profile,
|
|
||||||
relationship::{Relationship, RelationshipMut},
|
|
||||||
tombstone::{Tombstone, TombstoneMut},
|
|
||||||
};
|
};
|
||||||
|
|
29
apb/src/server.rs
Normal file
29
apb/src/server.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait Outbox {
|
||||||
|
type Object: crate::Object;
|
||||||
|
type Activity: crate::Activity;
|
||||||
|
type Error: std::error::Error;
|
||||||
|
|
||||||
|
async fn create_note(&self, uid: String, object: Self::Object) -> Result<String, Self::Error>;
|
||||||
|
async fn create(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
async fn like(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
async fn follow(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
async fn accept(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
async fn reject(&self, _uid: String, _activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
async fn undo(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait Inbox {
|
||||||
|
type Activity: crate::Activity;
|
||||||
|
type Error: std::error::Error;
|
||||||
|
|
||||||
|
async fn create(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn like(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn follow(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn accept(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn reject(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn undo(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn delete(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
async fn update(&self, activity: Self::Activity) -> Result<(), Self::Error>;
|
||||||
|
}
|
18
apb/src/target.rs
Normal file
18
apb/src/target.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use crate::{Object, Link};
|
||||||
|
|
||||||
|
pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public";
|
||||||
|
|
||||||
|
pub trait Addressed : Object {
|
||||||
|
fn addressed(&self) -> Vec<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstructured")]
|
||||||
|
impl Addressed for serde_json::Value {
|
||||||
|
fn addressed(&self) -> Vec<String> {
|
||||||
|
let mut to : Vec<String> = self.to().map(|x| x.href().to_string()).collect();
|
||||||
|
to.append(&mut self.bto().map(|x| x.href().to_string()).collect());
|
||||||
|
to.append(&mut self.cc().map(|x| x.href().to_string()).collect());
|
||||||
|
to.append(&mut self.bcc().map(|x| x.href().to_string()).collect());
|
||||||
|
to
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ crate::strenum! {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Link : super::Base {
|
pub trait Link : crate::Base {
|
||||||
fn href(&self) -> &str;
|
fn href(&self) -> &str;
|
||||||
fn rel(&self) -> Option<&str> { None }
|
fn rel(&self) -> Option<&str> { None }
|
||||||
fn link_media_type(&self) -> Option<&str> { None } // also in obj
|
fn link_media_type(&self) -> Option<&str> { None } // also in obj
|
||||||
|
@ -16,7 +16,7 @@ pub trait Link : super::Base {
|
||||||
fn link_preview(&self) -> Option<&str> { None } // also in obj
|
fn link_preview(&self) -> Option<&str> { None } // also in obj
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LinkMut : super::BaseMut {
|
pub trait LinkMut : crate::BaseMut {
|
||||||
fn set_href(self, href: &str) -> Self;
|
fn set_href(self, href: &str) -> Self;
|
||||||
fn set_rel(self, val: Option<&str>) -> Self;
|
fn set_rel(self, val: Option<&str>) -> Self;
|
||||||
fn set_link_media_type(self, val: Option<&str>) -> Self; // also in obj
|
fn set_link_media_type(self, val: Option<&str>) -> Self; // also in obj
|
3
apb/src/types/mod.rs
Normal file
3
apb/src/types/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod base;
|
||||||
|
pub mod link;
|
||||||
|
pub mod object;
|
|
@ -4,7 +4,7 @@ pub mod intransitive;
|
||||||
pub mod offer;
|
pub mod offer;
|
||||||
pub mod reject;
|
pub mod reject;
|
||||||
|
|
||||||
use crate::{Node, object::{Object, ObjectMut}};
|
use crate::{Node, Object, ObjectMut};
|
||||||
use accept::AcceptType;
|
use accept::AcceptType;
|
||||||
use reject::RejectType;
|
use reject::RejectType;
|
||||||
use offer::OfferType;
|
use offer::OfferType;
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
|
|
||||||
use super::{Object, ObjectMut, super::key::PublicKey};
|
use crate::{Object, ObjectMut, PublicKey};
|
||||||
|
|
||||||
crate::strenum! {
|
crate::strenum! {
|
||||||
pub enum ActorType {
|
pub enum ActorType {
|
|
@ -1,7 +1,7 @@
|
||||||
pub mod page;
|
pub mod page;
|
||||||
pub use page::CollectionPage;
|
pub use page::CollectionPage;
|
||||||
|
|
||||||
use crate::{Node, Object, object::ObjectMut};
|
use crate::{Node, Object, ObjectMut};
|
||||||
|
|
||||||
crate::strenum! {
|
crate::strenum! {
|
||||||
pub enum CollectionType {
|
pub enum CollectionType {
|
|
@ -7,7 +7,7 @@ pub mod place;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod relationship;
|
pub mod relationship;
|
||||||
|
|
||||||
use super::{Base, BaseMut, Link, Node};
|
use crate::{Base, BaseMut, Link, Node};
|
||||||
|
|
||||||
use actor::{Actor, ActorType};
|
use actor::{Actor, ActorType};
|
||||||
use document::{Document, DocumentType};
|
use document::{Document, DocumentType};
|
Loading…
Reference in a new issue