Implement remote follow (#3738)

* Add remote follow url to webfinger response

* update apub lib
This commit is contained in:
Nutomic 2023-08-31 15:00:41 +02:00 committed by GitHub
parent 384e55f0e4
commit fed6542055
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 21 deletions

4
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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<Url>, kind: &str) -> Vec<WebfingerLink> {
fn webfinger_link_for_actor(
url: Option<Url>,
kind: &str,
context: &LemmyContext,
) -> Vec<WebfingerLink> {
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![]
}

@ -1 +1 @@
Subproject commit 1c42c579460871de7b4ea18e58dc25543b80d289
Subproject commit 713ceed9c7ef84deaa222e68361e670e0763cd83