chore: clippy warns, async_trait fixes

This commit is contained in:
əlemi 2024-09-19 16:51:20 +02:00
parent 0934cdaad4
commit 174ef4198d
Signed by: alemi
GPG key ID: A4895B84D311642C
12 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,5 @@
use sea_orm::{EntityTrait, TransactionTrait}; use sea_orm::{EntityTrait, TransactionTrait};
use upub::traits::{fetch::{Fetchable, RequestError}, Addresser, Fetcher, Normalizer}; use upub::traits::{fetch::RequestError, Addresser, Fetcher, Normalizer};
pub async fn fetch(ctx: upub::Context, uri: String, save: bool, actor: Option<String>) -> Result<(), RequestError> { pub async fn fetch(ctx: upub::Context, uri: String, save: bool, actor: Option<String>) -> Result<(), RequestError> {
use apb::Base; use apb::Base;
@ -48,11 +48,11 @@ pub async fn fetch(ctx: upub::Context, uri: String, save: bool, actor: Option<St
}, },
Ok(apb::BaseType::Object(apb::ObjectType::Activity(_))) => { Ok(apb::BaseType::Object(apb::ObjectType::Activity(_))) => {
let act = ctx.insert_activity(obj, &tx).await?; let act = ctx.insert_activity(obj, &tx).await?;
ctx.address((Some(&act), None), &tx).await?; ctx.address(Some(&act), None, &tx).await?;
}, },
Ok(apb::BaseType::Object(apb::ObjectType::Note)) => { Ok(apb::BaseType::Object(apb::ObjectType::Note)) => {
let obj = ctx.insert_object(obj, &tx).await?; let obj = ctx.insert_object(obj, &tx).await?;
ctx.address((None, Some(&obj)), &tx).await?; ctx.address(None, Some(&obj), &tx).await?;
}, },
Ok(apb::BaseType::Object(t)) => tracing::warn!("not implemented: {:?}", t), Ok(apb::BaseType::Object(t)) => tracing::warn!("not implemented: {:?}", t),
Ok(apb::BaseType::Link(_)) => tracing::error!("fetched another link?"), Ok(apb::BaseType::Link(_)) => tracing::error!("fetched another link?"),

View file

@ -1,6 +1,6 @@
use sea_orm::{ConnectionTrait, PaginatorTrait}; use sea_orm::{ConnectionTrait, PaginatorTrait};
#[allow(async_fn_in_trait)]
pub trait AnyQuery { pub trait AnyQuery {
async fn any(self, db: &impl ConnectionTrait) -> Result<bool, sea_orm::DbErr>; async fn any(self, db: &impl ConnectionTrait) -> Result<bool, sea_orm::DbErr>;
} }

View file

@ -3,6 +3,7 @@ use std::collections::{hash_map::Entry, HashMap};
use sea_orm::{ConnectionTrait, DbErr, EntityTrait, FromQueryResult, ModelTrait, QueryFilter}; use sea_orm::{ConnectionTrait, DbErr, EntityTrait, FromQueryResult, ModelTrait, QueryFilter};
use super::RichActivity; use super::RichActivity;
#[allow(async_fn_in_trait)]
pub trait BatchFillable: Sized { pub trait BatchFillable: Sized {
async fn with_batched<E>(self, tx: &impl ConnectionTrait) -> Result<Self, DbErr> async fn with_batched<E>(self, tx: &impl ConnectionTrait) -> Result<Self, DbErr>
where where
@ -114,6 +115,7 @@ use crate::selector::rich::{RichHashtag, RichMention};
} }
} }
#[allow(async_fn_in_trait)]
pub trait BatchFillableAcceptor<B> { pub trait BatchFillableAcceptor<B> {
async fn accept(&mut self, batch: B, tx: &impl ConnectionTrait) -> Result<(), DbErr>; async fn accept(&mut self, batch: B, tx: &impl ConnectionTrait) -> Result<(), DbErr>;
} }

View file

