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