1 use crate::sensitive::Sensitive;
3 newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
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")]
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))]
21 pub struct CreatePost {
23 pub community_id: CommunityId,
24 #[cfg_attr(feature = "full", ts(type = "string"))]
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>,
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,
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.
48 pub id: Option<PostId>,
49 pub comment_id: Option<CommentId>,
50 pub auth: Option<Sensitive<String>>,
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>,
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.
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>>,
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>,
89 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
90 #[cfg_attr(feature = "full", derive(TS))]
91 #[cfg_attr(feature = "full", ts(export))]
93 pub struct CreatePostLike {
95 /// Score must be -1, 0, or 1.
97 pub auth: Sensitive<String>,
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))]
105 pub struct EditPost {
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>,
117 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
118 #[cfg_attr(feature = "full", derive(TS))]
119 #[cfg_attr(feature = "full", ts(export))]
121 pub struct DeletePost {
124 pub auth: Sensitive<String>,
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 {
135 pub reason: Option<String>,
136 pub auth: Sensitive<String>,
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 {
146 pub auth: Sensitive<String>,
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 {
156 pub auth: Sensitive<String>,
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 {
166 pub feature_type: PostFeatureType,
167 pub auth: Sensitive<String>,
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 {
177 pub auth: Sensitive<String>,
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 {
187 pub auth: Sensitive<String>,
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,
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,
205 pub auth: Sensitive<String>,
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>,
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>,
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"))]
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,
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>,