Address review comments

This commit is contained in:
Felix Ableitner 2021-02-04 16:54:46 +01:00
parent e421e31c79
commit 8a14af0b8f
4 changed files with 20 additions and 19 deletions

View file

@ -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<String> {
self.public_key.to_owned()
}
@ -52,11 +54,6 @@ impl ActorType for Community {
.into()
}
fn get_outbox_url(&self) -> Result<Url, ParseError> {
assert!(self.local);
Url::parse(&format!("{}/outbox", &self.actor_id()))
}
async fn send_follow(
&self,
_follow_actor_id: &Url,

View file

@ -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<Url, ParseError> {
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,

View file

@ -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<Url, ParseError>;
fn get_outbox_url(&self) -> Result<Url, LemmyError> {
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<PublicKeyExtension, LemmyError> {
Ok(

View file

@ -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);