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 liked_only: Option<bool>,
79 pub disliked_only: Option<bool>,
80 pub moderator_view: Option<bool>,
81 pub auth: Option<Sensitive<String>>,
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>,
92 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
93 #[cfg_attr(feature = "full", derive(TS))]
94 #[cfg_attr(feature = "full", ts(export))]
96 pub struct CreatePostLike {
98 /// Score must be -1, 0, or 1.
100 pub auth: Sensitive<String>,
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))]
108 pub struct EditPost {
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>,
120 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
121 #[cfg_attr(feature = "full", derive(TS))]
122 #[cfg_attr(feature = "full", ts(export))]
124 pub struct DeletePost {
127 pub auth: Sensitive<String>,
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 {
138 pub reason: Option<String>,
139 pub auth: Sensitive<String>,
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 {
149 pub auth: Sensitive<String>,
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 {
159 pub auth: Sensitive<String>,
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 {
169 pub feature_type: PostFeatureType,
170 pub auth: Sensitive<String>,
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 {
180 pub auth: Sensitive<String>,
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 {
190 pub auth: Sensitive<String>,
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,
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,
208 pub auth: Sensitive<String>,
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>,
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>,
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"))]
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,
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>,