Compare commits

...

3 commits

6 changed files with 38 additions and 15 deletions

View file

@ -24,13 +24,14 @@ sea-orm = { version = "0.12", optional = true }
reqwest = { version = "0.12", features = ["json"], optional = true }
[features]
default = ["activitypub-miscellaneous-terms"]
default = ["activitypub-miscellaneous-terms", "send"]
# extensions
activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/
activitypub-counters = [] # https://ns.alemi.dev/as/counters/#
activitypub-fe = [] # https://ns.alemi.dev/as/fe/#
litepub = [] # incomplete, https://litepub.social/
# builtin utils
send = []
orm = ["dep:sea-orm"]
fetch = ["dep:reqwest"]
# providers

View file

@ -1,3 +1,15 @@
#[cfg(feature = "send")]
pub trait MaybeSend : Send {}
#[cfg(feature = "send")]
impl<T : Send> MaybeSend for T {}
#[cfg(not(feature = "send"))]
pub trait MaybeSend {}
#[cfg(not(feature = "send"))]
impl<T> MaybeSend for T {}
#[derive(Debug, thiserror::Error)]
#[error("invalid type value")]
pub struct TypeValueError;

View file

@ -116,6 +116,15 @@ impl<T : super::Base> Node<T> {
Node::Array(x) => x.iter().filter_map(Self::id).collect()
}
}
pub fn flat(self) -> Vec<Node<T>> {
match self {
Node::Empty => vec![],
Node::Link(_) | Node::Object(_) => vec![self],
// i think AP disallows array of arrays so no need to make this recursive
Node::Array(arr) => arr.into()
}
}
}
#[cfg(feature = "unstructured")]

View file

@ -8,13 +8,13 @@ crate::strenum! {
};
}
pub trait Base {
pub trait Base : crate::macros::MaybeSend {
fn id(&self) -> Option<&str> { None }
fn base_type(&self) -> Option<BaseType> { None }
}
pub trait BaseMut {
pub trait BaseMut : crate::macros::MaybeSend {
fn set_id(self, val: Option<&str>) -> Self;
fn set_base_type(self, val: Option<BaseType>) -> Self;
}

View file

@ -117,6 +117,18 @@ impl Context {
}
}
/// get bare id, usually an uuid but unspecified
pub fn id(&self, uri: &str) -> String {
if uri.starts_with(&self.0.domain) {
uri.split('/').last().unwrap_or("").to_string()
} else {
uri
.replace("https://", "+")
.replace("http://", "+")
.replace('/', "@")
}
}
/// get full user id uri
pub fn uid(&self, id: String) -> String {
self.uri("users", id)
@ -132,17 +144,6 @@ impl Context {
self.uri("activities", id)
}
/// get bare id, usually an uuid but unspecified
pub fn id(&self, uri: &str) -> String {
if uri.starts_with(&self.0.domain) {
uri.split('/').last().unwrap_or("").to_string()
} else {
uri
.replace("https://", "+")
.replace("http://", "+")
.replace('/', "@")
}
}
pub fn server(id: &str) -> String {
id

View file

@ -319,7 +319,7 @@ impl apb::server::Inbox for Context {
// TODO in theory we could work with just object_id but right now only accept embedded
let undone_activity = activity.object().extract().ok_or_else(UpubError::bad_request)?;
let undone_aid = undone_activity.id().ok_or_else(UpubError::bad_request)?;
let undone_object_id = undone_activity.object().id().ok_or_else(UpubError::bad_request)?;
let undone_object_uri = undone_activity.object().id().ok_or_else(UpubError::bad_request)?;
let activity_type = undone_activity.activity_type().ok_or_else(UpubError::bad_request)?;
let undone_activity_author = undone_activity.actor().id().ok_or_else(UpubError::bad_request)?;