diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index 60b2a93f..b25930a5 100644 --- a/src/activitypub/mod.rs +++ b/src/activitypub/mod.rs @@ -2,12 +2,23 @@ pub mod user; pub mod object; pub mod activity; - use axum::{extract::State, http::StatusCode, Json}; use sea_orm::{EntityTrait, IntoActiveModel}; use crate::{activitystream::{self, object::{activity::{Activity, ActivityType}, actor::{ActorMut, ActorType}, ObjectMut, ObjectType}, Base, BaseMut, BaseType, Node}, model, server::Context, url}; +pub const PUBLIC_TARGET : &str = "https://www.w3.org/ns/activitystreams#Public"; + +pub fn split_id(id: &str) -> (String, String) { + let clean = id + .replace("http://", "") + .replace("https://", ""); + let mut splits = clean.split('/'); + let first = splits.next().unwrap_or(""); + let last = splits.last().unwrap_or(first); + (first.to_string(), last.to_string()) +} + #[derive(Debug, serde::Deserialize)] // TODO i don't really like how pleroma/mastodon do it actually, maybe change this? diff --git a/src/activitystream/node.rs b/src/activitystream/node.rs index f3e933ef..880b8888 100644 --- a/src/activitystream/node.rs +++ b/src/activitystream/node.rs @@ -85,8 +85,28 @@ impl Node { } impl Node{ - pub fn link(uri: &str) -> Self { - Node::Link(Box::new(uri.to_string())) + pub fn empty() -> Self { + Node::Empty + } + + pub fn link(uri: String) -> Self { + Node::Link(Box::new(uri)) + } + + pub fn links(uris: Vec) -> Self { + Node::Array( + uris + .into_iter() + .map(Node::link) + .collect() + ) + } + + pub fn maybe_link(uri: Option) -> Self { + match uri { + Some(uri) => Node::Link(Box::new(uri)), + None => Node::Empty, + } } pub fn object(x: serde_json::Value) -> Self { @@ -146,7 +166,3 @@ impl From for Node { } } - - - -