1 use crate::{fetcher::webfinger::webfinger_resolve_actor, ActorType};
2 use activitypub_federation::traits::ApubObject;
3 use itertools::Itertools;
4 use lemmy_api_common::context::LemmyContext;
5 use lemmy_db_schema::traits::ApubActor;
6 use lemmy_utils::error::LemmyError;
8 pub mod post_or_comment;
10 pub mod user_or_community;
13 /// Resolve actor identifier (eg `!news@example.com`) from local database to avoid network requests.
14 /// This only works for local actors, and remote actors which were previously fetched (so it doesnt
15 /// trigger any new fetch).
16 #[tracing::instrument(skip_all)]
17 pub async fn resolve_actor_identifier<Actor, DbActor>(
19 context: &LemmyContext,
20 include_deleted: bool,
21 ) -> Result<DbActor, LemmyError>
23 Actor: ApubObject<DataType = LemmyContext, Error = LemmyError>
24 + ApubObject<DbType = DbActor>
28 for<'de2> <Actor as ApubObject>::ApubType: serde::Deserialize<'de2>,
29 DbActor: ApubActor + Send + 'static,
32 if identifier.contains('@') {
33 let (name, domain) = identifier
36 .expect("invalid query");
37 let name = name.to_string();
38 let domain = format!("{}://{}", context.settings().get_protocol_string(), domain);
39 let actor = DbActor::read_from_name_and_domain(context.pool(), &name, &domain).await;
43 // Fetch the actor from its home instance using webfinger
44 let id = webfinger_resolve_actor::<Actor>(identifier, true, context, &mut 0).await?;
45 let actor: DbActor = DbActor::read_from_apub_id(context.pool(), &id)
47 .expect("actor exists as we fetched just before");
53 let identifier = identifier.to_string();
54 Ok(DbActor::read_from_name(context.pool(), &identifier, include_deleted).await?)