instance actor name and webfinger

This commit is contained in:
Felix Ableitner 2024-03-07 16:00:10 +01:00
parent c791b880a4
commit cabcf3877f
4 changed files with 33 additions and 23 deletions

2
Cargo.lock generated
View file

@ -17,7 +17,7 @@ checksum = "8f27d075294830fcab6f66e320dab524bc6d048f4a151698e153205559113772"
[[package]]
name = "activitypub_federation"
version = "0.5.1"
source = "git+https://github.com/LemmyNet/activitypub-federation-rust.git?branch=debug-signed-fetch#294c77c01b6cc5fd1b34126710edc56cd9769789"
source = "git+https://github.com/LemmyNet/activitypub-federation-rust.git?branch=debug-signed-fetch#b3978cf4183297590cb992cd9684484c7f94b279"
dependencies = [
"activitystreams-kinds",
"actix-web",

View file

@ -96,6 +96,7 @@ impl Object for ApubSite {
kind: ApplicationType::Application,
id: self.id().into(),
name: self.name.clone(),
preferred_username: data.domain().to_string(),
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),
source: self.sidebar.clone().map(Source::new),
summary: self.description.clone(),

View file

@ -19,8 +19,10 @@ pub struct Instance {
#[serde(rename = "type")]
pub(crate) kind: ApplicationType,
pub(crate) id: ObjectId<ApubSite>,
// site name
/// site name
pub(crate) name: String,
/// domain, necessary for mastodon authorized fetch
pub(crate) preferred_username: String,
pub(crate) inbox: Url,
/// mandatory field in activitypub, lemmy currently serves an empty outbox
pub(crate) outbox: Url,

View file

@ -38,28 +38,35 @@ async fn get_webfinger_response(
) -> Result<HttpResponse, LemmyError> {
let name = extract_webfinger_name(&info.resource, &context)?;
let user_id: Option<Url> = Person::read_from_name(&mut context.pool(), name, false)
.await
.ok()
.map(|c| c.actor_id.into());
let community_id: Option<Url> = Community::read_from_name(&mut context.pool(), name, false)
.await
.ok()
.and_then(|c| {
if c.visibility == CommunityVisibility::Public {
let id: Url = c.actor_id.into();
Some(id)
} else {
None
}
});
let links = if name == context.domain() {
// webfinger response for instance actor (required for mastodon authorized fetch)
let url = Url::parse(&format!("https://{name}"))?;
vec![webfinger_link_for_actor(Some(url), "none", &context)]
} else {
// webfinger response for user/community
let user_id: Option<Url> = Person::read_from_name(&mut context.pool(), name, false)
.await
.ok()
.map(|c| c.actor_id.into());
let community_id: Option<Url> = Community::read_from_name(&mut context.pool(), name, false)
.await
.ok()
.and_then(|c| {
if c.visibility == CommunityVisibility::Public {
let id: Url = c.actor_id.into();
Some(id)
} else {
None
}
});
// Mastodon seems to prioritize the last webfinger item in case of duplicates. Put
// community last so that it gets prioritized. For Lemmy the order doesnt matter.
let links = vec![
webfinger_link_for_actor(user_id, "Person", &context),
webfinger_link_for_actor(community_id, "Group", &context),
]
// Mastodon seems to prioritize the last webfinger item in case of duplicates. Put
// community last so that it gets prioritized. For Lemmy the order doesnt matter.
vec![
webfinger_link_for_actor(user_id, "Person", &context),
webfinger_link_for_actor(community_id, "Group", &context),
]
}
.into_iter()
.flatten()
.collect();