From 9da28935e012687f90e57ec999f93207c27f032e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 6 Mar 2024 15:33:16 +0100 Subject: [PATCH] fmt --- crates/apub/src/api/resolve_object.rs | 28 ++++++++++------------ crates/apub/src/fetcher/search.rs | 34 ++++++++++++--------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index d7edb2846..3447dc904 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -1,7 +1,6 @@ -use crate::fetcher::search::{ - search_query_to_object_id, - search_query_to_object_id_local, - SearchableObjects, +use crate::fetcher::{ + search::{search_query_to_object_id, search_query_to_object_id_local, SearchableObjects}, + user_or_community::UserOrCommunity, }; use activitypub_federation::config::Data; use actix_web::web::{Json, Query}; @@ -15,7 +14,6 @@ use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils:: use lemmy_db_views::structs::{CommentView, LocalUserView, PostView}; use lemmy_db_views_actor::structs::{CommunityView, PersonView}; use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType}; -use crate::fetcher::user_or_community::UserOrCommunity; #[tracing::instrument(skip(context))] pub async fn resolve_object( @@ -61,18 +59,16 @@ async fn convert_response( removed_or_deleted = c.deleted || c.removed; res.comment = Some(CommentView::read(pool, c.id, user_id).await?) } - PersonOrCommunity(p) => { - match p { - UserOrCommunity::User(u) => { - removed_or_deleted = u.deleted; - res.person = Some(PersonView::read(pool, u.id).await?) - } - UserOrCommunity::Community(c) => { - removed_or_deleted = c.deleted || c.removed; - res.community = Some(CommunityView::read(pool, c.id, user_id, false).await?) - } + PersonOrCommunity(p) => match p { + UserOrCommunity::User(u) => { + removed_or_deleted = u.deleted; + res.person = Some(PersonView::read(pool, u.id).await?) } - } + UserOrCommunity::Community(c) => { + removed_or_deleted = c.deleted || c.removed; + res.community = Some(CommunityView::read(pool, c.id, user_id, false).await?) + } + }, }; // if the object was deleted from database, dont return it if removed_or_deleted { diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index e78a9e998..f2cbad947 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -1,4 +1,5 @@ use crate::{ + fetcher::user_or_community::{PersonOrGroup, UserOrCommunity}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::objects::{note::Note, page::Page}, }; @@ -7,15 +8,12 @@ use activitypub_federation::{ fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor}, traits::Object, }; - use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::{LemmyError}; +use lemmy_utils::error::LemmyError; use serde::Deserialize; use url::Url; -use crate::fetcher::user_or_community::{PersonOrGroup, UserOrCommunity}; - /// Converts search query to object id. The query can either be an URL, which will be treated as /// ObjectId directly, or a webfinger identifier (@user@example.com or !community@example.com) /// which gets resolved to an URL. @@ -34,7 +32,9 @@ pub(crate) async fn search_query_to_object_id( if query.starts_with("!") || query.starts_with("@") { query.remove(0); } - SearchableObjects::PersonOrCommunity(webfinger_resolve_actor::(&query, context).await?) + SearchableObjects::PersonOrCommunity( + webfinger_resolve_actor::(&query, context).await?, + ) } }) } @@ -56,7 +56,7 @@ pub(crate) async fn search_query_to_object_id_local( pub(crate) enum SearchableObjects { Post(ApubPost), Comment(ApubComment), - PersonOrCommunity(UserOrCommunity) + PersonOrCommunity(UserOrCommunity), } #[derive(Deserialize)] @@ -64,7 +64,7 @@ pub(crate) enum SearchableObjects { pub(crate) enum SearchableKinds { Page(Page), Note(Note), - PersonOrGroup(PersonOrGroup) + PersonOrGroup(PersonOrGroup), } #[async_trait::async_trait] @@ -111,12 +111,10 @@ impl Object for SearchableObjects { match self { SearchableObjects::Post(p) => p.delete(data).await, SearchableObjects::Comment(c) => c.delete(data).await, - SearchableObjects::PersonOrCommunity(pc) => { - match pc { - UserOrCommunity::User(p) => p.delete(data).await, - UserOrCommunity::Community(c) => c.delete(data).await, - } - } + SearchableObjects::PersonOrCommunity(pc) => match pc { + UserOrCommunity::User(p) => p.delete(data).await, + UserOrCommunity::Community(c) => c.delete(data).await, + }, } } @@ -133,12 +131,10 @@ impl Object for SearchableObjects { match apub { SearchableKinds::Page(a) => ApubPost::verify(a, expected_domain, data).await, SearchableKinds::Note(a) => ApubComment::verify(a, expected_domain, data).await, - SearchableKinds::PersonOrGroup(pg) => { - match pg { - PersonOrGroup::Person(a) => ApubPerson::verify(a, expected_domain, data).await, - PersonOrGroup::Group(a) => ApubCommunity::verify(a, expected_domain, data).await, - } - } + SearchableKinds::PersonOrGroup(pg) => match pg { + PersonOrGroup::Person(a) => ApubPerson::verify(a, expected_domain, data).await, + PersonOrGroup::Group(a) => ApubCommunity::verify(a, expected_domain, data).await, + }, } }