lemmy_api_common/
post.rs

1use lemmy_db_schema::{
2  newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
3  ListingType,
4  PostFeatureType,
5  SortType,
6};
7use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView};
8use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
9use serde::{Deserialize, Serialize};
10use serde_with::skip_serializing_none;
11#[cfg(feature = "full")]
12use ts_rs::TS;
13
14#[skip_serializing_none]
15#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
16#[cfg_attr(feature = "full", derive(TS))]
17#[cfg_attr(feature = "full", ts(export))]
18/// Create a post.
19pub struct CreatePost {
20  pub name: String,
21  pub community_id: CommunityId,
22  pub url: Option<String>,
23  /// An optional body for the post in markdown.
24  pub body: Option<String>,
25  /// An optional alt_text, usable for image posts.
26  pub alt_text: Option<String>,
27  /// A honeypot to catch bots. Should be None.
28  pub honeypot: Option<String>,
29  pub nsfw: Option<bool>,
30  pub language_id: Option<LanguageId>,
31  /// Instead of fetching a thumbnail, use a custom one.
32  pub custom_thumbnail: Option<String>,
33}
34
35#[derive(Debug, Serialize, Deserialize, Clone)]
36#[cfg_attr(feature = "full", derive(TS))]
37#[cfg_attr(feature = "full", ts(export))]
38pub struct PostResponse {
39  pub post_view: PostView,
40}
41
42#[skip_serializing_none]
43#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
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.
47pub struct GetPost {
48  pub id: Option<PostId>,
49  pub comment_id: Option<CommentId>,
50}
51
52#[skip_serializing_none]
53#[derive(Debug, Serialize, Deserialize, Clone)]
54#[cfg_attr(feature = "full", derive(TS))]
55#[cfg_attr(feature = "full", ts(export))]
56/// The post response.
57pub 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, PartialEq, Eq, Hash)]
67#[cfg_attr(feature = "full", derive(TS))]
68#[cfg_attr(feature = "full", ts(export))]
69/// Get a list of posts.
70pub struct GetPosts {
71  pub type_: Option<ListingType>,
72  pub sort: Option<SortType>,
73  /// DEPRECATED, use page_cursor
74  pub page: Option<i64>,
75  pub limit: Option<i64>,
76  pub community_id: Option<CommunityId>,
77  pub community_name: Option<String>,
78  pub saved_only: Option<bool>,
79  pub liked_only: Option<bool>,
80  pub disliked_only: Option<bool>,
81  pub show_hidden: Option<bool>,
82  /// If true, then show the read posts (even if your user setting is to hide them)
83  pub show_read: Option<bool>,
84  /// If true, then show the nsfw posts (even if your user setting is to hide them)
85  pub show_nsfw: Option<bool>,
86  pub page_cursor: Option<PaginationCursor>,
87}
88
89#[skip_serializing_none]
90#[derive(Serialize, Deserialize, Debug, Clone)]
91#[cfg_attr(feature = "full", derive(TS))]
92#[cfg_attr(feature = "full", ts(export))]
93/// The post list response.
94pub struct GetPostsResponse {
95  pub posts: Vec<PostView>,
96  /// the pagination cursor to use to fetch the next page
97  pub next_page: Option<PaginationCursor>,
98}
99
100#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
101#[cfg_attr(feature = "full", derive(TS))]
102#[cfg_attr(feature = "full", ts(export))]
103/// Like a post.
104pub struct CreatePostLike {
105  pub post_id: PostId,
106  /// Score must be -1, 0, or 1.
107  pub score: i16,
108}
109
110#[skip_serializing_none]
111#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
112#[cfg_attr(feature = "full", derive(TS))]
113#[cfg_attr(feature = "full", ts(export))]
114/// Edit a post.
115pub struct EditPost {
116  pub post_id: PostId,
117  pub name: Option<String>,
118  pub url: Option<String>,
119  /// An optional body for the post in markdown.
120  pub body: Option<String>,
121  /// An optional alt_text, usable for image posts.
122  pub alt_text: Option<String>,
123  pub nsfw: Option<bool>,
124  pub language_id: Option<LanguageId>,
125  /// Instead of fetching a thumbnail, use a custom one.
126  pub custom_thumbnail: Option<String>,
127}
128
129#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
130#[cfg_attr(feature = "full", derive(TS))]
131#[cfg_attr(feature = "full", ts(export))]
132/// Delete a post.
133pub struct DeletePost {
134  pub post_id: PostId,
135  pub deleted: bool,
136}
137
138#[skip_serializing_none]
139#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
140#[cfg_attr(feature = "full", derive(TS))]
141#[cfg_attr(feature = "full", ts(export))]
142/// Remove a post (only doable by mods).
143pub struct RemovePost {
144  pub post_id: PostId,
145  pub removed: bool,
146  pub reason: Option<String>,
147}
148
149#[skip_serializing_none]
150#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
151#[cfg_attr(feature = "full", derive(TS))]
152#[cfg_attr(feature = "full", ts(export))]
153/// Mark a post as read.
154pub struct MarkPostAsRead {
155  pub post_ids: Vec<PostId>,
156  pub read: bool,
157}
158
159#[skip_serializing_none]
160#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
161#[cfg_attr(feature = "full", derive(TS))]
162#[cfg_attr(feature = "full", ts(export))]
163/// Hide a post from list views
164pub struct HidePost {
165  pub post_ids: Vec<PostId>,
166  pub hide: bool,
167}
168
169#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
170#[cfg_attr(feature = "full", derive(TS))]
171#[cfg_attr(feature = "full", ts(export))]
172/// Lock a post (prevent new comments).
173pub struct LockPost {
174  pub post_id: PostId,
175  pub locked: bool,
176}
177
178#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
179#[cfg_attr(feature = "full", derive(TS))]
180#[cfg_attr(feature = "full", ts(export))]
181/// Feature a post (stickies / pins to the top).
182pub struct FeaturePost {
183  pub post_id: PostId,
184  pub featured: bool,
185  pub feature_type: PostFeatureType,
186}
187
188#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
189#[cfg_attr(feature = "full", derive(TS))]
190#[cfg_attr(feature = "full", ts(export))]
191/// Save / bookmark a post.
192pub struct SavePost {
193  pub post_id: PostId,
194  pub save: bool,
195}
196
197#[derive(Debug, Serialize, Deserialize, Clone, Default)]
198#[cfg_attr(feature = "full", derive(TS))]
199#[cfg_attr(feature = "full", ts(export))]
200/// Create a post report.
201pub struct CreatePostReport {
202  pub post_id: PostId,
203  pub reason: String,
204}
205
206#[derive(Debug, Serialize, Deserialize, Clone)]
207#[cfg_attr(feature = "full", derive(TS))]
208#[cfg_attr(feature = "full", ts(export))]
209/// The post report response.
210pub struct PostReportResponse {
211  pub post_report_view: PostReportView,
212}
213
214#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
215#[cfg_attr(feature = "full", derive(TS))]
216#[cfg_attr(feature = "full", ts(export))]
217/// Resolve a post report (mods only).
218pub struct ResolvePostReport {
219  pub report_id: PostReportId,
220  pub resolved: bool,
221}
222
223#[skip_serializing_none]
224#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
225#[cfg_attr(feature = "full", derive(TS))]
226#[cfg_attr(feature = "full", ts(export))]
227/// List post reports.
228pub struct ListPostReports {
229  pub page: Option<i64>,
230  pub limit: Option<i64>,
231  /// Only shows the unresolved reports
232  pub unresolved_only: Option<bool>,
233  /// if no community is given, it returns reports for all communities moderated by the auth user
234  pub community_id: Option<CommunityId>,
235  pub post_id: Option<PostId>,
236}
237
238#[derive(Debug, Serialize, Deserialize, Clone)]
239#[cfg_attr(feature = "full", derive(TS))]
240#[cfg_attr(feature = "full", ts(export))]
241/// The post reports response.
242pub struct ListPostReportsResponse {
243  pub post_reports: Vec<PostReportView>,
244}
245
246#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
247#[cfg_attr(feature = "full", derive(TS))]
248#[cfg_attr(feature = "full", ts(export))]
249/// Get metadata for a given site.
250pub struct GetSiteMetadata {
251  pub url: String,
252}
253
254#[derive(Debug, Serialize, Deserialize, Clone)]
255#[cfg_attr(feature = "full", derive(TS))]
256#[cfg_attr(feature = "full", ts(export))]
257/// The site metadata response.
258pub struct GetSiteMetadataResponse {
259  pub metadata: LinkMetadata,
260}
261
262#[skip_serializing_none]
263#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, Default, Hash)]
264#[cfg_attr(feature = "full", derive(TS))]
265#[cfg_attr(feature = "full", ts(export))]
266/// Site metadata, from its opengraph tags.
267pub struct LinkMetadata {
268  #[serde(flatten)]
269  pub opengraph_data: OpenGraphData,
270  pub content_type: Option<String>,
271}
272
273#[skip_serializing_none]
274#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, Default, Hash)]
275#[cfg_attr(feature = "full", derive(TS))]
276#[cfg_attr(feature = "full", ts(export))]
277/// Site metadata, from its opengraph tags.
278pub struct OpenGraphData {
279  pub title: Option<String>,
280  pub description: Option<String>,
281  pub(crate) image: Option<DbUrl>,
282  pub embed_video_url: Option<DbUrl>,
283}
284
285#[skip_serializing_none]
286#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
287#[cfg_attr(feature = "full", derive(TS))]
288#[cfg_attr(feature = "full", ts(export))]
289/// List post likes. Admins-only.
290pub struct ListPostLikes {
291  pub post_id: PostId,
292  pub page: Option<i64>,
293  pub limit: Option<i64>,
294}
295
296#[derive(Debug, Serialize, Deserialize, Clone)]
297#[cfg_attr(feature = "full", derive(TS))]
298#[cfg_attr(feature = "full", ts(export))]
299/// The post likes response
300pub struct ListPostLikesResponse {
301  pub post_likes: Vec<VoteView>,
302}