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 moderator_view: Option<bool>,
79 pub auth: Option<Sensitive<String>>,
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>,
90 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
91 #[cfg_attr(feature = "full", derive(TS))]
92 #[cfg_attr(feature = "full", ts(export))]
94 pub struct CreatePostLike {
96 /// Score must be -1, 0, or 1.
98 pub auth: Sensitive<String>,
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))]
106 pub struct EditPost {
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>,
118 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
119 #[cfg_attr(feature = "full", derive(TS))]
120 #[cfg_attr(feature = "full", ts(export))]
122 pub struct DeletePost {
125 pub auth: Sensitive<String>,
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 {
136 pub reason: Option<String>,
137 pub auth: Sensitive<String>,
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 {
147 pub auth: Sensitive<String>,
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 {
157 pub auth: Sensitive<String>,
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 {
167 pub feature_type: PostFeatureType,
168 pub auth: Sensitive<String>,
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 {
178 pub auth: Sensitive<String>,
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 {
188 pub auth: Sensitive<String>,
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,
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,
206 pub auth: Sensitive<String>,
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>,
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>,
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"))]
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,
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>,