2 schema::{comment, comment_alias_1, comment_like, comment_saved},
9 use chrono::NaiveDateTime;
10 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
11 use lemmy_apub_lib::traits::ApubObject;
12 use lemmy_utils::LemmyError;
16 // WITH RECURSIVE MyTree AS (
17 // SELECT * FROM comment WHERE parent_id IS NULL
19 // SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
21 // SELECT * FROM MyTree;
23 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
25 #[table_name = "comment"]
28 pub creator_id: PersonId,
30 pub parent_id: Option<CommentId>,
33 pub read: bool, // Whether the recipient has read the comment or not
34 pub published: chrono::NaiveDateTime,
35 pub updated: Option<chrono::NaiveDateTime>,
41 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
43 #[table_name = "comment_alias_1"]
44 pub struct CommentAlias1 {
46 pub creator_id: PersonId,
48 pub parent_id: Option<CommentId>,
51 pub read: bool, // Whether the recipient has read the comment or not
52 pub published: chrono::NaiveDateTime,
53 pub updated: Option<chrono::NaiveDateTime>,
59 #[derive(Insertable, AsChangeset, Clone, Default)]
60 #[table_name = "comment"]
61 pub struct CommentForm {
62 pub creator_id: PersonId,
65 pub parent_id: Option<CommentId>,
66 pub removed: Option<bool>,
67 pub read: Option<bool>,
68 pub published: Option<chrono::NaiveDateTime>,
69 pub updated: Option<chrono::NaiveDateTime>,
70 pub deleted: Option<bool>,
71 pub ap_id: Option<DbUrl>,
72 pub local: Option<bool>,
75 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
76 #[belongs_to(Comment)]
77 #[table_name = "comment_like"]
78 pub struct CommentLike {
80 pub person_id: PersonId,
81 pub comment_id: CommentId,
82 pub post_id: PostId, // TODO this is redundant
84 pub published: chrono::NaiveDateTime,
87 #[derive(Insertable, AsChangeset, Clone)]
88 #[table_name = "comment_like"]
89 pub struct CommentLikeForm {
90 pub person_id: PersonId,
91 pub comment_id: CommentId,
92 pub post_id: PostId, // TODO this is redundant
96 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
97 #[belongs_to(Comment)]
98 #[table_name = "comment_saved"]
99 pub struct CommentSaved {
101 pub comment_id: CommentId,
102 pub person_id: PersonId,
103 pub published: chrono::NaiveDateTime,
106 #[derive(Insertable, AsChangeset)]
107 #[table_name = "comment_saved"]
108 pub struct CommentSavedForm {
109 pub comment_id: CommentId,
110 pub person_id: PersonId,
113 impl ApubObject for Comment {
114 type DataType = PgConnection;
116 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
120 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
121 use crate::schema::comment::dsl::*;
122 let object_id: DbUrl = object_id.into();
123 Ok(comment.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())