1 use activitypub_federation::{
3 fetch::webfinger::webfinger_resolve_actor,
4 traits::{Actor, Object},
7 use itertools::Itertools;
8 use lemmy_api_common::context::LemmyContext;
9 use lemmy_db_schema::traits::ApubActor;
10 use lemmy_db_views::structs::LocalUserView;
11 use lemmy_utils::error::LemmyError;
13 pub mod post_or_comment;
15 pub mod user_or_community;
17 /// Resolve actor identifier like `!news@example.com` to user or community object.
19 /// In case the requesting user is logged in and the object was not found locally, it is attempted
20 /// to fetch via webfinger from the original instance.
21 #[tracing::instrument(skip_all)]
22 pub async fn resolve_actor_identifier<ActorType, DbActor>(
24 context: &Data<LemmyContext>,
25 local_user_view: &Option<LocalUserView>,
26 include_deleted: bool,
27 ) -> Result<ActorType, LemmyError>
29 ActorType: Object<DataType = LemmyContext, Error = LemmyError>
35 for<'de2> <ActorType as Object>::Kind: serde::Deserialize<'de2>,
36 DbActor: ApubActor + Send + 'static,
39 if identifier.contains('@') {
40 let (name, domain) = identifier
43 .expect("invalid query");
44 let name = name.to_string();
45 let domain = format!("{}://{}", context.settings().get_protocol_string(), domain);
46 let actor = DbActor::read_from_name_and_domain(context.pool(), &name, &domain).await;
49 } else if local_user_view.is_some() {
50 // Fetch the actor from its home instance using webfinger
51 let actor: ActorType = webfinger_resolve_actor(identifier, context).await?;
59 let identifier = identifier.to_string();
61 DbActor::read_from_name(context.pool(), &identifier, include_deleted)