1 use crate::fetcher::webfinger::webfinger_resolve_actor;
2 use itertools::Itertools;
3 use lemmy_api_common::utils::blocking;
4 use lemmy_apub_lib::traits::{ActorType, ApubObject};
5 use lemmy_db_schema::traits::ApubActor;
6 use lemmy_utils::{settings::structs::Settings, LemmyError};
7 use lemmy_websocket::LemmyContext;
9 pub mod post_or_comment;
11 pub mod user_or_community;
14 /// Resolve actor identifier (eg `!news@example.com`) from local database to avoid network requests.
15 /// This only works for local actors, and remote actors which were previously fetched (so it doesnt
16 /// trigger any new fetch).
17 #[tracing::instrument(skip_all)]
18 pub async fn resolve_actor_identifier<Actor, DbActor>(
20 context: &LemmyContext,
21 ) -> Result<DbActor, LemmyError>
24 ApubObject<DataType = LemmyContext> + ApubObject<DbType = DbActor> + ActorType + Send + 'static,
25 for<'de2> <Actor as ApubObject>::ApubType: serde::Deserialize<'de2>,
26 DbActor: ApubActor + Send + 'static,
29 if identifier.contains('@') {
30 let (name, domain) = identifier
33 .expect("invalid query");
34 let name = name.to_string();
35 let domain = format!("{}://{}", Settings::get().get_protocol_string(), domain);
36 let actor = blocking(context.pool(), move |conn| {
37 DbActor::read_from_name_and_domain(conn, &name, &domain)
43 // Fetch the actor from its home instance using webfinger
44 let id = webfinger_resolve_actor::<Actor>(identifier, context, &mut 0).await?;
45 let actor: DbActor = blocking(context.pool(), move |conn| {
46 DbActor::read_from_apub_id(conn, &id)
49 .expect("actor exists as we fetched just before");
55 let identifier = identifier.to_string();
57 blocking(context.pool(), move |conn| {
58 DbActor::read_from_name(conn, &identifier)