]> Untitled Git - lemmy.git/blobdiff - crates/db_queries/src/source/post.rs
Rewrite fetcher (#1792)
[lemmy.git] / crates / db_queries / src / source / post.rs
index 02ae4d6e2d461cce5c339d832055bdb4c0be5f2a..7f185f429672d603254d990db3ded2348f357021 100644 (file)
@@ -1,4 +1,5 @@
 use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
+use chrono::NaiveDateTime;
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
@@ -72,6 +73,7 @@ pub trait Post_ {
     new_stickied: bool,
   ) -> Result<Post, Error>;
   fn is_post_creator(person_id: PersonId, post_creator_id: PersonId) -> bool;
+  fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error>;
 }
 
 impl Post_ for Post {
@@ -179,14 +181,6 @@ impl Post_ for Post {
   fn is_post_creator(person_id: PersonId, post_creator_id: PersonId) -> bool {
     person_id == post_creator_id
   }
-}
-
-impl ApubObject for Post {
-  type Form = PostForm;
-  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
-    post.filter(ap_id.eq(object_id)).first::<Self>(conn)
-  }
 
   fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
     use lemmy_db_schema::schema::post::dsl::*;
@@ -199,6 +193,17 @@ impl ApubObject for Post {
   }
 }
 
+impl ApubObject for Post {
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    None
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    post.filter(ap_id.eq(object_id)).first::<Self>(conn)
+  }
+}
+
 impl Likeable for PostLike {
   type Form = PostLikeForm;
   type IdType = PostId;