From b666d339f258348e46a3b21f5e789d7fa169965c Mon Sep 17 00:00:00 2001 From: aprilthepink Date: Sat, 3 Aug 2024 04:14:38 +0200 Subject: [PATCH] fmt: codebase --- src/activities/follow.rs | 1 - src/lysand/http.rs | 14 ++++++----- src/lysand/inbox.rs | 51 ++++++++++++++++++++++++++++------------ src/lysand/mod.rs | 2 +- src/main.rs | 5 +++- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/activities/follow.rs b/src/activities/follow.rs index be716c1..dd9dd7c 100644 --- a/src/activities/follow.rs +++ b/src/activities/follow.rs @@ -171,7 +171,6 @@ async fn save_follow( } // modify db entry let res = prelude::FollowRelation::update(query.unwrap()); - Ok(model) } diff --git a/src/lysand/http.rs b/src/lysand/http.rs index 082cc03..76d2b82 100644 --- a/src/lysand/http.rs +++ b/src/lysand/http.rs @@ -88,8 +88,6 @@ async fn lysand_inbox( body: web::Bytes, state: web::Data, ) -> actix_web::Result { - - Ok(HttpResponse::Created().finish()) } @@ -212,13 +210,16 @@ pub async fn lysand_url_to_user(url: Url) -> anyhow::Result::from(url) .dereference(&data.to_request_data()) - .await.unwrap(); + .await + .unwrap(); } Ok(lysand_user_from_db(target).await?) } -pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::objects::User, user::Model)> { +pub async fn lysand_url_to_user_and_model( + url: Url, +) -> anyhow::Result<(super::objects::User, user::Model)> { let db = DB.get().unwrap(); let data = FEDERATION_CONFIG.get().unwrap(); @@ -232,8 +233,9 @@ pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::ob } else { target = ObjectId::::from(url) .dereference(&data.to_request_data()) - .await.unwrap(); + .await + .unwrap(); } Ok((lysand_user_from_db(target.clone()).await?, target)) -} \ No newline at end of file +} diff --git a/src/lysand/inbox.rs b/src/lysand/inbox.rs index 2624ce5..a41cbf3 100644 --- a/src/lysand/inbox.rs +++ b/src/lysand/inbox.rs @@ -1,13 +1,27 @@ - -use activitypub_federation::{activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext}; +use crate::{ + activities::follow::Follow, + entities::{ + self, follow_relation, + prelude::{self, FollowRelation}, + user, + }, + utils::generate_follow_req_id, + DB, FEDERATION_CONFIG, +}; +use activitypub_federation::{ + activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext, +}; use activitystreams_kinds::activity::FollowType; use anyhow::Result; use sea_orm::{ActiveModelTrait, ColumnTrait, EntityOrSelect, EntityTrait, QueryFilter, Set}; use serde::Deserialize; use url::Url; -use crate::{activities::follow::Follow, entities::{self, follow_relation, prelude::{self, FollowRelation}, user}, utils::generate_follow_req_id, DB, FEDERATION_CONFIG}; -use super::{conversion::lysand_user_from_db, http::{lysand_url_to_user, lysand_url_to_user_and_model}, objects::LysandType}; +use super::{ + conversion::lysand_user_from_db, + http::{lysand_url_to_user, lysand_url_to_user_and_model}, + objects::LysandType, +}; pub async fn inbox_entry(json: &str) -> Result<()> { // Deserialize the JSON string into a dynamic value @@ -19,27 +33,25 @@ pub async fn inbox_entry(json: &str) -> Result<()> { match json_type.as_str() { Some("Note") => { let note: super::objects::Note = serde_json::from_str(json)?; - } Some("Patch") => { let patch: super::objects::Patch = serde_json::from_str(json)?; - } Some("Follow") => { let follow_req: super::objects::Follow = serde_json::from_str(json)?; - } Some("FollowAccept") => { let follow_accept: super::objects::FollowResult = serde_json::from_str(json)?; - } Some("FollowReject") => { let follow_rej: super::objects::FollowResult = serde_json::from_str(json)?; - } // Add more cases for other types as needed _ => { - return Err(anyhow::anyhow!("Unknown 'type' field in JSON, it is {}", json_type)); + return Err(anyhow::anyhow!( + "Unknown 'type' field in JSON, it is {}", + json_type + )); } } } else { @@ -57,20 +69,29 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> { .one(db) .await?; if query.is_some() { - return Err(anyhow::anyhow!("User is already follow requesting / following the followee")); + return Err(anyhow::anyhow!( + "User is already follow requesting / following the followee" + )); } let data = FEDERATION_CONFIG.get().unwrap(); let author = lysand_url_to_user_and_model(follow.author.into()).await?; let followee = lysand_url_to_user_and_model(follow.followee.into()).await?; - let serial_ap_author = serde_json::from_str::(&(author.1.ap_json.clone()).unwrap())?; - let serial_ap_followee = serde_json::from_str::(&(followee.1.ap_json.clone()).unwrap())?; + let serial_ap_author = serde_json::from_str::( + &(author.1.ap_json.clone()).unwrap(), + )?; + let serial_ap_followee = serde_json::from_str::( + &(followee.1.ap_json.clone()).unwrap(), + )?; let id = uuid::Uuid::now_v7().to_string(); let followee_object: ObjectId = serial_ap_followee.url.into(); let localuser_object: ObjectId = serial_ap_author.url.into(); - println!("Sending follow request to {}", &followee.0.display_name.unwrap_or(followee.0.username)); + println!( + "Sending follow request to {}", + &followee.0.display_name.unwrap_or(followee.0.username) + ); let create = Follow { actor: localuser_object.clone(), object: followee_object.clone(), @@ -106,4 +127,4 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> { } Ok(()) -} \ No newline at end of file +} diff --git a/src/lysand/mod.rs b/src/lysand/mod.rs index c258f10..c1d0526 100644 --- a/src/lysand/mod.rs +++ b/src/lysand/mod.rs @@ -1,7 +1,7 @@ pub mod conversion; pub mod funcs; pub mod http; +pub mod inbox; pub mod objects; pub mod superx; pub mod test; -pub mod inbox; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3f88120..47affc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -289,7 +289,10 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { .service(follow_manually) .route("/{user}", web::get().to(http_get_user)) .route("/{user}/inbox", web::post().to(http_post_user_inbox)) - .route("/apbridge/{user}/inbox", web::post().to(http_post_user_inbox)) + .route( + "/apbridge/{user}/inbox", + web::post().to(http_post_user_inbox), + ) .route("/.well-known/webfinger", web::get().to(webfinger)) .service(index) .service(fetch_post)