diff --git a/Cargo.lock b/Cargo.lock index 8cfcdd4dd..4f3524dd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3303,7 +3303,6 @@ dependencies = [ "kitsune-type", "kitsune-util", "pretty_assertions", - "serde", "simd-json", "thiserror", "tokio", diff --git a/crates/kitsune-core/src/resolve/inbox.rs b/crates/kitsune-activitypub/src/inbox_resolver.rs similarity index 100% rename from crates/kitsune-core/src/resolve/inbox.rs rename to crates/kitsune-activitypub/src/inbox_resolver.rs diff --git a/crates/kitsune-activitypub/src/lib.rs b/crates/kitsune-activitypub/src/lib.rs index 0e80fe89e..a502d5ee6 100644 --- a/crates/kitsune-activitypub/src/lib.rs +++ b/crates/kitsune-activitypub/src/lib.rs @@ -37,6 +37,7 @@ use typed_builder::TypedBuilder; pub mod deliverer; pub mod error; pub mod fetcher; +pub mod inbox_resolver; pub use self::{deliverer::Deliverer, fetcher::Fetcher}; diff --git a/crates/kitsune-core/src/error.rs b/crates/kitsune-core/src/error.rs index 46b5c01bc..e80740e88 100644 --- a/crates/kitsune-core/src/error.rs +++ b/crates/kitsune-core/src/error.rs @@ -1,9 +1,8 @@ -use std::error::Error as ErrorTrait; - use kitsune_http_signatures::ring; +use std::error::Error as StdError; use thiserror::Error; -pub type BoxError = Box; +pub type BoxError = Box; pub type Result = std::result::Result; #[derive(Debug, Error)] diff --git a/crates/kitsune-core/src/resolve/mod.rs b/crates/kitsune-core/src/resolve/mod.rs index a7c640d38..45488eb84 100644 --- a/crates/kitsune-core/src/resolve/mod.rs +++ b/crates/kitsune-core/src/resolve/mod.rs @@ -1,5 +1,3 @@ -mod inbox; mod post; -pub use self::inbox::InboxResolver; pub use self::post::PostResolver; diff --git a/crates/kitsune-core/src/traits.rs b/crates/kitsune-core/src/traits.rs index 8320f3968..9418afa1a 100644 --- a/crates/kitsune-core/src/traits.rs +++ b/crates/kitsune-core/src/traits.rs @@ -1,3 +1,4 @@ +use crate::error::BoxError; use kitsune_db::model::{account::Account, custom_emoji::CustomEmoji, post::Post}; use serde::{Deserialize, Serialize}; use std::future::Future; @@ -39,8 +40,44 @@ pub struct AccountResource { pub domain: String, } +#[derive(Clone)] +pub enum Action { + Create(Post), + Delete(Post), + Favourite(Post), + Repost(Post), + Unfavourite(Post), + Unrepost(Post), + UpdateAccount(Account), + UpdatePost(Post), +} + +pub trait Deliverer: Send + Sync { + type Error: Into; + + fn deliver(&self, action: Action) -> impl Future> + Send; +} + +impl Deliverer for [T] +where + T: Deliverer, +{ + type Error = BoxError; + + async fn deliver(&self, action: Action) -> Result<(), Self::Error> { + for deliverer in self { + deliverer + .deliver(action.clone()) + .await + .map_err(Into::into)?; + } + + Ok(()) + } +} + pub trait Fetcher { - type Error; + type Error: Into; fn fetch_account( &self, @@ -56,7 +93,7 @@ pub trait Fetcher { } pub trait Resolver { - type Error; + type Error: Into; fn resolve_account( &self, diff --git a/crates/kitsune-webfinger/Cargo.toml b/crates/kitsune-webfinger/Cargo.toml index 3bf635653..d0526c279 100644 --- a/crates/kitsune-webfinger/Cargo.toml +++ b/crates/kitsune-webfinger/Cargo.toml @@ -14,7 +14,6 @@ kitsune-core = { path = "../kitsune-core" } kitsune-http-client = { path = "../kitsune-http-client" } kitsune-type = { path = "../kitsune-type" } kitsune-util = { path = "../kitsune-util" } -serde = { version = "1.0.192", features = ["derive"] } thiserror = "1.0.50" tracing = "0.1.40" diff --git a/crates/kitsune-webfinger/tests/redirects.rs b/crates/kitsune-webfinger/tests/redirects.rs index a6ba5a1a4..e9f6a76b8 100644 --- a/crates/kitsune-webfinger/tests/redirects.rs +++ b/crates/kitsune-webfinger/tests/redirects.rs @@ -116,7 +116,7 @@ async fn reject_unbounded_number_of_jrd_redirects() { let webfinger = Webfinger::with_client(client, Arc::new(NoopCache.into())); let resource = webfinger - .resolve_actor("0x0", "corteximplant.com") + .resolve_account("0x0", "corteximplant.com") .await .expect("Failed to fetch resource");