From b2e76643398c7b1731b584eae63eefbe8a6d27dd Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 14 Feb 2021 22:14:44 +0900 Subject: [PATCH 1/3] Extract User::acct_authority() method --- plume-models/src/users.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 0b7cf3af..95b4d758 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -832,11 +832,7 @@ impl User { pub fn webfinger(&self, conn: &Connection) -> Result { Ok(Webfinger { - subject: format!( - "acct:{}@{}", - self.username, - self.get_instance(conn)?.public_domain - ), + subject: format!("acct:{}", self.acct_authority(conn)?), aliases: vec![self.ap_url.clone()], links: vec![ Link { @@ -874,6 +870,14 @@ impl User { }) } + pub fn acct_authority(&self, conn: &Connection) -> Result { + Ok(format!( + "{}@{}", + self.username, + self.get_instance(conn)?.public_domain + )) + } + pub fn set_avatar(&self, conn: &Connection, id: i32) -> Result<()> { diesel::update(self) .set(users::avatar_id.eq(id)) From 703328601c750143d7ec04066082efb83865f1cf Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 14 Feb 2021 22:15:32 +0900 Subject: [PATCH 2/3] [BUG FIX] Don't append host part twice to remote interact URI --- src/routes/user.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/routes/user.rs b/src/routes/user.rs index 4a3b8a8f..2a8265b7 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -134,16 +134,7 @@ pub fn follow_not_connected( if let Some(remote_form) = remote_form { if let Some(uri) = User::fetch_remote_interact_uri(&remote_form) .ok() - .and_then(|uri| { - Some(uri.replace( - "{uri}", - &format!( - "{}@{}", - target.fqn, - target.get_instance(&conn).ok()?.public_domain - ), - )) - }) + .and_then(|uri| Some(uri.replace("{uri}", &target.acct_authority(&conn).ok()?))) { Ok(Redirect::to(uri).into()) } else { From b7c7b6da9ffecbab63b19e280277516e83774c85 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 14 Feb 2021 22:59:01 +0900 Subject: [PATCH 3/3] Percent encode remote interact URI --- src/routes/user.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/routes/user.rs b/src/routes/user.rs index 2a8265b7..867c6a96 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -1,7 +1,7 @@ use activitypub::collection::{OrderedCollection, OrderedCollectionPage}; use diesel::SaveChangesDsl; use rocket::{ - http::{ContentType, Cookies}, + http::{uri::Uri, ContentType, Cookies}, request::LenientForm, response::{status, Content, Flash, Redirect}, }; @@ -134,7 +134,12 @@ pub fn follow_not_connected( if let Some(remote_form) = remote_form { if let Some(uri) = User::fetch_remote_interact_uri(&remote_form) .ok() - .and_then(|uri| Some(uri.replace("{uri}", &target.acct_authority(&conn).ok()?))) + .and_then(|uri| { + Some(uri.replace( + "{uri}", + &Uri::percent_encode(&target.acct_authority(&conn).ok()?), + )) + }) { Ok(Redirect::to(uri).into()) } else {