-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
117 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::error::BoxError; | ||
use kitsune_db::model::{account::Account, post::Post}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::future::Future; | ||
|
||
#[derive(Clone, Deserialize, Serialize)] | ||
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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::error::BoxError; | ||
use kitsune_db::model::{account::Account, custom_emoji::CustomEmoji, post::Post}; | ||
use std::future::Future; | ||
use typed_builder::TypedBuilder; | ||
|
||
#[derive(Clone, Debug, TypedBuilder)] | ||
/// Options passed to the fetcher | ||
pub struct AccountFetchOptions<'a> { | ||
/// Prefetched WebFinger `acct` URI | ||
#[builder(default, setter(strip_option))] | ||
pub acct: Option<(&'a str, &'a str)>, | ||
|
||
/// Refetch the ActivityPub entity | ||
/// | ||
/// This is mainly used to refresh possibly stale actors | ||
/// | ||
/// Default: false | ||
#[builder(default = false)] | ||
pub refetch: bool, | ||
|
||
/// URL of the ActivityPub entity | ||
pub url: &'a str, | ||
} | ||
|
||
impl<'a> From<&'a str> for AccountFetchOptions<'a> { | ||
fn from(value: &'a str) -> Self { | ||
Self::builder().url(value).build() | ||
} | ||
} | ||
|
||
pub trait Fetcher { | ||
type Error: Into<BoxError>; | ||
|
||
fn fetch_account( | ||
&self, | ||
opts: AccountFetchOptions<'_>, | ||
) -> impl Future<Output = Result<Account, Self::Error>> + Send; | ||
|
||
fn fetch_emoji( | ||
&self, | ||
url: &str, | ||
) -> impl Future<Output = Result<CustomEmoji, Self::Error>> + Send; | ||
|
||
fn fetch_post(&self, url: &str) -> impl Future<Output = Result<Post, Self::Error>> + Send; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod deliverer; | ||
pub mod fetcher; | ||
pub mod resolver; | ||
|
||
pub use self::{deliverer::Deliverer, fetcher::Fetcher, resolver::Resolver}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::error::BoxError; | ||
use serde::{Deserialize, Serialize}; | ||
use std::future::Future; | ||
|
||
/// Description of a resolved account | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct AccountResource { | ||
/// The `self` link (the account's URI) | ||
pub uri: String, | ||
/// The username part of the canonical `acct:` URI | ||
pub username: String, | ||
/// The host component of the canonical `acct:` URI | ||
pub domain: String, | ||
} | ||
|
||
pub trait Resolver { | ||
type Error: Into<BoxError>; | ||
|
||
fn resolve_account( | ||
&self, | ||
username: &str, | ||
domain: &str, | ||
) -> impl Future<Output = Result<Option<AccountResource>, Self::Error>> + Send; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters