use lemmy_db_schema::{ newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId}, ListingType, PostFeatureType, PostSortType, }; use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Create a post. pub struct CreatePost { pub name: String, pub community_id: CommunityId, pub url: Option, /// An optional body for the post in markdown. pub body: Option, /// An optional alt_text, usable for image posts. pub alt_text: Option, /// A honeypot to catch bots. Should be None. pub honeypot: Option, pub nsfw: Option, pub language_id: Option, /// Instead of fetching a thumbnail, use a custom one. pub custom_thumbnail: Option, /// Time when this post should be scheduled. Null means publish immediately. pub scheduled_publish_time: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct PostResponse { pub post_view: PostView, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Get a post. Needs either the post id, or comment_id. pub struct GetPost { pub id: Option, pub comment_id: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The post response. pub struct GetPostResponse { pub post_view: PostView, pub community_view: CommunityView, pub moderators: Vec, /// A list of cross-posts, or other times / communities this link has been posted to. pub cross_posts: Vec, } #[skip_serializing_none] #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Get a list of posts. pub struct GetPosts { pub type_: Option, pub sort: Option, /// DEPRECATED, use page_cursor pub page: Option, pub limit: Option, pub community_id: Option, pub community_name: Option, pub saved_only: Option, pub liked_only: Option, pub disliked_only: Option, pub show_hidden: Option, /// If true, then show the read posts (even if your user setting is to hide them) pub show_read: Option, /// If true, then show the nsfw posts (even if your user setting is to hide them) pub show_nsfw: Option, /// If true, then only show posts with no comments pub no_comments_only: Option, pub page_cursor: Option, } #[skip_serializing_none] #[derive(Serialize, Deserialize, Debug, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The post list response. pub struct GetPostsResponse { pub posts: Vec, /// the pagination cursor to use to fetch the next page pub next_page: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Like a post. pub struct CreatePostLike { pub post_id: PostId, /// Score must be -1, 0, or 1. pub score: i16, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Edit a post. pub struct EditPost { pub post_id: PostId, pub name: Option, pub url: Option, /// An optional body for the post in markdown. pub body: Option, /// An optional alt_text, usable for image posts. pub alt_text: Option, pub nsfw: Option, pub language_id: Option, /// Instead of fetching a thumbnail, use a custom one. pub custom_thumbnail: Option, /// Time when this post should be scheduled. Null means publish immediately. pub scheduled_publish_time: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Delete a post. pub struct DeletePost { pub post_id: PostId, pub deleted: bool, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Remove a post (only doable by mods). pub struct RemovePost { pub post_id: PostId, pub removed: bool, pub reason: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Mark a post as read. pub struct MarkPostAsRead { pub post_ids: Vec, pub read: bool, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Hide a post from list views pub struct HidePost { pub post_ids: Vec, pub hide: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Lock a post (prevent new comments). pub struct LockPost { pub post_id: PostId, pub locked: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Feature a post (stickies / pins to the top). pub struct FeaturePost { pub post_id: PostId, pub featured: bool, pub feature_type: PostFeatureType, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Save / bookmark a post. pub struct SavePost { pub post_id: PostId, pub save: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Create a post report. pub struct CreatePostReport { pub post_id: PostId, pub reason: String, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The post report response. pub struct PostReportResponse { pub post_report_view: PostReportView, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Resolve a post report (mods only). pub struct ResolvePostReport { pub report_id: PostReportId, pub resolved: bool, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// List post reports. pub struct ListPostReports { pub page: Option, pub limit: Option, /// Only shows the unresolved reports pub unresolved_only: Option, /// if no community is given, it returns reports for all communities moderated by the auth user pub community_id: Option, pub post_id: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The post reports response. pub struct ListPostReportsResponse { pub post_reports: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Get metadata for a given site. pub struct GetSiteMetadata { pub url: String, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The site metadata response. pub struct GetSiteMetadataResponse { pub metadata: LinkMetadata, } #[skip_serializing_none] #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, Default, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Site metadata, from its opengraph tags. pub struct LinkMetadata { #[serde(flatten)] pub opengraph_data: OpenGraphData, pub content_type: Option, } #[skip_serializing_none] #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, Default, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Site metadata, from its opengraph tags. pub struct OpenGraphData { pub title: Option, pub description: Option, pub(crate) image: Option, pub embed_video_url: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// List post likes. Admins-only. pub struct ListPostLikes { pub post_id: PostId, pub page: Option, pub limit: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The post likes response pub struct ListPostLikesResponse { pub post_likes: Vec, }