Remove depdendency on activitypub from plume-common

This commit is contained in:
Kitaiti Makoto 2022-01-10 23:44:04 +09:00
parent bb7267846f
commit 7a404c68df
4 changed files with 14 additions and 18 deletions

1
Cargo.lock generated
View File

@ -3102,7 +3102,6 @@ dependencies = [
name = "plume-common" name = "plume-common"
version = "0.7.1-dev" version = "0.7.1-dev"
dependencies = [ dependencies = [
"activitypub",
"activitystreams", "activitystreams",
"activitystreams-derive", "activitystreams-derive",
"activitystreams-traits", "activitystreams-traits",

View File

@ -5,7 +5,6 @@ authors = ["Plume contributors"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
activitypub = "0.1.1"
activitystreams-derive = "0.1.1" activitystreams-derive = "0.1.1"
activitystreams-traits = "0.1.0" activitystreams-traits = "0.1.0"
array_tool = "1.0" array_tool = "1.0"

View File

@ -200,7 +200,7 @@ where
pub fn with<A, V, M>(self, proxy: Option<&reqwest::Proxy>) -> Inbox<'a, C, E, R> pub fn with<A, V, M>(self, proxy: Option<&reqwest::Proxy>) -> Inbox<'a, C, E, R>
where where
A: AsActor<&'a C> + FromId<C, Error = E>, A: AsActor<&'a C> + FromId<C, Error = E>,
V: activitypub::Activity, V: serde::de::DeserializeOwned + serde::Serialize,
M: AsObject<A, V, &'a C, Error = E> + FromId<C, Error = E>, M: AsObject<A, V, &'a C, Error = E> + FromId<C, Error = E>,
M::Output: Into<R>, M::Output: Into<R>,
{ {
@ -333,7 +333,7 @@ pub trait FromId<C>: Sized {
type Error: From<InboxError<Self::Error>> + Debug; type Error: From<InboxError<Self::Error>> + Debug;
/// The ActivityPub object type representing Self /// The ActivityPub object type representing Self
type Object: activitypub::Object; type Object: serde::de::DeserializeOwned + serde::Serialize;
/// Tries to get an instance of `Self` from an ActivityPub ID. /// Tries to get an instance of `Self` from an ActivityPub ID.
/// ///
@ -521,7 +521,7 @@ pub trait AsActor<C> {
/// ``` /// ```
pub trait AsObject<A, V, C> pub trait AsObject<A, V, C>
where where
V: activitypub::Activity, V: serde::de::DeserializeOwned + serde::Serialize,
{ {
/// What kind of error is returned when something fails /// What kind of error is returned when something fails
type Error; type Error;

View File

@ -1,4 +1,4 @@
use activitypub::{Activity, Link, Object}; use activitystreams::{activity::Activity, object::ApObject};
use array_tool::vec::Uniq; use array_tool::vec::Uniq;
use reqwest::{header::HeaderValue, r#async::ClientBuilder, Url}; use reqwest::{header::HeaderValue, r#async::ClientBuilder, Url};
use rocket::{ use rocket::{
@ -57,13 +57,13 @@ pub fn context() -> serde_json::Value {
pub struct ActivityStream<T>(T); pub struct ActivityStream<T>(T);
impl<T> ActivityStream<T> { impl<O: serde::Serialize> ActivityStream<ApObject<O>> {
pub fn new(t: T) -> ActivityStream<T> { pub fn new(t: ApObject<O>) -> ActivityStream<ApObject<O>> {
ActivityStream(t) ActivityStream(t)
} }
} }
impl<'r, O: Object> Responder<'r> for ActivityStream<O> { impl<'r, O: serde::Serialize> Responder<'r> for ActivityStream<ApObject<O>> {
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> { fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?; let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
json["@context"] = context(); json["@context"] = context();
@ -108,10 +108,14 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
.unwrap_or(Outcome::Forward(())) .unwrap_or(Outcome::Forward(()))
} }
} }
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>, proxy: Option<reqwest::Proxy>) pub fn broadcast<S, A, T, C>(
where sender: &S,
act: Activity<A>,
to: Vec<T>,
proxy: Option<reqwest::Proxy>,
) where
S: sign::Signer, S: sign::Signer,
A: Activity, A: serde::Serialize,
T: inbox::AsActor<C>, T: inbox::AsActor<C>,
{ {
let boxes = to let boxes = to
@ -204,8 +208,6 @@ pub trait IntoId {
fn into_id(self) -> Id; fn into_id(self) -> Id;
} }
impl Link for Id {}
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ApSignature { pub struct ApSignature {
@ -251,13 +253,9 @@ pub struct Source {
pub content: String, pub content: String,
} }
impl Object for Source {}
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Licensed { pub struct Licensed {
#[activitystreams(concrete(String), functional)] #[activitystreams(concrete(String), functional)]
pub license: Option<serde_json::Value>, pub license: Option<serde_json::Value>,
} }
impl Object for Licensed {}