]> Untitled Git - lemmy.git/blob - crates/api_common/src/post.rs
Sanitize html (#3708)
[lemmy.git] / crates / api_common / src / post.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
4   ListingType,
5   PostFeatureType,
6   SortType,
7 };
8 use lemmy_db_views::structs::{PostReportView, PostView};
9 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
10 use serde::{Deserialize, Serialize};
11 use serde_with::skip_serializing_none;
12 #[cfg(feature = "full")]
13 use ts_rs::TS;
14 use url::Url;
15
16 #[skip_serializing_none]
17 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
18 #[cfg_attr(feature = "full", derive(TS))]
19 #[cfg_attr(feature = "full", ts(export))]
20 /// Create a post.
21 pub struct CreatePost {
22   pub name: String,
23   pub community_id: CommunityId,
24   #[cfg_attr(feature = "full", ts(type = "string"))]
25   pub url: Option<Url>,
26   /// An optional body for the post in markdown.
27   pub body: Option<String>,
28   /// A honeypot to catch bots. Should be None.
29   pub honeypot: Option<String>,
30   pub nsfw: Option<bool>,
31   pub language_id: Option<LanguageId>,
32   pub auth: Sensitive<String>,
33 }
34
35 #[derive(Debug, Serialize, Deserialize, Clone)]
36 #[cfg_attr(feature = "full", derive(TS))]
37 #[cfg_attr(feature = "full", ts(export))]
38 pub struct PostResponse {
39   pub post_view: PostView,
40 }
41
42 #[skip_serializing_none]
43 #[derive(Debug, Serialize, Deserialize, Clone)]
44 #[cfg_attr(feature = "full", derive(TS))]
45 #[cfg_attr(feature = "full", ts(export))]
46 /// Get a post. Needs either the post id, or comment_id.
47 pub struct GetPost {
48   pub id: Option<PostId>,
49   pub comment_id: Option<CommentId>,
50   pub auth: Option<Sensitive<String>>,
51 }
52
53 #[derive(Debug, Serialize, Deserialize, Clone)]
54 #[cfg_attr(feature = "full", derive(TS))]
55 #[cfg_attr(feature = "full", ts(export))]
56 /// The post response.
57 pub struct GetPostResponse {
58   pub post_view: PostView,
59   pub community_view: CommunityView,
60   pub moderators: Vec<CommunityModeratorView>,
61   /// A list of cross-posts, or other times / communities this link has been posted to.
62   pub cross_posts: Vec<PostView>,
63 }
64
65 #[skip_serializing_none]
66 #[derive(Serialize, Deserialize, Debug, Clone, Default)]
67 #[cfg_attr(feature = "full", derive(TS))]
68 #[cfg_attr(feature = "full", ts(export))]
69 /// Get a list of posts.
70 pub struct GetPosts {
71   pub type_: Option<ListingType>,
72   pub sort: Option<SortType>,
73   pub page: Option<i64>,
74   pub limit: Option<i64>,
75   pub community_id: Option<CommunityId>,
76   pub community_name: Option<String>,
77   pub saved_only: Option<bool>,
78   pub moderator_view: Option<bool>,
79   pub auth: Option<Sensitive<String>>,
80 }
81
82 #[derive(Serialize, Deserialize, Debug, Clone)]
83 #[cfg_attr(feature = "full", derive(TS))]
84 #[cfg_attr(feature = "full", ts(export))]
85 /// The post list response.
86 pub struct GetPostsResponse {
87   pub posts: Vec<PostView>,
88 }
89
90 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
91 #[cfg_attr(feature = "full", derive(TS))]
92 #[cfg_attr(feature = "full", ts(export))]
93 /// Like a post.
94 pub struct CreatePostLike {
95   pub post_id: PostId,
96   /// Score must be -1, 0, or 1.
97   pub score: i16,
98   pub auth: Sensitive<String>,
99 }
100
101 #[skip_serializing_none]
102 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
103 #[cfg_attr(feature = "full", derive(TS))]
104 #[cfg_attr(feature = "full", ts(export))]
105 /// Edit a post.
106 pub struct EditPost {
107   pub post_id: PostId,
108   pub name: Option<String>,
109   #[cfg_attr(feature = "full", ts(type = "string"))]
110   pub url: Option<Url>,
111   /// An optional body for the post in markdown.
112   pub body: Option<String>,
113   pub nsfw: Option<bool>,
114   pub language_id: Option<LanguageId>,
115   pub auth: Sensitive<String>,
116 }
117
118 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
119 #[cfg_attr(feature = "full", derive(TS))]
120 #[cfg_attr(feature = "full", ts(export))]
121 /// Delete a post.
122 pub struct DeletePost {
123   pub post_id: PostId,
124   pub deleted: bool,
125   pub auth: Sensitive<String>,
126 }
127
128 #[skip_serializing_none]
129 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
130 #[cfg_attr(feature = "full", derive(TS))]
131 #[cfg_attr(feature = "full", ts(export))]
132 /// Remove a post (only doable by mods).
133 pub struct RemovePost {
134   pub post_id: PostId,
135   pub removed: bool,
136   pub reason: Option<String>,
137   pub auth: Sensitive<String>,
138 }
139
140 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
141 #[cfg_attr(feature = "full", derive(TS))]
142 #[cfg_attr(feature = "full", ts(export))]
143 /// Mark a post as read.
144 pub struct MarkPostAsRead {
145   pub post_id: PostId,
146   pub read: bool,
147   pub auth: Sensitive<String>,
148 }
149
150 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
151 #[cfg_attr(feature = "full", derive(TS))]
152 #[cfg_attr(feature = "full", ts(export))]
153 /// Lock a post (prevent new comments).
154 pub struct LockPost {
155   pub post_id: PostId,
156   pub locked: bool,
157   pub auth: Sensitive<String>,
158 }
159
160 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
161 #[cfg_attr(feature = "full", derive(TS))]
162 #[cfg_attr(feature = "full", ts(export))]
163 /// Feature a post (stickies / pins to the top).
164 pub struct FeaturePost {
165   pub post_id: PostId,
166   pub featured: bool,
167   pub feature_type: PostFeatureType,
168   pub auth: Sensitive<String>,
169 }
170
171 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
172 #[cfg_attr(feature = "full", derive(TS))]
173 #[cfg_attr(feature = "full", ts(export))]
174 /// Save / bookmark a post.
175 pub struct SavePost {
176   pub post_id: PostId,
177   pub save: bool,
178   pub auth: Sensitive<String>,
179 }
180
181 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
182 #[cfg_attr(feature = "full", derive(TS))]
183 #[cfg_attr(feature = "full", ts(export))]
184 /// Create a post report.
185 pub struct CreatePostReport {
186   pub post_id: PostId,
187   pub reason: String,
188   pub auth: Sensitive<String>,
189 }
190
191 #[derive(Debug, Serialize, Deserialize, Clone)]
192 #[cfg_attr(feature = "full", derive(TS))]
193 #[cfg_attr(feature = "full", ts(export))]
194 /// The post report response.
195 pub struct PostReportResponse {
196   pub post_report_view: PostReportView,
197 }
198
199 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
200 #[cfg_attr(feature = "full", derive(TS))]
201 #[cfg_attr(feature = "full", ts(export))]
202 /// Resolve a post report (mods only).
203 pub struct ResolvePostReport {
204   pub report_id: PostReportId,
205   pub resolved: bool,
206   pub auth: Sensitive<String>,
207 }
208
209 #[skip_serializing_none]
210 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
211 #[cfg_attr(feature = "full", derive(TS))]
212 #[cfg_attr(feature = "full", ts(export))]
213 /// List post reports.
214 pub struct ListPostReports {
215   pub page: Option<i64>,
216   pub limit: Option<i64>,
217   /// Only shows the unresolved reports
218   pub unresolved_only: Option<bool>,
219   /// if no community is given, it returns reports for all communities moderated by the auth user
220   pub community_id: Option<CommunityId>,
221   pub auth: Sensitive<String>,
222 }
223
224 #[derive(Debug, Serialize, Deserialize, Clone)]
225 #[cfg_attr(feature = "full", derive(TS))]
226 #[cfg_attr(feature = "full", ts(export))]
227 /// The post reports response.
228 pub struct ListPostReportsResponse {
229   pub post_reports: Vec<PostReportView>,
230 }
231
232 #[derive(Debug, Serialize, Deserialize, Clone)]
233 #[cfg_attr(feature = "full", derive(TS))]
234 #[cfg_attr(feature = "full", ts(export))]
235 /// Get metadata for a given site.
236 pub struct GetSiteMetadata {
237   #[cfg_attr(feature = "full", ts(type = "string"))]
238   pub url: Url,
239 }
240
241 #[derive(Debug, Serialize, Deserialize, Clone)]
242 #[cfg_attr(feature = "full", derive(TS))]
243 #[cfg_attr(feature = "full", ts(export))]
244 /// The site metadata response.
245 pub struct GetSiteMetadataResponse {
246   pub metadata: SiteMetadata,
247 }
248
249 #[skip_serializing_none]
250 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
251 #[cfg_attr(feature = "full", derive(TS))]
252 #[cfg_attr(feature = "full", ts(export))]
253 /// Site metadata, from its opengraph tags.
254 pub struct SiteMetadata {
255   pub title: Option<String>,
256   pub description: Option<String>,
257   pub(crate) image: Option<DbUrl>,
258   pub embed_video_url: Option<DbUrl>,
259 }