2 schema::{post, post_like, post_read, post_saved},
8 use chrono::NaiveDateTime;
9 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
10 use lemmy_apub_lib::traits::ApubObject;
11 use lemmy_utils::LemmyError;
15 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
16 #[table_name = "post"]
20 pub url: Option<DbUrl>,
21 pub body: Option<String>,
22 pub creator_id: PersonId,
23 pub community_id: CommunityId,
26 pub published: chrono::NaiveDateTime,
27 pub updated: Option<chrono::NaiveDateTime>,
31 pub embed_title: Option<String>,
32 pub embed_description: Option<String>,
33 pub embed_html: Option<String>,
34 pub thumbnail_url: Option<DbUrl>,
39 #[derive(Insertable, AsChangeset, Default)]
40 #[table_name = "post"]
43 pub creator_id: PersonId,
44 pub community_id: CommunityId,
45 pub nsfw: Option<bool>,
46 pub url: Option<DbUrl>,
47 pub body: Option<String>,
48 pub removed: Option<bool>,
49 pub locked: Option<bool>,
50 pub published: Option<chrono::NaiveDateTime>,
51 pub updated: Option<chrono::NaiveDateTime>,
52 pub deleted: Option<bool>,
53 pub stickied: Option<bool>,
54 pub embed_title: Option<String>,
55 pub embed_description: Option<String>,
56 pub embed_html: Option<String>,
57 pub thumbnail_url: Option<DbUrl>,
58 pub ap_id: Option<DbUrl>,
59 pub local: Option<bool>,
62 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
64 #[table_name = "post_like"]
68 pub person_id: PersonId,
70 pub published: chrono::NaiveDateTime,
73 #[derive(Insertable, AsChangeset, Clone)]
74 #[table_name = "post_like"]
75 pub struct PostLikeForm {
77 pub person_id: PersonId,
81 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
83 #[table_name = "post_saved"]
84 pub struct PostSaved {
87 pub person_id: PersonId,
88 pub published: chrono::NaiveDateTime,
91 #[derive(Insertable, AsChangeset)]
92 #[table_name = "post_saved"]
93 pub struct PostSavedForm {
95 pub person_id: PersonId,
98 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
100 #[table_name = "post_read"]
101 pub struct PostRead {
104 pub person_id: PersonId,
105 pub published: chrono::NaiveDateTime,
108 #[derive(Insertable, AsChangeset)]
109 #[table_name = "post_read"]
110 pub struct PostReadForm {
112 pub person_id: PersonId,
115 impl ApubObject for Post {
116 type DataType = PgConnection;
118 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
122 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
123 use crate::schema::post::dsl::*;
124 let object_id: DbUrl = object_id.into();
125 Ok(post.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())