From 8a14af0b8fb207939bda1b3c1e28a184573980d8 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 4 Feb 2021 16:54:46 +0100 Subject: [PATCH] Address review comments --- crates/apub/src/activities/send/community.rs | 11 ++++------- crates/apub/src/activities/send/user.rs | 10 ++++------ crates/apub/src/lib.rs | 8 +++++++- migrations/2021-02-02-153240_apub_columns/up.sql | 10 +++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/crates/apub/src/activities/send/community.rs b/crates/apub/src/activities/send/community.rs index 398024322..a574c7b85 100644 --- a/crates/apub/src/activities/send/community.rs +++ b/crates/apub/src/activities/send/community.rs @@ -29,14 +29,16 @@ use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; -use url::{ParseError, Url}; +use url::Url; #[async_trait::async_trait(?Send)] impl ActorType for Community { + fn is_local(&self) -> bool { + self.local + } fn actor_id(&self) -> Url { self.actor_id.to_owned().into_inner() } - fn public_key(&self) -> Option { self.public_key.to_owned() } @@ -52,11 +54,6 @@ impl ActorType for Community { .into() } - fn get_outbox_url(&self) -> Result { - assert!(self.local); - Url::parse(&format!("{}/outbox", &self.actor_id())) - } - async fn send_follow( &self, _follow_actor_id: &Url, diff --git a/crates/apub/src/activities/send/user.rs b/crates/apub/src/activities/send/user.rs index 2e5e2c2df..1847ec5c5 100644 --- a/crates/apub/src/activities/send/user.rs +++ b/crates/apub/src/activities/send/user.rs @@ -21,10 +21,13 @@ use lemmy_db_schema::source::{ use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; -use url::{ParseError, Url}; +use url::Url; #[async_trait::async_trait(?Send)] impl ActorType for User_ { + fn is_local(&self) -> bool { + self.local + } fn actor_id(&self) -> Url { self.actor_id.to_owned().into_inner() } @@ -45,11 +48,6 @@ impl ActorType for User_ { .into() } - fn get_outbox_url(&self) -> Result { - assert!(self.local); - Url::parse(&format!("{}/outbox", &self.actor_id())) - } - /// As a given local user, send out a follow request to a remote community. async fn send_follow( &self, diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 87479b738..9a9507eb7 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -140,6 +140,7 @@ pub trait ApubLikeableType { /// implemented by all actors. #[async_trait::async_trait(?Send)] pub trait ActorType { + fn is_local(&self) -> bool; fn actor_id(&self) -> Url; // TODO: every actor should have a public key, so this shouldnt be an option (needs to be fixed in db) @@ -182,7 +183,12 @@ pub trait ActorType { /// Outbox URL is not generally used by Lemmy, so it can be generated on the fly (but only for /// local actors). - fn get_outbox_url(&self) -> Result; + fn get_outbox_url(&self) -> Result { + if !self.is_local() { + return Err(anyhow!("get_outbox_url() called for remote actor").into()); + } + Ok(Url::parse(&format!("{}/outbox", &self.actor_id()))?) + } fn get_public_key_ext(&self) -> Result { Ok( diff --git a/migrations/2021-02-02-153240_apub_columns/up.sql b/migrations/2021-02-02-153240_apub_columns/up.sql index ebb390b0a..48f3b20e5 100644 --- a/migrations/2021-02-02-153240_apub_columns/up.sql +++ b/migrations/2021-02-02-153240_apub_columns/up.sql @@ -1,9 +1,9 @@ -ALTER TABLE community ADD COLUMN followers_url TEXT NOT NULL DEFAULT generate_unique_changeme(); -ALTER TABLE community ADD COLUMN inbox_url TEXT NOT NULL DEFAULT generate_unique_changeme(); -ALTER TABLE community ADD COLUMN shared_inbox_url TEXT; +ALTER TABLE community ADD COLUMN followers_url varchar(255) NOT NULL DEFAULT generate_unique_changeme(); +ALTER TABLE community ADD COLUMN inbox_url varchar(255) NOT NULL DEFAULT generate_unique_changeme(); +ALTER TABLE community ADD COLUMN shared_inbox_url varchar(255); -ALTER TABLE user_ ADD COLUMN inbox_url TEXT NOT NULL DEFAULT generate_unique_changeme(); -ALTER TABLE user_ ADD COLUMN shared_inbox_url TEXT; +ALTER TABLE user_ ADD COLUMN inbox_url varchar(255) NOT NULL DEFAULT generate_unique_changeme(); +ALTER TABLE user_ ADD COLUMN shared_inbox_url varchar(255); ALTER TABLE community ADD CONSTRAINT idx_community_followers_url UNIQUE (followers_url); ALTER TABLE community ADD CONSTRAINT idx_community_inbox_url UNIQUE (inbox_url);