]> Untitled Git - lemmy.git/blob - crates/api_common/src/post.rs
add enable_federated_downvotes site option
[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 liked_only: Option<bool>,
79   pub disliked_only: Option<bool>,
80   pub moderator_view: Option<bool>,
81   pub auth: Option<Sensitive<String>>,
82 }
83
84 #[derive(Serialize, Deserialize, Debug, Clone)]
85 #[cfg_attr(feature = "full", derive(TS))]
86 #[cfg_attr(feature = "full", ts(export))]
87 /// The post list response.
88 pub struct GetPostsResponse {
89   pub posts: Vec<PostView>,
90 }
91
92 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
93 #[cfg_attr(feature = "full", derive(TS))]
94 #[cfg_attr(feature = "full", ts(export))]
95 /// Like a post.
96 pub struct CreatePostLike {
97   pub post_id: PostId,
98   /// Score must be -1, 0, or 1.
99   pub score: i16,
100   pub auth: Sensitive<String>,
101 }
102
103 #[skip_serializing_none]
104 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
105 #[cfg_attr(feature = "full", derive(TS))]
106 #[cfg_attr(feature = "full", ts(export))]
107 /// Edit a post.
108 pub struct EditPost {
109   pub post_id: PostId,
110   pub name: Option<String>,
111   #[cfg_attr(feature = "full", ts(type = "string"))]
112   pub url: Option<Url>,
113   /// An optional body for the post in markdown.
114   pub body: Option<String>,
115   pub nsfw: Option<bool>,
116   pub language_id: Option<LanguageId>,
117   pub auth: Sensitive<String>,
118 }
119
120 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
121 #[cfg_attr(feature = "full", derive(TS))]
122 #[cfg_attr(feature = "full", ts(export))]
123 /// Delete a post.
124 pub struct DeletePost {
125   pub post_id: PostId,
126   pub deleted: bool,
127   pub auth: Sensitive<String>,
128 }
129
130 #[skip_serializing_none]
131 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
132 #[cfg_attr(feature = "full", derive(TS))]
133 #[cfg_attr(feature = "full", ts(export))]
134 /// Remove a post (only doable by mods).
135 pub struct RemovePost {
136   pub post_id: PostId,
137   pub removed: bool,
138   pub reason: Option<String>,
139   pub auth: Sensitive<String>,
140 }
141
142 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
143 #[cfg_attr(feature = "full", derive(TS))]
144 #[cfg_attr(feature = "full", ts(export))]
145 /// Mark a post as read.
146 pub struct MarkPostAsRead {
147   pub post_id: PostId,
148   pub read: bool,
149   pub auth: Sensitive<String>,
150 }
151
152 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
153 #[cfg_attr(feature = "full", derive(TS))]
154 #[cfg_attr(feature = "full", ts(export))]
155 /// Lock a post (prevent new comments).
156 pub struct LockPost {
157   pub post_id: PostId,
158   pub locked: bool,
159   pub auth: Sensitive<String>,
160 }
161
162 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
163 #[cfg_attr(feature = "full", derive(TS))]
164 #[cfg_attr(feature = "full", ts(export))]
165 /// Feature a post (stickies / pins to the top).
166 pub struct FeaturePost {
167   pub post_id: PostId,
168   pub featured: bool,
169   pub feature_type: PostFeatureType,
170   pub auth: Sensitive<String>,
171 }
172
173 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
174 #[cfg_attr(feature = "full", derive(TS))]
175 #[cfg_attr(feature = "full", ts(export))]
176 /// Save / bookmark a post.
177 pub struct SavePost {
178   pub post_id: PostId,
179   pub save: bool,
180   pub auth: Sensitive<String>,
181 }
182
183 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
184 #[cfg_attr(feature = "full", derive(TS))]
185 #[cfg_attr(feature = "full", ts(export))]
186 /// Create a post report.
187 pub struct CreatePostReport {
188   pub post_id: PostId,
189   pub reason: String,
190   pub auth: Sensitive<String>,
191 }
192
193 #[derive(Debug, Serialize, Deserialize, Clone)]
194 #[cfg_attr(feature = "full", derive(TS))]
195 #[cfg_attr(feature = "full", ts(export))]
196 /// The post report response.
197 pub struct PostReportResponse {
198   pub post_report_view: PostReportView,
199 }
200
201 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
202 #[cfg_attr(feature = "full", derive(TS))]
203 #[cfg_attr(feature = "full", ts(export))]
204 /// Resolve a post report (mods only).
205 pub struct ResolvePostReport {
206   pub report_id: PostReportId,
207   pub resolved: bool,
208   pub auth: Sensitive<String>,
209 }
210
211 #[skip_serializing_none]
212 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
213 #[cfg_attr(feature = "full", derive(TS))]
214 #[cfg_attr(feature = "full", ts(export))]
215 /// List post reports.
216 pub struct ListPostReports {
217   pub page: Option<i64>,
218   pub limit: Option<i64>,
219   /// Only shows the unresolved reports
220   pub unresolved_only: Option<bool>,
221   /// if no community is given, it returns reports for all communities moderated by the auth user
222   pub community_id: Option<CommunityId>,
223   pub auth: Sensitive<String>,
224 }
225
226 #[derive(Debug, Serialize, Deserialize, Clone)]
227 #[cfg_attr(feature = "full", derive(TS))]
228 #[cfg_attr(feature = "full", ts(export))]
229 /// The post reports response.
230 pub struct ListPostReportsResponse {
231   pub post_reports: Vec<PostReportView>,
232 }
233
234 #[derive(Debug, Serialize, Deserialize, Clone)]
235 #[cfg_attr(feature = "full", derive(TS))]
236 #[cfg_attr(feature = "full", ts(export))]
237 /// Get metadata for a given site.
238 pub struct GetSiteMetadata {
239   #[cfg_attr(feature = "full", ts(type = "string"))]
240   pub url: Url,
241 }
242
243 #[derive(Debug, Serialize, Deserialize, Clone)]
244 #[cfg_attr(feature = "full", derive(TS))]
245 #[cfg_attr(feature = "full", ts(export))]
246 /// The site metadata response.
247 pub struct GetSiteMetadataResponse {
248   pub metadata: SiteMetadata,
249 }
250
251 #[skip_serializing_none]
252 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
253 #[cfg_attr(feature = "full", derive(TS))]
254 #[cfg_attr(feature = "full", ts(export))]
255 /// Site metadata, from its opengraph tags.
256 pub struct SiteMetadata {
257   pub title: Option<String>,
258   pub description: Option<String>,
259   pub(crate) image: Option<DbUrl>,
260   pub embed_video_url: Option<DbUrl>,
261 }