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