]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/lib.rs
Tag posts and comments with language (fixes #440) (#2269)
[lemmy.git] / crates / apub / src / lib.rs
index e758e706db23e753e5731a3be98a5416db357729..8fd8588b87ad7ae3bc75f959548724a7ad28e67f 100644 (file)
@@ -1,16 +1,20 @@
 use crate::fetcher::post_or_comment::PostOrComment;
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, signatures::PublicKey},
+  core::signatures::PublicKey,
+  traits::{Actor, ApubObject},
   InstanceSettingsBuilder,
   LocalInstance,
 };
 use anyhow::Context;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, utils::DbPool};
-use lemmy_utils::{error::LemmyError, location_info, settings::structs::Settings};
+use lemmy_utils::{
+  error::LemmyError,
+  location_info,
+  settings::{structs::Settings, SETTINGS},
+};
 use lemmy_websocket::LemmyContext;
 use once_cell::sync::{Lazy, OnceCell};
-use std::env;
 use url::{ParseError, Url};
 
 pub mod activities;
@@ -31,14 +35,16 @@ fn local_instance(context: &LemmyContext) -> &'static LocalInstance {
   static LOCAL_INSTANCE: OnceCell<LocalInstance> = OnceCell::new();
   LOCAL_INSTANCE.get_or_init(|| {
     let settings = InstanceSettingsBuilder::default()
-      .http_fetch_retry_limit(context.settings().http_fetch_retry_limit)
+      .http_fetch_retry_limit(context.settings().federation.http_fetch_retry_limit)
       .worker_count(context.settings().federation.worker_count)
-      .testing_send_sync(env::var("APUB_TESTING_SEND_SYNC").is_ok())
-      .verify_url_function(|url| check_apub_id_valid(url, &Settings::get()))
+      .debug(context.settings().federation.debug)
+      // TODO No idea why, but you can't pass context.settings() to the verify_url_function closure
+      // without the value getting captured.
+      .verify_url_function(|url| check_apub_id_valid(url, &SETTINGS))
       .build()
       .expect("configure federation");
     LocalInstance::new(
-      context.settings().hostname,
+      context.settings().hostname.to_owned(),
       context.client().clone(),
       settings,
     )
@@ -204,19 +210,11 @@ async fn insert_activity(
 
 /// Common methods provided by ActivityPub actors (community and person). Not all methods are
 /// implemented by all actors.
-pub trait ActorType: ActorPublicKey {
+pub trait ActorType: Actor + ApubObject {
   fn actor_id(&self) -> Url;
 
   fn private_key(&self) -> Option<String>;
 
-  fn inbox_url(&self) -> Url;
-
-  fn shared_inbox_url(&self) -> Option<Url>;
-
-  fn shared_inbox_or_inbox_url(&self) -> Url {
-    self.shared_inbox_url().unwrap_or_else(|| self.inbox_url())
-  }
-
   fn get_public_key(&self) -> PublicKey {
     PublicKey::new_main_key(self.actor_id(), self.public_key().to_string())
   }