]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/objects/instance.rs
Diesel 2.0.0 upgrade (#2452)
[lemmy.git] / crates / apub / src / objects / instance.rs
index cd4ceb467634c435ab2f426b4f825d6dc9f68078..dbf2f9f3a05fdd362139c58c42052c49d627d2ed 100644 (file)
@@ -10,16 +10,16 @@ use crate::{
   ActorType,
 };
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, object_id::ObjectId},
+  core::object_id::ObjectId,
   deser::values::MediaTypeHtml,
-  traits::ApubObject,
+  traits::{Actor, ApubObject},
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
   source::site::{Site, SiteForm},
-  utils::naive_now,
+  utils::{naive_now, DbPool},
 };
 use lemmy_utils::{
   error::LemmyError,
@@ -103,7 +103,7 @@ impl ApubObject for ApubSite {
     data: &Self::DataType,
     _request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    check_apub_id_valid_with_strictness(apub.id.inner(), true, &data.settings())?;
+    check_apub_id_valid_with_strictness(apub.id.inner(), true, data.settings())?;
     verify_domains_match(expected_domain, apub.id.inner())?;
 
     let slur_regex = &data.settings().slur_regex();
@@ -147,20 +147,16 @@ impl ActorType for ApubSite {
   fn private_key(&self) -> Option<String> {
     self.private_key.to_owned()
   }
-
-  fn inbox_url(&self) -> Url {
-    self.inbox_url.clone().into()
-  }
-
-  fn shared_inbox_url(&self) -> Option<Url> {
-    None
-  }
 }
 
-impl ActorPublicKey for ApubSite {
+impl Actor for ApubSite {
   fn public_key(&self) -> &str {
     &self.public_key
   }
+
+  fn inbox(&self) -> Url {
+    self.inbox_url.clone().into()
+  }
 }
 
 /// Instance actor is at the root path, so we simply need to clear the path and other unnecessary
@@ -181,13 +177,23 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object(
   // try to fetch the instance actor (to make things like instance rules available)
   let instance_id = instance_actor_id_from_url(object_id);
   let site = ObjectId::<ApubSite>::new(instance_id.clone())
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await;
   if let Err(e) = site {
     debug!("Failed to dereference site for {}: {}", instance_id, e);
   }
 }
 
+pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+  Ok(
+    blocking(pool, Site::read_remote_sites)
+      .await??
+      .into_iter()
+      .map(|s| ApubSite::from(s).shared_inbox_or_inbox())
+      .collect(),
+  )
+}
+
 #[cfg(test)]
 pub(crate) mod tests {
   use super::*;
@@ -213,11 +219,12 @@ pub(crate) mod tests {
   #[serial]
   async fn test_parse_lemmy_instance() {
     let context = init_context();
+    let conn = &mut context.pool().get().unwrap();
     let site = parse_lemmy_instance(&context).await;
 
     assert_eq!(site.name, "Enterprise");
     assert_eq!(site.description.as_ref().unwrap().len(), 15);
 
-    Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
+    Site::delete(conn, site.id).unwrap();
   }
 }