1 #[cfg(feature = "full")]
2 use crate::newtypes::LtreeDef;
3 use crate::newtypes::{CommentId, DbUrl, LanguageId, PersonId, PostId};
4 #[cfg(feature = "full")]
5 use crate::schema::{comment, comment_like, comment_saved};
6 #[cfg(feature = "full")]
7 use diesel_ltree::Ltree;
8 use serde::{Deserialize, Serialize};
9 use serde_with::skip_serializing_none;
10 #[cfg(feature = "full")]
12 use typed_builder::TypedBuilder;
14 #[skip_serializing_none]
15 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
16 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
17 #[cfg_attr(feature = "full", ts(export))]
18 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
19 #[cfg_attr(feature = "full", diesel(table_name = comment))]
23 pub creator_id: PersonId,
26 /// Whether the comment has been removed.
28 pub published: chrono::NaiveDateTime,
29 pub updated: Option<chrono::NaiveDateTime>,
30 /// Whether the comment has been deleted by its creator.
32 /// The federated activity id / ap_id.
34 /// Whether the comment is local.
36 #[cfg(feature = "full")]
37 #[cfg_attr(feature = "full", serde(with = "LtreeDef"))]
38 #[cfg_attr(feature = "full", ts(type = "string"))]
39 /// The path / tree location of a comment, separated by dots, ending with the comment's id. Ex: 0.24.27
41 #[cfg(not(feature = "full"))]
43 /// Whether the comment has been distinguished(speaking officially) by a mod.
44 pub distinguished: bool,
45 pub language_id: LanguageId,
48 #[derive(Debug, Clone, TypedBuilder)]
49 #[builder(field_defaults(default))]
50 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
51 #[cfg_attr(feature = "full", diesel(table_name = comment))]
52 pub struct CommentInsertForm {
54 pub creator_id: PersonId,
59 pub removed: Option<bool>,
60 pub published: Option<chrono::NaiveDateTime>,
61 pub updated: Option<chrono::NaiveDateTime>,
62 pub deleted: Option<bool>,
63 pub ap_id: Option<DbUrl>,
64 pub local: Option<bool>,
65 pub distinguished: Option<bool>,
66 pub language_id: Option<LanguageId>,
69 #[derive(Debug, Clone, Default)]
70 #[cfg_attr(feature = "full", derive(AsChangeset))]
71 #[cfg_attr(feature = "full", diesel(table_name = comment))]
72 pub struct CommentUpdateForm {
73 pub content: Option<String>,
74 pub removed: Option<bool>,
75 // Don't use a default naive_now here, because the create function does a lot of comment updates
76 pub updated: Option<Option<chrono::NaiveDateTime>>,
77 pub deleted: Option<bool>,
78 pub ap_id: Option<DbUrl>,
79 pub local: Option<bool>,
80 pub distinguished: Option<bool>,
81 pub language_id: Option<LanguageId>,
84 #[derive(PartialEq, Eq, Debug, Clone)]
85 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
86 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
87 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
88 pub struct CommentLike {
90 pub person_id: PersonId,
91 pub comment_id: CommentId,
92 pub post_id: PostId, // TODO this is redundant
94 pub published: chrono::NaiveDateTime,
98 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
99 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
100 pub struct CommentLikeForm {
101 pub person_id: PersonId,
102 pub comment_id: CommentId,
103 pub post_id: PostId, // TODO this is redundant
107 #[derive(PartialEq, Eq, Debug)]
108 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
109 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
110 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
111 pub struct CommentSaved {
113 pub comment_id: CommentId,
114 pub person_id: PersonId,
115 pub published: chrono::NaiveDateTime,
118 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
119 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
120 pub struct CommentSavedForm {
121 pub comment_id: CommentId,
122 pub person_id: PersonId,