]> Untitled Git - lemmy.git/blobdiff - lemmy_db/src/comment.rs
Merge branch 'main' into move_views_to_diesel
[lemmy.git] / lemmy_db / src / comment.rs
index c88eb9adb8ff7684b8a1f6a608b04bada30c2630..fb327a308dfbe8d63eee316648fa779141f0ddd8 100644 (file)
@@ -2,6 +2,7 @@ use super::post::Post;
 use crate::{
   naive_now,
   schema::{comment, comment_like, comment_saved},
+  ApubObject,
   Crud,
   Likeable,
   Saveable,
@@ -86,6 +87,23 @@ impl Crud<CommentForm> for Comment {
   }
 }
 
+impl ApubObject<CommentForm> for Comment {
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+    use crate::schema::comment::dsl::*;
+    comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
+  }
+
+  fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+    use crate::schema::comment::dsl::*;
+    insert_into(comment)
+      .values(comment_form)
+      .on_conflict(ap_id)
+      .do_update()
+      .set(comment_form)
+      .get_result::<Self>(conn)
+  }
+}
+
 impl Comment {
   pub fn update_ap_id(
     conn: &PgConnection,
@@ -99,11 +117,6 @@ impl Comment {
       .get_result::<Self>(conn)
   }
 
-  pub fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
-  }
-
   pub fn permadelete_for_creator(
     conn: &PgConnection,
     for_creator_id: i32,
@@ -168,16 +181,6 @@ impl Comment {
       .set((content.eq(new_content), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
-
-  pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    insert_into(comment)
-      .values(comment_form)
-      .on_conflict(ap_id)
-      .do_update()
-      .set(comment_form)
-      .get_result::<Self>(conn)
-  }
 }
 
 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]