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;
13 use serde::{Deserialize, Serialize};
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;
24 Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize,
27 #[table_name = "comment"]
30 pub creator_id: PersonId,
32 pub parent_id: Option<CommentId>,
35 pub read: bool, // Whether the recipient has read the comment or not
36 pub published: chrono::NaiveDateTime,
37 pub updated: Option<chrono::NaiveDateTime>,
44 Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize,
47 #[table_name = "comment_alias_1"]
48 pub struct CommentAlias1 {
50 pub creator_id: PersonId,
52 pub parent_id: Option<CommentId>,
55 pub read: bool, // Whether the recipient has read the comment or not
56 pub published: chrono::NaiveDateTime,
57 pub updated: Option<chrono::NaiveDateTime>,
63 #[derive(Insertable, AsChangeset, Clone, Default)]
64 #[table_name = "comment"]
65 pub struct CommentForm {
66 pub creator_id: PersonId,
69 pub parent_id: Option<CommentId>,
70 pub removed: Option<bool>,
71 pub read: Option<bool>,
72 pub published: Option<chrono::NaiveDateTime>,
73 pub updated: Option<chrono::NaiveDateTime>,
74 pub deleted: Option<bool>,
75 pub ap_id: Option<DbUrl>,
76 pub local: Option<bool>,
79 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
80 #[belongs_to(Comment)]
81 #[table_name = "comment_like"]
82 pub struct CommentLike {
84 pub person_id: PersonId,
85 pub comment_id: CommentId,
86 pub post_id: PostId, // TODO this is redundant
88 pub published: chrono::NaiveDateTime,
91 #[derive(Insertable, AsChangeset, Clone)]
92 #[table_name = "comment_like"]
93 pub struct CommentLikeForm {
94 pub person_id: PersonId,
95 pub comment_id: CommentId,
96 pub post_id: PostId, // TODO this is redundant
100 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
101 #[belongs_to(Comment)]
102 #[table_name = "comment_saved"]
103 pub struct CommentSaved {
105 pub comment_id: CommentId,
106 pub person_id: PersonId,
107 pub published: chrono::NaiveDateTime,
110 #[derive(Insertable, AsChangeset)]
111 #[table_name = "comment_saved"]
112 pub struct CommentSavedForm {
113 pub comment_id: CommentId,
114 pub person_id: PersonId,
117 impl ApubObject for Comment {
118 type DataType = PgConnection;
120 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
124 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
125 use crate::schema::comment::dsl::*;
126 let object_id: DbUrl = object_id.into();
127 Ok(comment.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())