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 /// Whether the comment has been distinguished(speaking officially) by a mod.
42 pub distinguished: bool,
43 pub language_id: LanguageId,
46 #[derive(Debug, Clone, TypedBuilder)]
47 #[builder(field_defaults(default))]
48 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
49 #[cfg_attr(feature = "full", diesel(table_name = comment))]
50 pub struct CommentInsertForm {
52 pub creator_id: PersonId,
57 pub removed: Option<bool>,
58 pub published: Option<chrono::NaiveDateTime>,
59 pub updated: Option<chrono::NaiveDateTime>,
60 pub deleted: Option<bool>,
61 pub ap_id: Option<DbUrl>,
62 pub local: Option<bool>,
63 pub distinguished: Option<bool>,
64 pub language_id: Option<LanguageId>,
67 #[derive(Debug, Clone, TypedBuilder)]
68 #[builder(field_defaults(default))]
69 #[cfg_attr(feature = "full", derive(AsChangeset))]
70 #[cfg_attr(feature = "full", diesel(table_name = comment))]
71 pub struct CommentUpdateForm {
72 pub content: Option<String>,
73 pub removed: Option<bool>,
74 // Don't use a default naive_now here, because the create function does a lot of comment updates
75 pub updated: Option<Option<chrono::NaiveDateTime>>,
76 pub deleted: Option<bool>,
77 pub ap_id: Option<DbUrl>,
78 pub local: Option<bool>,
79 pub distinguished: Option<bool>,
80 pub language_id: Option<LanguageId>,
83 #[derive(PartialEq, Eq, Debug, Clone)]
84 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
85 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
86 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
87 pub struct CommentLike {
89 pub person_id: PersonId,
90 pub comment_id: CommentId,
91 pub post_id: PostId, // TODO this is redundant
93 pub published: chrono::NaiveDateTime,
97 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
98 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
99 pub struct CommentLikeForm {
100 pub person_id: PersonId,
101 pub comment_id: CommentId,
102 pub post_id: PostId, // TODO this is redundant
106 #[derive(PartialEq, Eq, Debug)]
107 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
108 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
109 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
110 pub struct CommentSaved {
112 pub comment_id: CommentId,
113 pub person_id: PersonId,
114 pub published: chrono::NaiveDateTime,
117 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
118 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
119 pub struct CommentSavedForm {
120 pub comment_id: CommentId,
121 pub person_id: PersonId,