From: Nutomic Date: Wed, 22 Feb 2023 02:25:26 +0000 (+0900) Subject: Include type information with webfinger responses (fixes #2037) (#2746) X-Git-Url: http://these/git/readmes/%7B%60%24%7BarchiveTodayUrl%7D/static/%7Bthis.state.post.url%7D?a=commitdiff_plain;h=675353d4e920e124ae4bc048ddc45fbbed7b7875;p=lemmy.git Include type information with webfinger responses (fixes #2037) (#2746) So that it is easier to parse for other software --- diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index 9056ea63..4d744de9 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -7,6 +7,7 @@ use lemmy_db_schema::{ }; use lemmy_utils::{error::LemmyError, location_info, WebfingerLink, WebfingerResponse}; use serde::Deserialize; +use std::collections::HashMap; use url::Url; #[derive(Deserialize)] @@ -53,8 +54,8 @@ async fn get_webfinger_response( // 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), - webfinger_link_for_actor(community_id), + webfinger_link_for_actor(user_id, "Person"), + webfinger_link_for_actor(community_id, "Group"), ] .into_iter() .flatten() @@ -68,18 +69,25 @@ async fn get_webfinger_response( Ok(HttpResponse::Ok().json(json)) } -fn webfinger_link_for_actor(url: Option) -> Vec { +fn webfinger_link_for_actor(url: Option, kind: &str) -> Vec { if let Some(url) = url { + let mut properties = HashMap::new(); + properties.insert( + "https://www.w3.org/ns/activitystreams#type".to_string(), + kind.to_string(), + ); vec![ WebfingerLink { rel: Some("http://webfinger.net/rel/profile-page".to_string()), kind: Some("text/html".to_string()), href: Some(url.clone()), + properties: Default::default(), }, WebfingerLink { rel: Some("self".to_string()), kind: Some("application/activity+json".to_string()), href: Some(url), + properties, }, ] } else { diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 48d16615..799d6994 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -15,7 +15,7 @@ pub mod utils; pub mod version; use serde::{Deserialize, Serialize}; -use std::{fmt, time::Duration}; +use std::{collections::HashMap, fmt, time::Duration}; use url::Url; pub type ConnectionId = usize; @@ -37,6 +37,7 @@ pub struct WebfingerLink { #[serde(rename = "type")] pub kind: Option, pub href: Option, + pub properties: HashMap, } #[derive(Serialize, Deserialize, Debug)]