mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 12:21:18 +00:00
Implement remote follow (#3738)
* Add remote follow url to webfinger response * update apub lib
This commit is contained in:
parent
384e55f0e4
commit
fed6542055
4 changed files with 37 additions and 21 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub_federation"
|
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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb4c5f0e97215be7fb8bdd632283f66d78168f388029d678ab4854ff599f0238"
|
checksum = "8210e0ac4675753f9288c1102fb4940b22e5868308383c286b07eb63f3ff4c65"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitystreams-kinds",
|
"activitystreams-kinds",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
|
|
@ -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 = { version = "=0.18.1", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" }
|
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" }
|
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",
|
"actix-web",
|
||||||
] }
|
] }
|
||||||
diesel = "2.1.0"
|
diesel = "2.1.0"
|
||||||
|
|
|
@ -50,8 +50,8 @@ async fn get_webfinger_response(
|
||||||
// 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![
|
let links = vec![
|
||||||
webfinger_link_for_actor(user_id, "Person"),
|
webfinger_link_for_actor(user_id, "Person", &context),
|
||||||
webfinger_link_for_actor(community_id, "Group"),
|
webfinger_link_for_actor(community_id, "Group", &context),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -66,29 +66,45 @@ async fn get_webfinger_response(
|
||||||
Ok(HttpResponse::Ok().json(json))
|
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 {
|
if let Some(url) = url {
|
||||||
let mut properties = HashMap::new();
|
let type_key = "https://www.w3.org/ns/activitystreams#type"
|
||||||
properties.insert(
|
.parse()
|
||||||
"https://www.w3.org/ns/activitystreams#type"
|
.expect("parse url");
|
||||||
.parse()
|
|
||||||
.expect("parse url"),
|
let mut vec = vec![
|
||||||
kind.to_string(),
|
|
||||||
);
|
|
||||||
vec![
|
|
||||||
WebfingerLink {
|
WebfingerLink {
|
||||||
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
|
rel: Some("http://webfinger.net/rel/profile-page".into()),
|
||||||
kind: Some("text/html".to_string()),
|
kind: Some("text/html".into()),
|
||||||
href: Some(url.clone()),
|
href: Some(url.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
WebfingerLink {
|
WebfingerLink {
|
||||||
rel: Some("self".to_string()),
|
rel: Some("self".into()),
|
||||||
kind: Some("application/activity+json".to_string()),
|
kind: Some("application/activity+json".into()),
|
||||||
href: Some(url),
|
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 {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1c42c579460871de7b4ea18e58dc25543b80d289
|
Subproject commit 713ceed9c7ef84deaa222e68361e670e0763cd83
|
Loading…
Reference in a new issue