@ -5,6 +5,7 @@ use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, ConnectionTrait, DbErr, E
use crate::traits::fetch::Fetcher; use crate::traits::fetch::Fetcher;
#[allow(async_fn_in_trait)]
pub trait Addresser { pub trait Addresser {
async fn deliver(&self, to: Vec<String>, aid: &str, from: &str, tx: &impl ConnectionTrait) -> Result<(), DbErr>; async fn deliver(&self, to: Vec<String>, aid: &str, from: &str, tx: &impl ConnectionTrait) -> Result<(), DbErr>;
async fn address(&self, activity: Option<&crate::model::activity::Model>, object: Option<&crate::model::object::Model>, tx: &impl ConnectionTrait) -> Result<(), DbErr>; async fn address(&self, activity: Option<&crate::model::activity::Model>, object: Option<&crate::model::object::Model>, tx: &impl ConnectionTrait) -> Result<(), DbErr>;

View file

@ -2,6 +2,7 @@ use sea_orm::{ActiveValue::{NotSet, Set}, DbErr, EntityTrait};
use crate::ext::JsonVec; use crate::ext::JsonVec;
#[allow(async_fn_in_trait)]
pub trait Administrable { pub trait Administrable {
async fn register_user( async fn register_user(
&self, &self,

View file

@ -463,6 +463,7 @@ async fn resolve_object_r(ctx: &crate::Context, object: serde_json::Value, depth
Ok(object_model) Ok(object_model)
} }
#[allow(async_fn_in_trait)]
pub trait Fetchable : Sync + Send { pub trait Fetchable : Sync + Send {
async fn fetch(&mut self, ctx: &crate::Context) -> Result<&mut Self, RequestError>; async fn fetch(&mut self, ctx: &crate::Context) -> Result<&mut Self, RequestError>;
} }

View file

@ -15,6 +15,7 @@ pub enum NormalizerError {
DbErr(#[from] sea_orm::DbErr), DbErr(#[from] sea_orm::DbErr),
} }
#[allow(async_fn_in_trait)]
pub trait Normalizer { pub trait Normalizer {
async fn insert_object(&self, obj: impl apb::Object, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, NormalizerError>; async fn insert_object(&self, obj: impl apb::Object, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, NormalizerError>;
async fn insert_activity(&self, act: impl apb::Activity, tx: &impl ConnectionTrait) -> Result<crate::model::activity::Model, NormalizerError>; async fn insert_activity(&self, act: impl apb::Activity, tx: &impl ConnectionTrait) -> Result<crate::model::activity::Model, NormalizerError>;

View file

@ -29,10 +29,12 @@ pub enum ProcessorError {
PullError(#[from] crate::traits::fetch::RequestError), PullError(#[from] crate::traits::fetch::RequestError),
} }
#[async_trait::async_trait]
pub trait Processor { pub trait Processor {
async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError>; async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError>;
} }
#[async_trait::async_trait]
impl Processor for crate::Context { impl Processor for crate::Context {
async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> {
// TODO we could process Links and bare Objects maybe, but probably out of AP spec? // TODO we could process Links and bare Objects maybe, but probably out of AP spec?

View file

@ -33,3 +33,8 @@ nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs", rev = "
# mastodon # mastodon
mastodon-async-entities = { version = "1.1.0", optional = true } mastodon-async-entities = { version = "1.1.0", optional = true }
time = { version = "0.3", features = ["serde"], optional = true } time = { version = "0.3", features = ["serde"], optional = true }
[features]
default = []
mastodon = ["dep:mastodon-async-entities"]
web = []

View file

@ -62,6 +62,7 @@ impl Identity {
pub struct AuthIdentity(pub Identity); pub struct AuthIdentity(pub Identity);
#[axum::async_trait]
impl<S> FromRequestParts<S> for AuthIdentity impl<S> FromRequestParts<S> for AuthIdentity
where where
upub::Context: FromRef<S>, upub::Context: FromRef<S>,

View file

@ -3,6 +3,7 @@ use reqwest::Method;
use apb::{LD, ActivityMut}; use apb::{LD, ActivityMut};
use upub::{Context, model, traits::Fetcher}; use upub::{Context, model, traits::Fetcher};
#[allow(clippy::manual_map)] // TODO can Update code be improved?
pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> { pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> {
tracing::info!("delivering {} to {:?}", job.activity, job.target); tracing::info!("delivering {} to {:?}", job.activity, job.target);

View file

@ -29,6 +29,7 @@ pub enum JobError {
pub type JobResult<T> = Result<T, JobError>; pub type JobResult<T> = Result<T, JobError>;
#[allow(async_fn_in_trait)]
pub trait JobDispatcher : Sized { pub trait JobDispatcher : Sized {
async fn poll(&self, filter: Option<model::job::JobType>) -> JobResult<Option<model::job::Model>>; async fn poll(&self, filter: Option<model::job::JobType>) -> JobResult<Option<model::job::Model>>;
async fn lock(&self, job_internal: i64) -> JobResult<bool>; async fn lock(&self, job_internal: i64) -> JobResult<bool>;