Add support for building webfinger for multiple URLs with type

Update `build_webfinger_response` to accept `Vec<(Url, Option<&str>)>`
where `Url` is the ActivityPub ID and `&str` is the optional type.
This commit is contained in:
Grafcube 2023-03-31 21:06:02 +05:30
parent c56f526914
commit 3f70586e63
No known key found for this signature in database
GPG key ID: E383688F2878A440

View file

@ -95,10 +95,11 @@ where
/// build_webfinger_response(subject, url);
/// # Ok::<(), anyhow::Error>(())
/// ```
pub fn build_webfinger_response(subject: String, url: Url) -> Webfinger {
pub fn build_webfinger_response(subject: String, url: Vec<(Url, Option<&str>)>) -> Webfinger {
Webfinger {
subject,
links: vec![
links: url.iter().fold(vec![], |mut acc, (url, kind)| {
acc.extend(vec![
WebfingerLink {
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
kind: Some("text/html".to_string()),
@ -108,10 +109,21 @@ pub fn build_webfinger_response(subject: String, url: Url) -> Webfinger {
WebfingerLink {
rel: Some("self".to_string()),
kind: Some(FEDERATION_CONTENT_TYPE.to_string()),
href: Some(url),
properties: Default::default(),
href: Some(url.clone()),
properties: kind
.map(|kind| {
HashMap::from([(
"https://www.w3.org/ns/activitystreams#type"
.parse::<Url>()
.expect("parse url"),
kind.to_string(),
)])
})
.unwrap_or_default(),
},
],
]);
acc
}),
aliases: vec![],
properties: Default::default(),
}