]> Untitled Git - lemmy.git/blob - crates/api_common/src/comment.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / api_common / src / comment.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId},
4   CommentSortType,
5   ListingType,
6 };
7 use lemmy_db_views::structs::{CommentReportView, CommentView};
8 use serde::{Deserialize, Serialize};
9
10 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
11 pub struct CreateComment {
12   pub content: String,
13   pub post_id: PostId,
14   pub parent_id: Option<CommentId>,
15   pub form_id: Option<String>,
16   pub auth: Sensitive<String>,
17 }
18
19 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
20 pub struct GetComment {
21   pub id: CommentId,
22   pub auth: Option<Sensitive<String>>,
23 }
24
25 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
26 pub struct EditComment {
27   pub content: String,
28   pub comment_id: CommentId,
29   pub form_id: Option<String>,
30   pub auth: Sensitive<String>,
31 }
32
33 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
34 pub struct DeleteComment {
35   pub comment_id: CommentId,
36   pub deleted: bool,
37   pub auth: Sensitive<String>,
38 }
39
40 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
41 pub struct RemoveComment {
42   pub comment_id: CommentId,
43   pub removed: bool,
44   pub reason: Option<String>,
45   pub auth: Sensitive<String>,
46 }
47
48 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
49 pub struct SaveComment {
50   pub comment_id: CommentId,
51   pub save: bool,
52   pub auth: Sensitive<String>,
53 }
54
55 #[derive(Debug, Serialize, Deserialize, Clone)]
56 pub struct CommentResponse {
57   pub comment_view: CommentView,
58   pub recipient_ids: Vec<LocalUserId>,
59   pub form_id: Option<String>, // An optional front end ID, to tell which is coming back
60 }
61
62 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
63 pub struct CreateCommentLike {
64   pub comment_id: CommentId,
65   pub score: i16,
66   pub auth: Sensitive<String>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
70 pub struct GetComments {
71   pub type_: Option<ListingType>,
72   pub sort: Option<CommentSortType>,
73   pub max_depth: Option<i32>,
74   pub page: Option<i64>,
75   pub limit: Option<i64>,
76   pub community_id: Option<CommunityId>,
77   pub community_name: Option<String>,
78   pub post_id: Option<PostId>,
79   pub parent_id: Option<CommentId>,
80   pub saved_only: Option<bool>,
81   pub auth: Option<Sensitive<String>>,
82 }
83
84 #[derive(Debug, Serialize, Deserialize, Clone)]
85 pub struct GetCommentsResponse {
86   pub comments: Vec<CommentView>,
87 }
88
89 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
90 pub struct CreateCommentReport {
91   pub comment_id: CommentId,
92   pub reason: String,
93   pub auth: Sensitive<String>,
94 }
95
96 #[derive(Debug, Serialize, Deserialize, Clone)]
97 pub struct CommentReportResponse {
98   pub comment_report_view: CommentReportView,
99 }
100
101 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
102 pub struct ResolveCommentReport {
103   pub report_id: CommentReportId,
104   pub resolved: bool,
105   pub auth: Sensitive<String>,
106 }
107
108 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
109 pub struct ListCommentReports {
110   pub page: Option<i64>,
111   pub limit: Option<i64>,
112   /// Only shows the unresolved reports
113   pub unresolved_only: Option<bool>,
114   /// if no community is given, it returns reports for all communities moderated by the auth user
115   pub community_id: Option<CommunityId>,
116   pub auth: Sensitive<String>,
117 }
118
119 #[derive(Debug, Serialize, Deserialize, Clone)]
120 pub struct ListCommentReportsResponse {
121   pub comment_reports: Vec<CommentReportView>,
122 }