]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/community.rs
Making public key required. Fixes #1934
[lemmy.git] / crates / db_schema / src / impls / community.rs
index 8acce790cd3f7ff50efab572aeea70c03d01c441..8adf2ba5778c68e76637e8387bbb1f8eca2cdd6b 100644 (file)
@@ -14,10 +14,7 @@ use crate::{
   },
   traits::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
 };
-use chrono::NaiveDateTime;
 use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::{ActorType, ApubObject};
-use lemmy_utils::LemmyError;
 use url::Url;
 
 mod safe_type {
@@ -129,16 +126,6 @@ impl Community {
     community.select(actor_id).distinct().load::<String>(conn)
   }
 
-  pub fn read_from_followers_url(
-    conn: &PgConnection,
-    followers_url_: &DbUrl,
-  ) -> Result<Community, Error> {
-    use crate::schema::community::dsl::*;
-    community
-      .filter(followers_url.eq(followers_url_))
-      .first::<Self>(conn)
-  }
-
   pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
     use crate::schema::community::dsl::*;
     insert_into(community)
@@ -148,6 +135,17 @@ impl Community {
       .set(community_form)
       .get_result::<Self>(conn)
   }
+  pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
+    use crate::schema::community::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(
+      community
+        .filter(actor_id.eq(object_id))
+        .first::<Community>(conn)
+        .ok()
+        .map(Into::into),
+    )
+  }
 }
 
 impl Joinable for CommunityModerator {
@@ -297,59 +295,6 @@ impl Followable for CommunityFollower {
   }
 }
 
-impl ApubObject for Community {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    Some(self.last_refreshed_at)
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::community::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(
-      community
-        .filter(actor_id.eq(object_id))
-        .first::<Self>(conn)
-        .ok(),
-    )
-  }
-
-  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
-    use crate::schema::community::dsl::*;
-    diesel::update(community.find(self.id))
-      .set((deleted.eq(true), updated.eq(naive_now())))
-      .get_result::<Self>(conn)?;
-    Ok(())
-  }
-}
-
-impl ActorType for Community {
-  fn is_local(&self) -> bool {
-    self.local
-  }
-  fn actor_id(&self) -> Url {
-    self.actor_id.to_owned().into()
-  }
-  fn name(&self) -> String {
-    self.name.clone()
-  }
-  fn public_key(&self) -> Option<String> {
-    self.public_key.to_owned()
-  }
-  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> {
-    self.shared_inbox_url.clone().map(|s| s.into_inner())
-  }
-}
-
 #[cfg(test)]
 mod tests {
   use crate::{
@@ -374,6 +319,7 @@ mod tests {
     let new_community = CommunityForm {
       name: "TIL".into(),
       title: "nada".to_owned(),
+      public_key: "nada".to_owned(),
       ..CommunityForm::default()
     };
 
@@ -392,7 +338,7 @@ mod tests {
       actor_id: inserted_community.actor_id.to_owned(),
       local: true,
       private_key: None,
-      public_key: None,
+      public_key: "nada".to_owned(),
       last_refreshed_at: inserted_community.published,
       icon: None,
       banner: None,