mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-14 00:37:07 +00:00
fmt
This commit is contained in:
parent
c2249c009a
commit
9da28935e0
2 changed files with 27 additions and 35 deletions
|
@ -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 {
|
||||
|
|
|
@ -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::<LemmyContext, UserOrCommunity>(&query, context).await?)
|
||||
SearchableObjects::PersonOrCommunity(
|
||||
webfinger_resolve_actor::<LemmyContext, UserOrCommunity>(&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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue