]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/collections/community_moderators.rs
Diesel 2.0.0 upgrade (#2452)
[lemmy.git] / crates / apub / src / collections / community_moderators.rs
index 028174ae9ec234a76b08050ebf1fbe1ff97b00f3..9f4374dbb6df3585733c611d76f7d4ba443552ea 100644 (file)
@@ -1,19 +1,24 @@
 use crate::{
   collections::CommunityContext,
   generate_moderators_url,
+  local_instance,
   objects::person::ApubPerson,
   protocol::collections::group_moderators::GroupModerators,
 };
+use activitypub_federation::{
+  core::object_id::ObjectId,
+  traits::ApubObject,
+  utils::verify_domains_match,
+};
 use activitystreams_kinds::collection::OrderedCollectionType;
 use chrono::NaiveDateTime;
 use lemmy_api_common::utils::blocking;
-use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject, verify::verify_domains_match};
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
   traits::Joinable,
 };
 use lemmy_db_views_actor::structs::CommunityModeratorView;
-use lemmy_utils::LemmyError;
+use lemmy_utils::error::LemmyError;
 use url::Url;
 
 #[derive(Clone, Debug)]
@@ -22,8 +27,8 @@ pub(crate) struct ApubCommunityModerators(pub(crate) Vec<CommunityModeratorView>
 #[async_trait::async_trait(?Send)]
 impl ApubObject for ApubCommunityModerators {
   type DataType = CommunityContext;
-  type TombstoneType = ();
   type ApubType = GroupModerators;
+  type Error = LemmyError;
 
   fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
     None
@@ -66,10 +71,6 @@ impl ApubObject for ApubCommunityModerators {
     })
   }
 
-  fn to_tombstone(&self) -> Result<Self::TombstoneType, LemmyError> {
-    unimplemented!()
-  }
-
   #[tracing::instrument(skip_all)]
   async fn verify(
     group_moderators: &GroupModerators,
@@ -111,7 +112,7 @@ impl ApubObject for ApubCommunityModerators {
     for mod_id in apub.ordered_items {
       let mod_id = ObjectId::new(mod_id);
       let mod_user: ApubPerson = mod_id
-        .dereference(&data.1, data.1.client(), request_counter)
+        .dereference(&data.1, local_instance(&data.1), request_counter)
         .await?;
 
       if !current_moderators
@@ -162,21 +163,23 @@ mod tests {
   #[serial]
   async fn test_parse_lemmy_community_moderators() {
     let context = init_context();
+    let conn = &mut context.pool().get().unwrap();
     let (new_mod, site) = parse_lemmy_person(&context).await;
     let community = parse_lemmy_community(&context).await;
     let community_id = community.id;
 
     let old_mod = PersonForm {
       name: "holly".into(),
+      public_key: Some("pubkey".to_string()),
       ..PersonForm::default()
     };
-    let old_mod = Person::create(&context.pool().get().unwrap(), &old_mod).unwrap();
+    let old_mod = Person::create(conn, &old_mod).unwrap();
     let community_moderator_form = CommunityModeratorForm {
       community_id: community.id,
       person_id: old_mod.id,
     };
 
-    CommunityModerator::join(&context.pool().get().unwrap(), &community_moderator_form).unwrap();
+    CommunityModerator::join(conn, &community_moderator_form).unwrap();
 
     assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
 
@@ -203,13 +206,9 @@ mod tests {
     assert_eq!(current_moderators.len(), 1);
     assert_eq!(current_moderators[0].moderator.id, new_mod.id);
 
-    Person::delete(&*community_context.1.pool().get().unwrap(), old_mod.id).unwrap();
-    Person::delete(&*community_context.1.pool().get().unwrap(), new_mod.id).unwrap();
-    Community::delete(
-      &*community_context.1.pool().get().unwrap(),
-      community_context.0.id,
-    )
-    .unwrap();
-    Site::delete(&*community_context.1.pool().get().unwrap(), site.id).unwrap();
+    Person::delete(conn, old_mod.id).unwrap();
+    Person::delete(conn, new_mod.id).unwrap();
+    Community::delete(conn, community_context.0.id).unwrap();
+    Site::delete(conn, site.id).unwrap();
   }
 }