Skip to content

Commit

Permalink
add deliverer trait
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 12, 2023
1 parent ff0bb2e commit 86455b7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions crates/kitsune-activitypub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
5 changes: 2 additions & 3 deletions crates/kitsune-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -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<dyn ErrorTrait + Send + Sync>;
pub type BoxError = Box<dyn StdError + Send + Sync>;
pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, Error)]
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod inbox;
mod post;

pub use self::inbox::InboxResolver;
pub use self::post::PostResolver;
41 changes: 39 additions & 2 deletions crates/kitsune-core/src/traits.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<BoxError>;

fn deliver(&self, action: Action) -> impl Future<Output = Result<(), Self::Error>> + Send;
}

impl<T> 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<BoxError>;

fn fetch_account(
&self,
Expand All @@ -56,7 +93,7 @@ pub trait Fetcher {
}

pub trait Resolver {
type Error;
type Error: Into<BoxError>;

fn resolve_account(
&self,
Expand Down
1 change: 0 additions & 1 deletion crates/kitsune-webfinger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-webfinger/tests/redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 86455b7

Please sign in to comment.