mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-06-06 00:18:54 +00:00
instance actor name and webfinger
This commit is contained in:
parent
c791b880a4
commit
cabcf3877f
4 changed files with 33 additions and 23 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -17,7 +17,7 @@ checksum = "8f27d075294830fcab6f66e320dab524bc6d048f4a151698e153205559113772"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub_federation"
|
name = "activitypub_federation"
|
||||||
version = "0.5.1"
|
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 = [
|
dependencies = [
|
||||||
"activitystreams-kinds",
|
"activitystreams-kinds",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
|
|
@ -96,6 +96,7 @@ impl Object for ApubSite {
|
||||||
kind: ApplicationType::Application,
|
kind: ApplicationType::Application,
|
||||||
id: self.id().into(),
|
id: self.id().into(),
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
|
preferred_username: data.domain().to_string(),
|
||||||
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),
|
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),
|
||||||
source: self.sidebar.clone().map(Source::new),
|
source: self.sidebar.clone().map(Source::new),
|
||||||
summary: self.description.clone(),
|
summary: self.description.clone(),
|
||||||
|
|
|
@ -19,8 +19,10 @@ pub struct Instance {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub(crate) kind: ApplicationType,
|
pub(crate) kind: ApplicationType,
|
||||||
pub(crate) id: ObjectId<ApubSite>,
|
pub(crate) id: ObjectId<ApubSite>,
|
||||||
// site name
|
/// site name
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
|
/// domain, necessary for mastodon authorized fetch
|
||||||
|
pub(crate) preferred_username: String,
|
||||||
pub(crate) inbox: Url,
|
pub(crate) inbox: Url,
|
||||||
/// mandatory field in activitypub, lemmy currently serves an empty outbox
|
/// mandatory field in activitypub, lemmy currently serves an empty outbox
|
||||||
pub(crate) outbox: Url,
|
pub(crate) outbox: Url,
|
||||||
|
|
|
@ -38,28 +38,35 @@ async fn get_webfinger_response(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let name = extract_webfinger_name(&info.resource, &context)?;
|
let name = extract_webfinger_name(&info.resource, &context)?;
|
||||||
|
|
||||||
let user_id: Option<Url> = Person::read_from_name(&mut context.pool(), name, false)
|
let links = if name == context.domain() {
|
||||||
.await
|
// webfinger response for instance actor (required for mastodon authorized fetch)
|
||||||
.ok()
|
let url = Url::parse(&format!("https://{name}"))?;
|
||||||
.map(|c| c.actor_id.into());
|
vec![webfinger_link_for_actor(Some(url), "none", &context)]
|
||||||
let community_id: Option<Url> = Community::read_from_name(&mut context.pool(), name, false)
|
} else {
|
||||||
.await
|
// webfinger response for user/community
|
||||||
.ok()
|
let user_id: Option<Url> = Person::read_from_name(&mut context.pool(), name, false)
|
||||||
.and_then(|c| {
|
.await
|
||||||
if c.visibility == CommunityVisibility::Public {
|
.ok()
|
||||||
let id: Url = c.actor_id.into();
|
.map(|c| c.actor_id.into());
|
||||||
Some(id)
|
let community_id: Option<Url> = Community::read_from_name(&mut context.pool(), name, false)
|
||||||
} else {
|
.await
|
||||||
None
|
.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
|
// 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.
|
// community last so that it gets prioritized. For Lemmy the order doesnt matter.
|
||||||
let links = vec![
|
vec![
|
||||||
webfinger_link_for_actor(user_id, "Person", &context),
|
webfinger_link_for_actor(user_id, "Person", &context),
|
||||||
webfinger_link_for_actor(community_id, "Group", &context),
|
webfinger_link_for_actor(community_id, "Group", &context),
|
||||||
]
|
]
|
||||||
|
}
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Reference in a new issue