You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
13 KiB
Rust
304 lines
13 KiB
Rust
use chrono::NaiveDateTime;
|
|
use rdf_types::vocabulary::IriIndex;
|
|
use rdf_types::Vocabulary;
|
|
use std::fmt;
|
|
|
|
use crate::ap::trans::{
|
|
matches_type, AbstractObject, ApDocument, DebugApub, ParseApub, PropHelper, RawObject,
|
|
};
|
|
use crate::ap::vocab::Ids;
|
|
|
|
pub struct AbstractActivity {
|
|
_super: AbstractObject,
|
|
pub actor: Vec<ApDocument>,
|
|
pub object: Vec<ApDocument>,
|
|
pub target: Option<Box<ApDocument>>,
|
|
pub origin: Option<Box<ApDocument>>,
|
|
pub instrument: Vec<ApDocument>,
|
|
}
|
|
ap_extends!(AbstractActivity, AbstractObject);
|
|
|
|
impl<V: Vocabulary<Iri = IriIndex>> ParseApub<V> for AbstractActivity {
|
|
fn parse_apub(obj: &RawObject, vocab: &V, ids: &Ids) -> Option<Self> {
|
|
matches_type(obj, &ids.apub.object.activity)?;
|
|
unsafe { Self::_parse_apub_unchecked(obj, vocab, ids) }
|
|
}
|
|
|
|
unsafe fn _parse_apub_unchecked(obj: &RawObject, vocab: &V, ids: &Ids) -> Option<Self> {
|
|
let ph = PropHelper::new(obj, vocab, ids)?;
|
|
let prop_ids = &ids.apub.property;
|
|
|
|
AbstractObject::_parse_apub_unchecked(obj, vocab, ids).map(|s| Self {
|
|
_super: s,
|
|
actor: ph.parse_prop_vec(&prop_ids.actor),
|
|
object: ph.parse_prop_vec(&prop_ids.object),
|
|
target: ph.parse_prop_box(&prop_ids.target),
|
|
origin: ph.parse_prop_box(&prop_ids.origin),
|
|
instrument: ph.parse_prop_vec(&prop_ids.instrument),
|
|
})
|
|
}
|
|
}
|
|
|
|
impl DebugApub for AbstractActivity {
|
|
fn apub_class_name(&self) -> &str {
|
|
"Activity"
|
|
}
|
|
|
|
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
self._super.debug_apub_members(f, depth)?;
|
|
ap_display_prop_vec!(self, f, actor, depth)?;
|
|
ap_display_prop_vec!(self, f, object, depth)?;
|
|
ap_display_prop_box!(self, f, target, depth)?;
|
|
ap_display_prop_box!(self, f, origin, depth)?;
|
|
ap_display_prop_vec!(self, f, instrument, depth)
|
|
}
|
|
}
|
|
|
|
pub enum Activity {
|
|
Accept(Accept),
|
|
Add(Add),
|
|
Announce(Announce),
|
|
Arrive(Arrive),
|
|
Block(Block),
|
|
Create(Create),
|
|
Delete(Delete),
|
|
Dislike(Dislike),
|
|
Flag(Flag),
|
|
Follow(Follow),
|
|
Ignore(Ignore),
|
|
Invite(Invite),
|
|
Join(Join),
|
|
Leave(Leave),
|
|
Like(Like),
|
|
Listen(Listen),
|
|
Move(Move),
|
|
Offer(Offer),
|
|
Question(Question),
|
|
Reject(Reject),
|
|
Read(Read),
|
|
Remove(Remove),
|
|
TentativeReject(TentativeReject),
|
|
TentativeAccept(TentativeAccept),
|
|
Travel(Travel),
|
|
Undo(Undo),
|
|
Update(Update),
|
|
View(View),
|
|
}
|
|
|
|
impl<V: Vocabulary<Iri = IriIndex>> ParseApub<V> for Activity {
|
|
fn parse_apub(obj: &RawObject, vocab: &V, ids: &Ids) -> Option<Self> {
|
|
Accept::parse_apub(obj, vocab, ids)
|
|
.map(Self::Accept)
|
|
.or_else(|| Add::parse_apub(obj, vocab, ids).map(Self::Add))
|
|
.or_else(|| Announce::parse_apub(obj, vocab, ids).map(Self::Announce))
|
|
.or_else(|| Arrive::parse_apub(obj, vocab, ids).map(Self::Arrive))
|
|
.or_else(|| Block::parse_apub(obj, vocab, ids).map(Self::Block))
|
|
.or_else(|| Create::parse_apub(obj, vocab, ids).map(Self::Create))
|
|
.or_else(|| Delete::parse_apub(obj, vocab, ids).map(Self::Delete))
|
|
.or_else(|| Dislike::parse_apub(obj, vocab, ids).map(Self::Dislike))
|
|
.or_else(|| Flag::parse_apub(obj, vocab, ids).map(Self::Flag))
|
|
.or_else(|| Follow::parse_apub(obj, vocab, ids).map(Self::Follow))
|
|
.or_else(|| Ignore::parse_apub(obj, vocab, ids).map(Self::Ignore))
|
|
.or_else(|| Invite::parse_apub(obj, vocab, ids).map(Self::Invite))
|
|
.or_else(|| Join::parse_apub(obj, vocab, ids).map(Self::Join))
|
|
.or_else(|| Leave::parse_apub(obj, vocab, ids).map(Self::Leave))
|
|
.or_else(|| Like::parse_apub(obj, vocab, ids).map(Self::Like))
|
|
.or_else(|| Listen::parse_apub(obj, vocab, ids).map(Self::Listen))
|
|
.or_else(|| Move::parse_apub(obj, vocab, ids).map(Self::Move))
|
|
.or_else(|| Offer::parse_apub(obj, vocab, ids).map(Self::Offer))
|
|
.or_else(|| Question::parse_apub(obj, vocab, ids).map(Self::Question))
|
|
.or_else(|| Reject::parse_apub(obj, vocab, ids).map(Self::Reject))
|
|
.or_else(|| Read::parse_apub(obj, vocab, ids).map(Self::Read))
|
|
.or_else(|| Remove::parse_apub(obj, vocab, ids).map(Self::Remove))
|
|
.or_else(|| TentativeReject::parse_apub(obj, vocab, ids).map(Self::TentativeReject))
|
|
.or_else(|| TentativeAccept::parse_apub(obj, vocab, ids).map(Self::TentativeAccept))
|
|
.or_else(|| Travel::parse_apub(obj, vocab, ids).map(Self::Travel))
|
|
.or_else(|| Undo::parse_apub(obj, vocab, ids).map(Self::Undo))
|
|
.or_else(|| Update::parse_apub(obj, vocab, ids).map(Self::Update))
|
|
.or_else(|| View::parse_apub(obj, vocab, ids).map(Self::View))
|
|
}
|
|
}
|
|
|
|
impl DebugApub for Activity {
|
|
fn apub_class_name(&self) -> &str {
|
|
use Activity::*;
|
|
|
|
match self {
|
|
Accept(a) => a.apub_class_name(),
|
|
Add(a) => a.apub_class_name(),
|
|
Announce(a) => a.apub_class_name(),
|
|
Arrive(a) => a.apub_class_name(),
|
|
Block(b) => b.apub_class_name(),
|
|
Create(c) => c.apub_class_name(),
|
|
Delete(d) => d.apub_class_name(),
|
|
Dislike(d) => d.apub_class_name(),
|
|
Flag(f) => f.apub_class_name(),
|
|
Follow(f) => f.apub_class_name(),
|
|
Ignore(i) => i.apub_class_name(),
|
|
Invite(i) => i.apub_class_name(),
|
|
Join(j) => j.apub_class_name(),
|
|
Leave(l) => l.apub_class_name(),
|
|
Like(l) => l.apub_class_name(),
|
|
Listen(l) => l.apub_class_name(),
|
|
Move(m) => m.apub_class_name(),
|
|
Offer(o) => o.apub_class_name(),
|
|
Question(q) => q.apub_class_name(),
|
|
Reject(r) => r.apub_class_name(),
|
|
Read(r) => r.apub_class_name(),
|
|
Remove(r) => r.apub_class_name(),
|
|
TentativeReject(t) => t.apub_class_name(),
|
|
TentativeAccept(t) => t.apub_class_name(),
|
|
Travel(t) => t.apub_class_name(),
|
|
Undo(u) => u.apub_class_name(),
|
|
Update(u) => u.apub_class_name(),
|
|
View(v) => v.apub_class_name(),
|
|
}
|
|
}
|
|
|
|
fn debug_apub(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
use Activity::*;
|
|
|
|
match self {
|
|
Accept(a) => a.debug_apub(f, depth),
|
|
Add(a) => a.debug_apub(f, depth),
|
|
Announce(a) => a.debug_apub(f, depth),
|
|
Arrive(a) => a.debug_apub(f, depth),
|
|
Block(b) => b.debug_apub(f, depth),
|
|
Create(c) => c.debug_apub(f, depth),
|
|
Delete(d) => d.debug_apub(f, depth),
|
|
Dislike(d) => d.debug_apub(f, depth),
|
|
Flag(flag) => flag.debug_apub(f, depth),
|
|
Follow(follow) => follow.debug_apub(f, depth),
|
|
Ignore(i) => i.debug_apub(f, depth),
|
|
Invite(i) => i.debug_apub(f, depth),
|
|
Join(j) => j.debug_apub(f, depth),
|
|
Leave(l) => l.debug_apub(f, depth),
|
|
Like(l) => l.debug_apub(f, depth),
|
|
Listen(l) => l.debug_apub(f, depth),
|
|
Move(m) => m.debug_apub(f, depth),
|
|
Offer(o) => o.debug_apub(f, depth),
|
|
Question(q) => q.debug_apub(f, depth),
|
|
Reject(r) => r.debug_apub(f, depth),
|
|
Read(r) => r.debug_apub(f, depth),
|
|
Remove(r) => r.debug_apub(f, depth),
|
|
TentativeReject(t) => t.debug_apub(f, depth),
|
|
TentativeAccept(t) => t.debug_apub(f, depth),
|
|
Travel(t) => t.debug_apub(f, depth),
|
|
Undo(u) => u.debug_apub(f, depth),
|
|
Update(u) => u.debug_apub(f, depth),
|
|
View(v) => v.debug_apub(f, depth),
|
|
}
|
|
}
|
|
|
|
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
use Activity::*;
|
|
|
|
match self {
|
|
Accept(a) => a.debug_apub_members(f, depth),
|
|
Add(a) => a.debug_apub_members(f, depth),
|
|
Announce(a) => a.debug_apub_members(f, depth),
|
|
Arrive(a) => a.debug_apub_members(f, depth),
|
|
Block(b) => b.debug_apub_members(f, depth),
|
|
Create(c) => c.debug_apub_members(f, depth),
|
|
Delete(d) => d.debug_apub_members(f, depth),
|
|
Dislike(d) => d.debug_apub_members(f, depth),
|
|
Flag(flag) => flag.debug_apub_members(f, depth),
|
|
Follow(follow) => follow.debug_apub_members(f, depth),
|
|
Ignore(i) => i.debug_apub_members(f, depth),
|
|
Invite(i) => i.debug_apub_members(f, depth),
|
|
Join(j) => j.debug_apub_members(f, depth),
|
|
Leave(l) => l.debug_apub_members(f, depth),
|
|
Like(l) => l.debug_apub_members(f, depth),
|
|
Listen(l) => l.debug_apub_members(f, depth),
|
|
Move(m) => m.debug_apub_members(f, depth),
|
|
Offer(o) => o.debug_apub_members(f, depth),
|
|
Question(q) => q.debug_apub_members(f, depth),
|
|
Reject(r) => r.debug_apub_members(f, depth),
|
|
Read(r) => r.debug_apub_members(f, depth),
|
|
Remove(r) => r.debug_apub_members(f, depth),
|
|
TentativeReject(t) => t.debug_apub_members(f, depth),
|
|
TentativeAccept(t) => t.debug_apub_members(f, depth),
|
|
Travel(t) => t.debug_apub_members(f, depth),
|
|
Undo(u) => u.debug_apub_members(f, depth),
|
|
Update(u) => u.debug_apub_members(f, depth),
|
|
View(v) => v.debug_apub_members(f, depth),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct Question {
|
|
_super: AbstractActivity,
|
|
pub one_of: Vec<ApDocument>,
|
|
pub any_of: Vec<ApDocument>,
|
|
pub closed: Option<NaiveDateTime>,
|
|
}
|
|
ap_extends!(Question, AbstractActivity);
|
|
|
|
impl<V: Vocabulary<Iri = IriIndex>> ParseApub<V> for Question {
|
|
fn parse_apub(obj: &RawObject, vocab: &V, ids: &Ids) -> Option<Self> {
|
|
matches_type(obj, &ids.apub.object.question)?;
|
|
unsafe { Self::_parse_apub_unchecked(obj, vocab, ids) }
|
|
}
|
|
|
|
unsafe fn _parse_apub_unchecked(obj: &RawObject, vocab: &V, ids: &Ids) -> Option<Self> {
|
|
let ph = PropHelper::new(obj, vocab, ids)?;
|
|
let prop_ids = &ids.apub.property;
|
|
|
|
AbstractActivity::_parse_apub_unchecked(obj, vocab, ids).map(|s| Self {
|
|
_super: s,
|
|
one_of: ph.parse_prop_vec(&prop_ids.one_of),
|
|
any_of: ph.parse_prop_vec(&prop_ids.any_of),
|
|
closed: ph.parse_prop(&prop_ids.closed),
|
|
})
|
|
}
|
|
}
|
|
|
|
impl DebugApub for Question {
|
|
fn debug_apub_members(&self, f: &mut fmt::Formatter, depth: usize) -> fmt::Result {
|
|
self._super.debug_apub_members(f, depth)?;
|
|
ap_display_prop_vec!(self, f, one_of, depth)?;
|
|
ap_display_prop_vec!(self, f, any_of, depth)?;
|
|
ap_display_prop!(self, f, closed, depth)
|
|
}
|
|
}
|
|
|
|
ap_empty_child_impl!(Accept, AbstractActivity, apub, activity, accept);
|
|
ap_empty_child_impl!(Add, AbstractActivity, apub, activity, add);
|
|
ap_empty_child_impl!(Announce, AbstractActivity, apub, activity, announce);
|
|
ap_empty_child_impl!(Arrive, AbstractActivity, apub, activity, arrive);
|
|
ap_empty_child_impl!(Block, Ignore, apub, activity, block);
|
|
ap_empty_child_impl!(Create, AbstractActivity, apub, activity, create);
|
|
ap_empty_child_impl!(Delete, AbstractActivity, apub, activity, delete);
|
|
ap_empty_child_impl!(Dislike, AbstractActivity, apub, activity, dislike);
|
|
ap_empty_child_impl!(Flag, AbstractActivity, apub, activity, flag);
|
|
ap_empty_child_impl!(Follow, AbstractActivity, apub, activity, follow);
|
|
ap_empty_child_impl!(Ignore, AbstractActivity, apub, activity, ignore);
|
|
ap_empty_child_impl!(Invite, AbstractActivity, apub, activity, invite);
|
|
ap_empty_child_impl!(Join, AbstractActivity, apub, activity, join);
|
|
ap_empty_child_impl!(Leave, AbstractActivity, apub, activity, leave);
|
|
ap_empty_child_impl!(Like, AbstractActivity, apub, activity, like);
|
|
ap_empty_child_impl!(Listen, AbstractActivity, apub, activity, listen);
|
|
ap_empty_child_impl!(Move, AbstractActivity, apub, activity, mov);
|
|
ap_empty_child_impl!(Offer, AbstractActivity, apub, activity, offer);
|
|
ap_empty_child_impl!(Reject, AbstractActivity, apub, activity, reject);
|
|
ap_empty_child_impl!(Read, AbstractActivity, apub, activity, read);
|
|
ap_empty_child_impl!(Remove, AbstractActivity, apub, activity, remove);
|
|
ap_empty_child_impl!(
|
|
TentativeReject,
|
|
AbstractActivity,
|
|
apub,
|
|
activity,
|
|
tentative_reject
|
|
);
|
|
ap_empty_child_impl!(
|
|
TentativeAccept,
|
|
AbstractActivity,
|
|
apub,
|
|
activity,
|
|
tentative_accept
|
|
);
|
|
ap_empty_child_impl!(Travel, AbstractActivity, apub, activity, travel);
|
|
ap_empty_child_impl!(Undo, AbstractActivity, apub, activity, undo);
|
|
ap_empty_child_impl!(Update, AbstractActivity, apub, activity, update);
|
|
ap_empty_child_impl!(View, AbstractActivity, apub, activity, view);
|