From fed654205596fba61d2308a6b9474753e4a09ff1 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 31 Aug 2023 15:00:41 +0200 Subject: [PATCH] Implement remote follow (#3738) * Add remote follow url to webfinger response * update apub lib --- Cargo.lock | 4 +-- Cargo.toml | 2 +- crates/routes/src/webfinger.rs | 50 ++++++++++++++++++++++------------ crates/utils/translations | 2 +- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ed7ea6ee..f7d99de7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "activitypub_federation" -version = "0.5.0-beta.1" +version = "0.5.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb4c5f0e97215be7fb8bdd632283f66d78168f388029d678ab4854ff599f0238" +checksum = "8210e0ac4675753f9288c1102fb4940b22e5868308383c286b07eb63f3ff4c65" dependencies = [ "activitystreams-kinds", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index c2adfd0cd..56484859f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ lemmy_routes = { version = "=0.18.1", path = "./crates/routes" } lemmy_db_views = { version = "=0.18.1", path = "./crates/db_views" } lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" } lemmy_db_views_moderator = { version = "=0.18.1", path = "./crates/db_views_moderator" } -activitypub_federation = { version = "0.5.0-beta.1", default-features = false, features = [ +activitypub_federation = { version = "0.5.0-beta.2", default-features = false, features = [ "actix-web", ] } diesel = "2.1.0" diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index e3a0a5615..afb2d33ae 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -50,8 +50,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, "Person"), - webfinger_link_for_actor(community_id, "Group"), + webfinger_link_for_actor(user_id, "Person", &context), + webfinger_link_for_actor(community_id, "Group", &context), ] .into_iter() .flatten() @@ -66,29 +66,45 @@ async fn get_webfinger_response( Ok(HttpResponse::Ok().json(json)) } -fn webfinger_link_for_actor(url: Option, kind: &str) -> Vec { +fn webfinger_link_for_actor( + url: Option, + kind: &str, + context: &LemmyContext, +) -> Vec { if let Some(url) = url { - let mut properties = HashMap::new(); - properties.insert( - "https://www.w3.org/ns/activitystreams#type" - .parse() - .expect("parse url"), - kind.to_string(), - ); - vec![ + let type_key = "https://www.w3.org/ns/activitystreams#type" + .parse() + .expect("parse url"); + + let mut vec = vec![ WebfingerLink { - rel: Some("http://webfinger.net/rel/profile-page".to_string()), - kind: Some("text/html".to_string()), + rel: Some("http://webfinger.net/rel/profile-page".into()), + kind: Some("text/html".into()), href: Some(url.clone()), ..Default::default() }, WebfingerLink { - rel: Some("self".to_string()), - kind: Some("application/activity+json".to_string()), + rel: Some("self".into()), + kind: Some("application/activity+json".into()), href: Some(url), - properties, + properties: HashMap::from([(type_key, kind.into())]), + ..Default::default() }, - ] + ]; + + // insert remote follow link + if kind == "Person" { + let template = format!( + "{}/activitypub/externalInteraction?uri={{uri}}", + context.settings().get_protocol_and_hostname() + ); + vec.push(WebfingerLink { + rel: Some("http://ostatus.org/schema/1.0/subscribe".into()), + template: Some(template), + ..Default::default() + }); + } + vec } else { vec![] } diff --git a/crates/utils/translations b/crates/utils/translations index 1c42c5794..713ceed9c 160000 --- a/crates/utils/translations +++ b/crates/utils/translations @@ -1 +1 @@ -Subproject commit 1c42c579460871de7b4ea18e58dc25543b80d289 +Subproject commit 713ceed9c7ef84deaa222e68361e670e0763cd83