]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Adding distinguish comment. Fixes #2002 (#2391)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 use crate::newtypes::{CommentId, DbUrl, LtreeDef, PersonId, PostId};
2 use diesel_ltree::Ltree;
3 use serde::{Deserialize, Serialize};
4
5 #[cfg(feature = "full")]
6 use crate::schema::{comment, comment_like, comment_saved};
7
8 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
9 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
10 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
11 #[cfg_attr(feature = "full", table_name = "comment")]
12 pub struct Comment {
13   pub id: CommentId,
14   pub creator_id: PersonId,
15   pub post_id: PostId,
16   pub content: String,
17   pub removed: bool,
18   pub published: chrono::NaiveDateTime,
19   pub updated: Option<chrono::NaiveDateTime>,
20   pub deleted: bool,
21   pub ap_id: DbUrl,
22   pub local: bool,
23   #[serde(with = "LtreeDef")]
24   pub path: Ltree,
25   pub distinguished: bool,
26 }
27
28 #[derive(Clone, Default)]
29 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
30 #[cfg_attr(feature = "full", table_name = "comment")]
31 pub struct CommentForm {
32   pub creator_id: PersonId,
33   pub post_id: PostId,
34   pub content: String,
35   pub removed: Option<bool>,
36   pub published: Option<chrono::NaiveDateTime>,
37   pub updated: Option<chrono::NaiveDateTime>,
38   pub deleted: Option<bool>,
39   pub ap_id: Option<DbUrl>,
40   pub local: Option<bool>,
41   pub distinguished: Option<bool>,
42 }
43
44 #[derive(PartialEq, Debug, Clone)]
45 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
46 #[cfg_attr(feature = "full", belongs_to(Comment))]
47 #[cfg_attr(feature = "full", table_name = "comment_like")]
48 pub struct CommentLike {
49   pub id: i32,
50   pub person_id: PersonId,
51   pub comment_id: CommentId,
52   pub post_id: PostId, // TODO this is redundant
53   pub score: i16,
54   pub published: chrono::NaiveDateTime,
55 }
56
57 #[derive(Clone)]
58 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
59 #[cfg_attr(feature = "full", table_name = "comment_like")]
60 pub struct CommentLikeForm {
61   pub person_id: PersonId,
62   pub comment_id: CommentId,
63   pub post_id: PostId, // TODO this is redundant
64   pub score: i16,
65 }
66
67 #[derive(PartialEq, Debug)]
68 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
69 #[cfg_attr(feature = "full", belongs_to(Comment))]
70 #[cfg_attr(feature = "full", table_name = "comment_saved")]
71 pub struct CommentSaved {
72   pub id: i32,
73   pub comment_id: CommentId,
74   pub person_id: PersonId,
75   pub published: chrono::NaiveDateTime,
76 }
77
78 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
79 #[cfg_attr(feature = "full", table_name = "comment_saved")]
80 pub struct CommentSavedForm {
81   pub comment_id: CommentId,
82   pub person_id: PersonId,
83 }