- if apub_id.scheme() != Settings::get().get_protocol_string() {
- return Err(anyhow!("invalid apub id scheme {}: {}", apub_id.scheme(), apub_id).into());
- }
-
- let allowed_instances = Settings::get().get_allowed_instances();
- let blocked_instances = Settings::get().get_blocked_instances();
-
- if allowed_instances.is_none() && blocked_instances.is_none() {
- Ok(())
- } else if let Some(mut allowed) = allowed_instances {
- // need to allow this explicitly because apub receive might contain objects from our local
- // instance. split is needed to remove the port in our federation test setup.
- allowed.push(local_instance);
-
- if allowed.contains(&domain) {
- Ok(())
- } else {
- Err(anyhow!("{} not in federation allowlist", domain).into())
- }
- } else if let Some(blocked) = blocked_instances {
- if blocked.contains(&domain) {
- Err(anyhow!("{} is in federation blocklist", domain).into())
- } else {
- Ok(())
- }
- } else {
- panic!("Invalid config, both allowed_instances and blocked_instances are specified");
- }
-}
-
-/// Common functions for ActivityPub objects, which are implemented by most (but not all) objects
-/// and actors in Lemmy.
-#[async_trait::async_trait(?Send)]
-pub trait ApubObjectType {
- async fn send_create(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_update(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_delete(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_undo_delete(
- &self,
- creator: &User_,
- context: &LemmyContext,
- ) -> Result<(), LemmyError>;
- async fn send_remove(&self, mod_: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_undo_remove(&self, mod_: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
-}
-
-#[async_trait::async_trait(?Send)]
-pub trait ApubLikeableType {
- async fn send_like(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_dislike(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_undo_like(&self, creator: &User_, context: &LemmyContext)
- -> Result<(), LemmyError>;
-}
-
-/// Common methods provided by ActivityPub actors (community and user). Not all methods are
-/// 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)
- fn public_key(&self) -> Option<String>;
- fn private_key(&self) -> Option<String>;
-
- async fn send_follow(
- &self,
- follow_actor_id: &Url,
- context: &LemmyContext,
- ) -> Result<(), LemmyError>;
- async fn send_unfollow(
- &self,
- follow_actor_id: &Url,
- context: &LemmyContext,
- ) -> Result<(), LemmyError>;
-
- async fn send_accept_follow(
- &self,
- follow: Follow,
- context: &LemmyContext,
- ) -> Result<(), LemmyError>;
-
- async fn send_delete(&self, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_undo_delete(&self, context: &LemmyContext) -> Result<(), LemmyError>;
-
- async fn send_remove(&self, context: &LemmyContext) -> Result<(), LemmyError>;
- async fn send_undo_remove(&self, context: &LemmyContext) -> Result<(), LemmyError>;
-
- async fn send_announce(
- &self,
- activity: AnyBase,
- context: &LemmyContext,
- ) -> Result<(), LemmyError>;
-
- /// For a given community, returns the inboxes of all followers.
- async fn get_follower_inboxes(&self, pool: &DbPool) -> Result<Vec<Url>, LemmyError>;
-
- fn get_shared_inbox_or_inbox_url(&self) -> Url;
-
- /// 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, LemmyError> {
- if !self.is_local() {
- return Err(anyhow!("get_outbox_url() called for remote actor").into());
- }
- Ok(Url::parse(&format!("{}/outbox", &self.actor_id()))?)