diff --git a/src/backend/api/article.rs b/src/backend/api/article.rs index 79d00bb..76eb9ae 100644 --- a/src/backend/api/article.rs +++ b/src/backend/api/article.rs @@ -1,7 +1,7 @@ use crate::backend::database::article::DbArticleForm; use crate::backend::database::conflict::{DbConflict, DbConflictForm}; use crate::backend::database::edit::DbEditForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::activities::create_article::CreateArticle; use crate::backend::federation::activities::submit_article_update; @@ -27,7 +27,7 @@ use diffy::create_patch; #[debug_handler] pub(in crate::backend::api) async fn create_article( Extension(user): Extension, - data: Data, + data: Data, Form(create_article): Form, ) -> MyResult> { if create_article.title.is_empty() { @@ -77,7 +77,7 @@ pub(in crate::backend::api) async fn create_article( #[debug_handler] pub(in crate::backend::api) async fn edit_article( Extension(user): Extension, - data: Data, + data: Data, Form(mut edit_form): Form, ) -> MyResult>> { // resolve conflict if any @@ -139,7 +139,7 @@ pub(in crate::backend::api) async fn edit_article( #[debug_handler] pub(in crate::backend::api) async fn get_article( Query(query): Query, - data: Data, + data: Data, ) -> MyResult> { match (query.title, query.id) { (Some(title), None) => Ok(Json(DbArticle::read_view_title( @@ -160,7 +160,7 @@ pub(in crate::backend::api) async fn get_article( #[debug_handler] pub(in crate::backend::api) async fn list_articles( Query(query): Query, - data: Data, + data: Data, ) -> MyResult>> { let only_local = query.only_local.unwrap_or(false); Ok(Json(DbArticle::read_all(only_local, &data.db_connection)?)) @@ -171,7 +171,7 @@ pub(in crate::backend::api) async fn list_articles( #[debug_handler] pub(in crate::backend::api) async fn fork_article( Extension(_user): Extension, - data: Data, + data: Data, Form(fork_form): Form, ) -> MyResult> { // TODO: lots of code duplicated from create_article(), can move it into helper @@ -221,7 +221,7 @@ pub(in crate::backend::api) async fn fork_article( #[debug_handler] pub(super) async fn resolve_article( Query(query): Query, - data: Data, + data: Data, ) -> MyResult> { let article: DbArticle = ObjectId::from(query.id).dereference(&data).await?; let edits = DbEdit::read_for_article(&article, &data.db_connection)?; @@ -237,7 +237,7 @@ pub(super) async fn resolve_article( #[debug_handler] pub(super) async fn search_article( Query(query): Query, - data: Data, + data: Data, ) -> MyResult>> { let article = DbArticle::search(&query.query, &data.db_connection)?; Ok(Json(article)) diff --git a/src/backend/api/instance.rs b/src/backend/api/instance.rs index 0b5719d..da08c13 100644 --- a/src/backend/api/instance.rs +++ b/src/backend/api/instance.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::activities::follow::Follow; use crate::common::{DbInstance, InstanceView, ResolveObject}; @@ -13,7 +13,7 @@ use axum_macros::debug_handler; /// Retrieve the local instance info. #[debug_handler] pub(in crate::backend::api) async fn get_local_instance( - data: Data, + data: Data, ) -> MyResult> { let local_instance = DbInstance::read_local_view(&data.db_connection)?; Ok(Json(local_instance)) @@ -24,7 +24,7 @@ pub(in crate::backend::api) async fn get_local_instance( #[debug_handler] pub(in crate::backend::api) async fn follow_instance( Extension(user): Extension, - data: Data, + data: Data, Form(query): Form, ) -> MyResult<()> { let target = DbInstance::read(query.id, &data.db_connection)?; @@ -40,7 +40,7 @@ pub(in crate::backend::api) async fn follow_instance( #[debug_handler] pub(super) async fn resolve_instance( Query(query): Query, - data: Data, + data: Data, ) -> MyResult> { let instance: DbInstance = ObjectId::from(query.id).dereference(&data).await?; Ok(Json(instance)) diff --git a/src/backend/api/mod.rs b/src/backend/api/mod.rs index cccf3f5..dbbe629 100644 --- a/src/backend/api/mod.rs +++ b/src/backend/api/mod.rs @@ -9,7 +9,7 @@ use crate::backend::api::user::validate; use crate::backend::api::user::{login_user, logout_user}; use crate::backend::api::user::{my_profile, AUTH_COOKIE}; use crate::backend::database::conflict::DbConflict; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::common::ApiConflict; use crate::common::LocalUserView; @@ -54,7 +54,7 @@ pub fn api_routes() -> Router { } async fn auth( - data: Data, + data: Data, jar: CookieJar, mut request: Request, next: Next, @@ -74,7 +74,7 @@ async fn auth( #[debug_handler] async fn edit_conflicts( Extension(user): Extension, - data: Data, + data: Data, ) -> MyResult>> { let conflicts = DbConflict::list(&user.local_user, &data.db_connection)?; let conflicts: Vec = try_join_all(conflicts.into_iter().map(|c| { diff --git a/src/backend/api/user.rs b/src/backend/api/user.rs index 4b53371..9a6d595 100644 --- a/src/backend/api/user.rs +++ b/src/backend/api/user.rs @@ -1,4 +1,4 @@ -use crate::backend::database::{read_jwt_secret, MyDataHandle}; +use crate::backend::database::{read_jwt_secret, IbisData}; use crate::backend::error::MyResult; use crate::common::{DbLocalUser, DbPerson, LocalUserView, LoginUserData, RegisterUserData}; use activitypub_federation::config::Data; @@ -29,7 +29,7 @@ struct Claims { pub exp: u64, } -fn generate_login_token(local_user: &DbLocalUser, data: &Data) -> MyResult { +fn generate_login_token(local_user: &DbLocalUser, data: &Data) -> MyResult { let hostname = data.domain().to_string(); let claims = Claims { sub: local_user.id.to_string(), @@ -44,7 +44,7 @@ fn generate_login_token(local_user: &DbLocalUser, data: &Data) -> Ok(jwt) } -pub async fn validate(jwt: &str, data: &Data) -> MyResult { +pub async fn validate(jwt: &str, data: &Data) -> MyResult { let validation = Validation::default(); let secret = read_jwt_secret(data)?; let key = DecodingKey::from_secret(secret.as_bytes()); @@ -54,7 +54,7 @@ pub async fn validate(jwt: &str, data: &Data) -> MyResult, + data: Data, jar: CookieJar, Form(form): Form, ) -> MyResult<(CookieJar, Json)> { @@ -69,7 +69,7 @@ pub(in crate::backend::api) async fn register_user( #[debug_handler] pub(in crate::backend::api) async fn login_user( - data: Data, + data: Data, jar: CookieJar, Form(form): Form, ) -> MyResult<(CookieJar, Json)> { @@ -83,7 +83,7 @@ pub(in crate::backend::api) async fn login_user( Ok((jar, Json(user))) } -fn create_cookie(jwt: String, data: &Data) -> Cookie<'static> { +fn create_cookie(jwt: String, data: &Data) -> Cookie<'static> { let mut domain = data.domain().to_string(); // remove port from domain if domain.contains(':') { @@ -103,7 +103,7 @@ fn create_cookie(jwt: String, data: &Data) -> Cookie<'static> { #[debug_handler] pub(in crate::backend::api) async fn my_profile( - data: Data, + data: Data, jar: CookieJar, ) -> MyResult> { let jwt = jar.get(AUTH_COOKIE).map(|c| c.value()); @@ -116,7 +116,7 @@ pub(in crate::backend::api) async fn my_profile( #[debug_handler] pub(in crate::backend::api) async fn logout_user( - data: Data, + data: Data, jar: CookieJar, ) -> MyResult { let jar = jar.remove(create_cookie(String::new(), &data)); diff --git a/src/backend/database/conflict.rs b/src/backend/database/conflict.rs index 63aa4d1..c1f9698 100644 --- a/src/backend/database/conflict.rs +++ b/src/backend/database/conflict.rs @@ -1,5 +1,5 @@ use crate::backend::database::schema::conflict; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::activities::submit_article_update; use crate::backend::utils::generate_article_version; @@ -63,10 +63,7 @@ impl DbConflict { Ok(delete(conflict::table.find(id)).get_result(conn.deref_mut())?) } - pub async fn to_api_conflict( - &self, - data: &Data, - ) -> MyResult> { + pub async fn to_api_conflict(&self, data: &Data) -> MyResult> { let article = DbArticle::read(self.article_id, &data.db_connection)?; // Make sure to get latest version from origin so that all conflicts can be resolved let original_article = article.ap_id.dereference_forced(data).await?; diff --git a/src/backend/database/instance.rs b/src/backend/database/instance.rs index 5b2a38d..ad0031d 100644 --- a/src/backend/database/instance.rs +++ b/src/backend/database/instance.rs @@ -1,5 +1,5 @@ use crate::backend::database::schema::{instance, instance_follow}; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::objects::articles_collection::DbArticleCollection; use crate::common::{DbInstance, DbPerson, InstanceView}; @@ -46,7 +46,7 @@ impl DbInstance { pub fn read_from_ap_id( ap_id: &ObjectId, - data: &Data, + data: &Data, ) -> MyResult { let mut conn = data.db_connection.lock().unwrap(); Ok(instance::table @@ -75,7 +75,7 @@ impl DbInstance { follower: &DbPerson, instance: &DbInstance, pending_: bool, - data: &Data, + data: &Data, ) -> MyResult<()> { use instance_follow::dsl::{follower_id, instance_id, pending}; let mut conn = data.db_connection.lock().unwrap(); diff --git a/src/backend/database/mod.rs b/src/backend/database/mod.rs index 3ce9071..7ebe13b 100644 --- a/src/backend/database/mod.rs +++ b/src/backend/database/mod.rs @@ -1,13 +1,11 @@ -use diesel::PgConnection; -use std::ops::Deref; -use std::sync::{Arc, Mutex}; -// TODO: can remove this -pub type MyDataHandle = IbisData; use crate::backend::database::schema::jwt_secret; use crate::backend::error::MyResult; use crate::config::IbisConfig; +use diesel::PgConnection; use diesel::{QueryDsl, RunQueryDsl}; +use std::ops::Deref; use std::ops::DerefMut; +use std::sync::{Arc, Mutex}; pub mod article; pub mod conflict; diff --git a/src/backend/database/user.rs b/src/backend/database/user.rs index e7fa6bb..9fbbb79 100644 --- a/src/backend/database/user.rs +++ b/src/backend/database/user.rs @@ -1,6 +1,6 @@ use crate::backend::database::schema::{instance, instance_follow}; use crate::backend::database::schema::{local_user, person}; -use crate::backend::database::{IbisData, MyDataHandle}; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::common::{DbInstance, DbLocalUser, DbPerson, LocalUserView}; use activitypub_federation::config::Data; @@ -46,7 +46,7 @@ impl DbPerson { .get_result::(conn.deref_mut())?) } - pub fn read(id: i32, data: &Data) -> MyResult { + pub fn read(id: i32, data: &Data) -> MyResult { let mut conn = data.db_connection.lock().unwrap(); Ok(person::table.find(id).get_result(conn.deref_mut())?) } @@ -95,7 +95,7 @@ impl DbPerson { pub fn read_from_ap_id( ap_id: &ObjectId, - data: &Data, + data: &Data, ) -> MyResult { let mut conn = data.db_connection.lock().unwrap(); Ok(person::table @@ -103,10 +103,7 @@ impl DbPerson { .get_result(conn.deref_mut())?) } - pub fn read_local_from_name( - username: &str, - data: &Data, - ) -> MyResult { + pub fn read_local_from_name(username: &str, data: &Data) -> MyResult { let mut conn = data.db_connection.lock().unwrap(); let (person, local_user) = person::table .inner_join(local_user::table) @@ -122,7 +119,7 @@ impl DbPerson { }) } - pub fn read_local_from_id(id: i32, data: &Data) -> MyResult { + pub fn read_local_from_id(id: i32, data: &Data) -> MyResult { let mut conn = data.db_connection.lock().unwrap(); let (person, local_user) = person::table .inner_join(local_user::table) diff --git a/src/backend/federation/activities/accept.rs b/src/backend/federation/activities/accept.rs index 65fad0e..4da47c6 100644 --- a/src/backend/federation/activities/accept.rs +++ b/src/backend/federation/activities/accept.rs @@ -1,7 +1,7 @@ use crate::backend::error::MyResult; use crate::backend::federation::send_activity; use crate::backend::utils::generate_activity_id; -use crate::backend::{database::MyDataHandle, federation::activities::follow::Follow}; +use crate::backend::{database::IbisData, federation::activities::follow::Follow}; use crate::common::DbInstance; use activitypub_federation::traits::Actor; use activitypub_federation::{ @@ -24,7 +24,7 @@ impl Accept { pub async fn send( local_instance: DbInstance, object: Follow, - data: &Data, + data: &Data, ) -> MyResult<()> { let id = generate_activity_id(local_instance.ap_id.inner())?; let follower = object.actor.dereference(data).await?; @@ -47,7 +47,7 @@ impl Accept { #[async_trait::async_trait] impl ActivityHandler for Accept { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/activities/create_article.rs b/src/backend/federation/activities/create_article.rs index 2ef32e8..676477c 100644 --- a/src/backend/federation/activities/create_article.rs +++ b/src/backend/federation/activities/create_article.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::objects::article::ApubArticle; use crate::backend::utils::generate_activity_id; @@ -27,7 +27,7 @@ pub struct CreateArticle { } impl CreateArticle { - pub async fn send_to_followers(article: DbArticle, data: &Data) -> MyResult<()> { + pub async fn send_to_followers(article: DbArticle, data: &Data) -> MyResult<()> { let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let object = article.clone().into_json(data).await?; let id = generate_activity_id(local_instance.ap_id.inner())?; @@ -47,7 +47,7 @@ impl CreateArticle { } #[async_trait::async_trait] impl ActivityHandler for CreateArticle { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/activities/follow.rs b/src/backend/federation/activities/follow.rs index 11c36b8..30ca8dc 100644 --- a/src/backend/federation/activities/follow.rs +++ b/src/backend/federation/activities/follow.rs @@ -1,7 +1,7 @@ use crate::backend::error::MyResult; use crate::backend::federation::send_activity; use crate::backend::{ - database::MyDataHandle, federation::activities::accept::Accept, generate_activity_id, + database::IbisData, federation::activities::accept::Accept, generate_activity_id, }; use crate::common::DbInstance; use crate::common::DbPerson; @@ -26,7 +26,7 @@ pub struct Follow { } impl Follow { - pub async fn send(actor: DbPerson, to: DbInstance, data: &Data) -> MyResult<()> { + pub async fn send(actor: DbPerson, to: DbInstance, data: &Data) -> MyResult<()> { let id = generate_activity_id(actor.ap_id.inner())?; let follow = Follow { actor: actor.ap_id.clone(), @@ -41,7 +41,7 @@ impl Follow { #[async_trait::async_trait] impl ActivityHandler for Follow { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/activities/mod.rs b/src/backend/federation/activities/mod.rs index de20200..f46c150 100644 --- a/src/backend/federation/activities/mod.rs +++ b/src/backend/federation/activities/mod.rs @@ -1,5 +1,5 @@ use crate::backend::database::edit::DbEditForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::federation::activities::update_local_article::UpdateLocalArticle; use crate::backend::federation::activities::update_remote_article::UpdateRemoteArticle; @@ -22,7 +22,7 @@ pub async fn submit_article_update( previous_version: EditVersion, original_article: &DbArticle, creator_id: i32, - data: &Data, + data: &Data, ) -> Result<(), Error> { let form = DbEditForm::new( original_article, diff --git a/src/backend/federation/activities/reject.rs b/src/backend/federation/activities/reject.rs index 11bb175..1c0d9a8 100644 --- a/src/backend/federation/activities/reject.rs +++ b/src/backend/federation/activities/reject.rs @@ -1,5 +1,5 @@ use crate::backend::database::conflict::{DbConflict, DbConflictForm}; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::objects::edit::ApubEdit; use crate::backend::utils::generate_activity_id; @@ -31,7 +31,7 @@ impl RejectEdit { pub async fn send( edit: ApubEdit, user_instance: DbInstance, - data: &Data, + data: &Data, ) -> MyResult<()> { let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let id = generate_activity_id(local_instance.ap_id.inner())?; @@ -55,7 +55,7 @@ impl RejectEdit { #[async_trait::async_trait] impl ActivityHandler for RejectEdit { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/activities/update_local_article.rs b/src/backend/federation/activities/update_local_article.rs index a14162d..f223112 100644 --- a/src/backend/federation/activities/update_local_article.rs +++ b/src/backend/federation/activities/update_local_article.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::objects::article::ApubArticle; @@ -33,7 +33,7 @@ impl UpdateLocalArticle { pub async fn send( article: DbArticle, extra_recipients: Vec, - data: &Data, + data: &Data, ) -> MyResult<()> { debug_assert!(article.local); let local_instance = DbInstance::read_local_instance(&data.db_connection)?; @@ -56,7 +56,7 @@ impl UpdateLocalArticle { #[async_trait::async_trait] impl ActivityHandler for UpdateLocalArticle { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/activities/update_remote_article.rs b/src/backend/federation/activities/update_remote_article.rs index 33897b7..1507a9f 100644 --- a/src/backend/federation/activities/update_remote_article.rs +++ b/src/backend/federation/activities/update_remote_article.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::MyResult; use crate::backend::federation::activities::reject::RejectEdit; @@ -37,7 +37,7 @@ impl UpdateRemoteArticle { pub async fn send( edit: DbEdit, article_instance: DbInstance, - data: &Data, + data: &Data, ) -> MyResult<()> { let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let id = generate_activity_id(local_instance.ap_id.inner())?; @@ -61,7 +61,7 @@ impl UpdateRemoteArticle { #[async_trait::async_trait] impl ActivityHandler for UpdateRemoteArticle { - type DataType = MyDataHandle; + type DataType = IbisData; type Error = crate::backend::error::Error; fn id(&self) -> &Url { diff --git a/src/backend/federation/mod.rs b/src/backend/federation/mod.rs index 3feeba9..0275cd2 100644 --- a/src/backend/federation/mod.rs +++ b/src/backend/federation/mod.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::config::IbisConfig; use activitypub_federation::activity_sending::SendActivityTask; use activitypub_federation::config::{Data, UrlVerifier}; @@ -19,7 +19,7 @@ pub async fn send_activity( actor: &ActorType, activity: Activity, recipients: Vec, - data: &Data, + data: &Data, ) -> Result<(), ::Error> where Activity: ActivityHandler + Serialize + Debug + Send + Sync, diff --git a/src/backend/federation/objects/article.rs b/src/backend/federation/objects/article.rs index faafb26..741c005 100644 --- a/src/backend/federation/objects/article.rs +++ b/src/backend/federation/objects/article.rs @@ -1,5 +1,5 @@ use crate::backend::database::article::DbArticleForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::federation::objects::edits_collection::DbEditCollection; use crate::common::DbArticle; @@ -33,7 +33,7 @@ pub struct ApubArticle { #[async_trait::async_trait] impl Object for DbArticle { - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ApubArticle; type Error = Error; diff --git a/src/backend/federation/objects/articles_collection.rs b/src/backend/federation/objects/articles_collection.rs index 5b194b5..5463eb2 100644 --- a/src/backend/federation/objects/articles_collection.rs +++ b/src/backend/federation/objects/articles_collection.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::federation::objects::article::ApubArticle; use crate::common::DbInstance; @@ -29,7 +29,7 @@ pub struct DbArticleCollection(Vec); #[async_trait::async_trait] impl Collection for DbArticleCollection { type Owner = DbInstance; - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ArticleCollection; type Error = Error; diff --git a/src/backend/federation/objects/edit.rs b/src/backend/federation/objects/edit.rs index aa3ed6b..6b8f3fa 100644 --- a/src/backend/federation/objects/edit.rs +++ b/src/backend/federation/objects/edit.rs @@ -1,5 +1,5 @@ use crate::backend::database::edit::DbEditForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::common::DbPerson; use crate::common::EditVersion; @@ -35,7 +35,7 @@ pub struct ApubEdit { #[async_trait::async_trait] impl Object for DbEdit { - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ApubEdit; type Error = Error; diff --git a/src/backend/federation/objects/edits_collection.rs b/src/backend/federation/objects/edits_collection.rs index 8a8789b..b62b0d3 100644 --- a/src/backend/federation/objects/edits_collection.rs +++ b/src/backend/federation/objects/edits_collection.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::federation::objects::edit::ApubEdit; use crate::common::DbArticle; @@ -30,7 +30,7 @@ pub struct DbEditCollection(pub Vec); #[async_trait::async_trait] impl Collection for DbEditCollection { type Owner = DbArticle; - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ApubEditCollection; type Error = Error; diff --git a/src/backend/federation/objects/instance.rs b/src/backend/federation/objects/instance.rs index c18fbe0..69e33f9 100644 --- a/src/backend/federation/objects/instance.rs +++ b/src/backend/federation/objects/instance.rs @@ -1,5 +1,5 @@ use crate::backend::database::instance::DbInstanceForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::federation::objects::articles_collection::DbArticleCollection; use crate::backend::federation::send_activity; @@ -38,7 +38,7 @@ impl DbInstance { Ok(Url::parse(&format!("{}/followers", self.ap_id.inner()))?) } - pub fn follower_ids(&self, data: &Data) -> MyResult> { + pub fn follower_ids(&self, data: &Data) -> MyResult> { Ok(DbInstance::read_followers(self.id, &data.db_connection)? .into_iter() .map(|f| f.ap_id.into()) @@ -49,7 +49,7 @@ impl DbInstance { &self, activity: Activity, extra_recipients: Vec, - data: &Data, + data: &Data, ) -> Result<(), ::Error> where Activity: ActivityHandler + Serialize + Debug + Send + Sync, @@ -72,7 +72,7 @@ impl DbInstance { #[async_trait::async_trait] impl Object for DbInstance { - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ApubInstance; type Error = Error; diff --git a/src/backend/federation/objects/user.rs b/src/backend/federation/objects/user.rs index 86b765e..c392418 100644 --- a/src/backend/federation/objects/user.rs +++ b/src/backend/federation/objects/user.rs @@ -1,5 +1,5 @@ use crate::backend::database::user::DbPersonForm; -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::common::DbPerson; use activitypub_federation::kinds::actor::PersonType; @@ -27,7 +27,7 @@ pub struct ApubUser { #[async_trait::async_trait] impl Object for DbPerson { - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = ApubUser; type Error = Error; diff --git a/src/backend/federation/routes.rs b/src/backend/federation/routes.rs index f3cd191..9d0d986 100644 --- a/src/backend/federation/routes.rs +++ b/src/backend/federation/routes.rs @@ -1,4 +1,4 @@ -use crate::backend::database::MyDataHandle; +use crate::backend::database::IbisData; use crate::backend::error::Error; use crate::backend::error::MyResult; use crate::backend::federation::activities::accept::Accept; @@ -45,7 +45,7 @@ pub fn federation_routes() -> Router { #[debug_handler] async fn http_get_instance( - data: Data, + data: Data, ) -> MyResult>> { let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let json_instance = local_instance.into_json(&data).await?; @@ -55,7 +55,7 @@ async fn http_get_instance( #[debug_handler] async fn http_get_person( Path(name): Path, - data: Data, + data: Data, ) -> MyResult>> { let person = DbPerson::read_local_from_name(&name, &data)?.person; let json_person = person.into_json(&data).await?; @@ -64,7 +64,7 @@ async fn http_get_person( #[debug_handler] async fn http_get_all_articles( - data: Data, + data: Data, ) -> MyResult>> { let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let collection = DbArticleCollection::read_local(&local_instance, &data).await?; @@ -74,7 +74,7 @@ async fn http_get_all_articles( #[debug_handler] async fn http_get_article( Path(title): Path, - data: Data, + data: Data, ) -> MyResult>> { let article = DbArticle::read_local_title(&title, &data.db_connection)?; let json = article.into_json(&data).await?; @@ -84,7 +84,7 @@ async fn http_get_article( #[debug_handler] async fn http_get_article_edits( Path(title): Path, - data: Data, + data: Data, ) -> MyResult>> { let article = DbArticle::read_local_title(&title, &data.db_connection)?; let json = DbEditCollection::read_local(&article, &data).await?; @@ -106,14 +106,11 @@ pub enum InboxActivities { #[debug_handler] pub async fn http_post_inbox( - data: Data, + data: Data, activity_data: ActivityData, ) -> impl IntoResponse { - receive_activity::, UserOrInstance, MyDataHandle>( - activity_data, - &data, - ) - .await + receive_activity::, UserOrInstance, IbisData>(activity_data, &data) + .await } #[derive(Clone, Debug)] @@ -137,7 +134,7 @@ pub enum PersonOrInstanceType { #[async_trait::async_trait] impl Object for UserOrInstance { - type DataType = MyDataHandle; + type DataType = IbisData; type Kind = PersonOrInstance; type Error = Error; diff --git a/tests/test.rs b/tests/test.rs index 13d556b..857d390 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -104,11 +104,9 @@ async fn test_follow_instance() -> MyResult<()> { assert_eq!(0, beta_instance.followers.len()); data.alpha.follow_instance(&data.beta.hostname).await?; - dbg!(&data.alpha.hostname, &data.beta.hostname); // check that follow was federated let alpha_user = data.alpha.my_profile().await?; - dbg!(&alpha_user); assert_eq!(1, alpha_user.following.len()); assert_eq!(beta_instance.instance.ap_id, alpha_user.following[0].ap_id);