]> Untitled Git - lemmy.git/blob - crates/api_common/src/comment.rs
Fix process shutdown (#3673)
[lemmy.git] / crates / api_common / src / comment.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommentReportId, CommunityId, LanguageId, LocalUserId, PostId},
4   CommentSortType,
5   ListingType,
6 };
7 use lemmy_db_views::structs::{CommentReportView, CommentView};
8 use serde::{Deserialize, Serialize};
9 use serde_with::skip_serializing_none;
10 #[cfg(feature = "full")]
11 use ts_rs::TS;
12
13 #[skip_serializing_none]
14 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
15 #[cfg_attr(feature = "full", derive(TS))]
16 #[cfg_attr(feature = "full", ts(export))]
17 /// Create a comment.
18 pub struct CreateComment {
19   pub content: String,
20   pub post_id: PostId,
21   pub parent_id: Option<CommentId>,
22   pub language_id: Option<LanguageId>,
23   /// An optional front-end ID, to help UIs determine where the comment should go.
24   pub form_id: Option<String>,
25   pub auth: Sensitive<String>,
26 }
27
28 #[skip_serializing_none]
29 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
30 #[cfg_attr(feature = "full", derive(TS))]
31 #[cfg_attr(feature = "full", ts(export))]
32 /// Fetch an individual comment.
33 pub struct GetComment {
34   pub id: CommentId,
35   pub auth: Option<Sensitive<String>>,
36 }
37
38 #[skip_serializing_none]
39 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
40 #[cfg_attr(feature = "full", derive(TS))]
41 #[cfg_attr(feature = "full", ts(export))]
42 /// Edit a comment.
43 pub struct EditComment {
44   pub comment_id: CommentId,
45   pub content: Option<String>,
46   pub language_id: Option<LanguageId>,
47   pub form_id: Option<String>,
48   pub auth: Sensitive<String>,
49 }
50
51 #[skip_serializing_none]
52 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
53 #[cfg_attr(feature = "full", derive(TS))]
54 #[cfg_attr(feature = "full", ts(export))]
55 /// Distinguish a comment (IE speak as moderator).
56 pub struct DistinguishComment {
57   pub comment_id: CommentId,
58   pub distinguished: bool,
59   pub auth: Sensitive<String>,
60 }
61
62 #[skip_serializing_none]
63 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
64 #[cfg_attr(feature = "full", derive(TS))]
65 #[cfg_attr(feature = "full", ts(export))]
66 /// Delete your own comment.
67 pub struct DeleteComment {
68   pub comment_id: CommentId,
69   pub deleted: bool,
70   pub auth: Sensitive<String>,
71 }
72
73 #[skip_serializing_none]
74 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
75 #[cfg_attr(feature = "full", derive(TS))]
76 #[cfg_attr(feature = "full", ts(export))]
77 /// Remove a comment (only doable by mods).
78 pub struct RemoveComment {
79   pub comment_id: CommentId,
80   pub removed: bool,
81   pub reason: Option<String>,
82   pub auth: Sensitive<String>,
83 }
84
85 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
86 #[cfg_attr(feature = "full", derive(TS))]
87 #[cfg_attr(feature = "full", ts(export))]
88 /// Save / bookmark a comment.
89 pub struct SaveComment {
90   pub comment_id: CommentId,
91   pub save: bool,
92   pub auth: Sensitive<String>,
93 }
94
95 #[skip_serializing_none]
96 #[derive(Debug, Serialize, Deserialize, Clone)]
97 #[cfg_attr(feature = "full", derive(TS))]
98 #[cfg_attr(feature = "full", ts(export))]
99 /// A comment response.
100 pub struct CommentResponse {
101   pub comment_view: CommentView,
102   pub recipient_ids: Vec<LocalUserId>,
103   /// An optional front end ID, to tell which is coming back  
104   pub form_id: Option<String>,
105 }
106
107 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
108 #[cfg_attr(feature = "full", derive(TS))]
109 #[cfg_attr(feature = "full", ts(export))]
110 /// Like a comment.
111 pub struct CreateCommentLike {
112   pub comment_id: CommentId,
113   /// Must be -1, 0, or 1 .
114   pub score: i16,
115   pub auth: Sensitive<String>,
116 }
117
118 #[skip_serializing_none]
119 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
120 #[cfg_attr(feature = "full", derive(TS))]
121 #[cfg_attr(feature = "full", ts(export))]
122 /// Get a list of comments.
123 pub struct GetComments {
124   pub type_: Option<ListingType>,
125   pub sort: Option<CommentSortType>,
126   pub max_depth: Option<i32>,
127   pub page: Option<i64>,
128   pub limit: Option<i64>,
129   pub community_id: Option<CommunityId>,
130   pub community_name: Option<String>,
131   pub post_id: Option<PostId>,
132   pub parent_id: Option<CommentId>,
133   pub saved_only: Option<bool>,
134   pub auth: Option<Sensitive<String>>,
135 }
136
137 #[derive(Debug, Serialize, Deserialize, Clone)]
138 #[cfg_attr(feature = "full", derive(TS))]
139 #[cfg_attr(feature = "full", ts(export))]
140 /// The comment list response.
141 pub struct GetCommentsResponse {
142   pub comments: Vec<CommentView>,
143 }
144
145 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
146 #[cfg_attr(feature = "full", derive(TS))]
147 #[cfg_attr(feature = "full", ts(export))]
148 /// Report a comment.
149 pub struct CreateCommentReport {
150   pub comment_id: CommentId,
151   pub reason: String,
152   pub auth: Sensitive<String>,
153 }
154
155 #[derive(Debug, Serialize, Deserialize, Clone)]
156 #[cfg_attr(feature = "full", derive(TS))]
157 #[cfg_attr(feature = "full", ts(export))]
158 /// The comment report response.
159 pub struct CommentReportResponse {
160   pub comment_report_view: CommentReportView,
161 }
162
163 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
164 #[cfg_attr(feature = "full", derive(TS))]
165 #[cfg_attr(feature = "full", ts(export))]
166 /// Resolve a comment report (only doable by mods).
167 pub struct ResolveCommentReport {
168   pub report_id: CommentReportId,
169   pub resolved: bool,
170   pub auth: Sensitive<String>,
171 }
172
173 #[skip_serializing_none]
174 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
175 #[cfg_attr(feature = "full", derive(TS))]
176 #[cfg_attr(feature = "full", ts(export))]
177 /// List comment reports.
178 pub struct ListCommentReports {
179   pub page: Option<i64>,
180   pub limit: Option<i64>,
181   /// Only shows the unresolved reports
182   pub unresolved_only: Option<bool>,
183   /// if no community is given, it returns reports for all communities moderated by the auth user
184   pub community_id: Option<CommunityId>,
185   pub auth: Sensitive<String>,
186 }
187
188 #[derive(Debug, Serialize, Deserialize, Clone)]
189 #[cfg_attr(feature = "full", derive(TS))]
190 #[cfg_attr(feature = "full", ts(export))]
191 /// The comment report list response.
192 pub struct ListCommentReportsResponse {
193   pub comment_reports: Vec<CommentReportView>,
194 }