use crate::{
- naive_now,
newtypes::{CommunityId, DbUrl, PersonId, PostId},
source::post::{
Post,
PostSavedForm,
},
traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable},
+ utils::naive_now,
};
-use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::ApubObject;
-use lemmy_utils::LemmyError;
use url::Url;
impl Crud for Post {
use crate::schema::post::dsl::*;
post
.filter(community_id.eq(the_community_id))
+ .filter(deleted.eq(false))
+ .filter(removed.eq(false))
.then_order_by(published.desc())
.then_order_by(stickied.desc())
.limit(20)
.set(post_form)
.get_result::<Self>(conn)
}
+ pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
+ use crate::schema::post::dsl::*;
+ let object_id: DbUrl = object_id.into();
+ Ok(
+ post
+ .filter(ap_id.eq(object_id))
+ .first::<Post>(conn)
+ .ok()
+ .map(Into::into),
+ )
+ }
}
impl Likeable for PostLike {
self.body = None;
self.embed_title = None;
self.embed_description = None;
- self.embed_html = None;
+ self.embed_video_url = None;
self.thumbnail_url = None;
self
}
}
-impl ApubObject for Post {
- type DataType = PgConnection;
-
- fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
- None
- }
-
- fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
- use crate::schema::post::dsl::*;
- let object_id: DbUrl = object_id.into();
- Ok(post.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
- }
-
- fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
- use crate::schema::post::dsl::*;
- diesel::update(post.find(self.id))
- .set((deleted.eq(true), updated.eq(naive_now())))
- .get_result::<Self>(conn)?;
- Ok(())
- }
-}
-
#[cfg(test)]
mod tests {
use crate::{
- establish_unpooled_connection,
source::{
community::{Community, CommunityForm},
person::*,
post::*,
},
traits::{Crud, Likeable, Readable, Saveable},
+ utils::establish_unpooled_connection,
};
use serial_test::serial;
updated: None,
embed_title: None,
embed_description: None,
- embed_html: None,
+ embed_video_url: None,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,