Skip to content

Commit

Permalink
Adding comments to all API related types. Fixes #2846
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed May 9, 2023
1 parent 88a0d2f commit 784a3b3
Show file tree
Hide file tree
Showing 36 changed files with 484 additions and 41 deletions.
19 changes: 18 additions & 1 deletion crates/api_common/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a comment.
pub struct CreateComment {
pub content: String,
pub post_id: PostId,
pub parent_id: Option<CommentId>,
pub language_id: Option<LanguageId>,
/// An optional front-end ID, to help UIs determine where the comment should go.
pub form_id: Option<String>,
pub auth: Sensitive<String>,
}
Expand All @@ -27,6 +29,7 @@ pub struct CreateComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Fetch an individual comment.
pub struct GetComment {
pub id: CommentId,
pub auth: Option<Sensitive<String>>,
Expand All @@ -36,6 +39,7 @@ pub struct GetComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Edit a comment.
pub struct EditComment {
pub comment_id: CommentId,
pub content: Option<String>,
Expand All @@ -48,6 +52,7 @@ pub struct EditComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Distinguish a comment (IE speak as moderator).
pub struct DistinguishComment {
pub comment_id: CommentId,
pub distinguished: bool,
Expand All @@ -58,6 +63,7 @@ pub struct DistinguishComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Delete your own comment.
pub struct DeleteComment {
pub comment_id: CommentId,
pub deleted: bool,
Expand All @@ -68,6 +74,7 @@ pub struct DeleteComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Remove a comment (only doable by mods).
pub struct RemoveComment {
pub comment_id: CommentId,
pub removed: bool,
Expand All @@ -78,6 +85,7 @@ pub struct RemoveComment {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Save / bookmark a comment.
pub struct SaveComment {
pub comment_id: CommentId,
pub save: bool,
Expand All @@ -88,6 +96,7 @@ pub struct SaveComment {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A comment response.
pub struct CommentResponse {
pub comment_view: CommentView,
pub recipient_ids: Vec<LocalUserId>,
Expand All @@ -98,8 +107,10 @@ pub struct CommentResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Like a comment.
pub struct CreateCommentLike {
pub comment_id: CommentId,
/// Must be -1, 0, or 1 .
pub score: i16,
pub auth: Sensitive<String>,
}
Expand All @@ -108,6 +119,7 @@ pub struct CreateCommentLike {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Get a list of comments.
pub struct GetComments {
pub type_: Option<ListingType>,
pub sort: Option<CommentSortType>,
Expand All @@ -125,13 +137,15 @@ pub struct GetComments {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment list response.
pub struct GetCommentsResponse {
pub comments: Vec<CommentView>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Report a comment.
pub struct CreateCommentReport {
pub comment_id: CommentId,
pub reason: String,
Expand All @@ -141,13 +155,15 @@ pub struct CreateCommentReport {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report response.
pub struct CommentReportResponse {
pub comment_report_view: CommentReportView,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a comment report (only doable by mods).
pub struct ResolveCommentReport {
pub report_id: CommentReportId,
pub resolved: bool,
Expand All @@ -158,9 +174,9 @@ pub struct ResolveCommentReport {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List comment reports.
pub struct ListCommentReports {
pub page: Option<i64>,

pub limit: Option<i64>,
/// Only shows the unresolved reports
pub unresolved_only: Option<bool>,
Expand All @@ -172,6 +188,7 @@ pub struct ListCommentReports {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report list response.
pub struct ListCommentReportsResponse {
pub comment_reports: Vec<CommentReportView>,
}
32 changes: 32 additions & 0 deletions crates/api_common/src/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Get a community. Must provide either an id, or a name.
pub struct GetCommunity {
pub id: Option<CommunityId>,
/// Example: star_trek , or [email protected]
Expand All @@ -26,6 +27,7 @@ pub struct GetCommunity {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The community response.
pub struct GetCommunityResponse {
pub community_view: CommunityView,
pub site: Option<Site>,
Expand All @@ -41,13 +43,21 @@ pub struct GetCommunityResponse {
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
/// Create a community.
pub struct CreateCommunity {
/// The unique name.
pub name: String,
/// A longer title.
pub title: String,
/// A longer sidebar, or description of your community, in markdown.
pub description: Option<String>,
/// An icon URL.
pub icon: Option<String>,
/// A banner URL.
pub banner: Option<String>,
/// Whether its an NSFW community.
pub nsfw: Option<bool>,
/// Whether to restrict posting only to moderators.
pub posting_restricted_to_mods: Option<bool>,
pub discussion_languages: Option<Vec<LanguageId>>,
pub auth: Sensitive<String>,
Expand All @@ -56,6 +66,7 @@ pub struct CreateCommunity {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A simple community response.
pub struct CommunityResponse {
pub community_view: CommunityView,
pub discussion_languages: Vec<LanguageId>,
Expand All @@ -65,6 +76,7 @@ pub struct CommunityResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a list of communities.
pub struct ListCommunities {
pub type_: Option<ListingType>,
pub sort: Option<SortType>,
Expand All @@ -76,6 +88,7 @@ pub struct ListCommunities {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for listing communities.
pub struct ListCommunitiesResponse {
pub communities: Vec<CommunityView>,
}
Expand All @@ -84,6 +97,7 @@ pub struct ListCommunitiesResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Ban a user from a community.
pub struct BanFromCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
Expand All @@ -97,6 +111,7 @@ pub struct BanFromCommunity {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for banning a user from a community.
pub struct BanFromCommunityResponse {
pub person_view: PersonView,
pub banned: bool,
Expand All @@ -105,6 +120,7 @@ pub struct BanFromCommunityResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Add a moderator to a community.
pub struct AddModToCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
Expand All @@ -115,6 +131,7 @@ pub struct AddModToCommunity {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response of adding a moderator to a community.
pub struct AddModToCommunityResponse {
pub moderators: Vec<CommunityModeratorView>,
}
Expand All @@ -123,13 +140,20 @@ pub struct AddModToCommunityResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Edit a community.
pub struct EditCommunity {
pub community_id: CommunityId,
/// A longer title.
pub title: Option<String>,
/// A longer sidebar, or description of your community, in markdown.
pub description: Option<String>,
/// An icon URL.
pub icon: Option<String>,
/// A banner URL.
pub banner: Option<String>,
/// Whether its an NSFW community.
pub nsfw: Option<bool>,
/// Whether to restrict posting only to moderators.
pub posting_restricted_to_mods: Option<bool>,
pub discussion_languages: Option<Vec<LanguageId>>,
pub auth: Sensitive<String>,
Expand All @@ -139,6 +163,8 @@ pub struct EditCommunity {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Hide a community from the main view.
// TODO this should really be a part of edit community. And why does it contain a reason, that should be in the mod tables.
pub struct HideCommunity {
pub community_id: CommunityId,
pub hidden: bool,
Expand All @@ -150,6 +176,7 @@ pub struct HideCommunity {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Delete your own community.
pub struct DeleteCommunity {
pub community_id: CommunityId,
pub deleted: bool,
Expand All @@ -160,6 +187,7 @@ pub struct DeleteCommunity {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Remove a community (only doable by moderators).
pub struct RemoveCommunity {
pub community_id: CommunityId,
pub removed: bool,
Expand All @@ -171,6 +199,7 @@ pub struct RemoveCommunity {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Follow / subscribe to a community.
pub struct FollowCommunity {
pub community_id: CommunityId,
pub follow: bool,
Expand All @@ -180,6 +209,7 @@ pub struct FollowCommunity {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Block a community.
pub struct BlockCommunity {
pub community_id: CommunityId,
pub block: bool,
Expand All @@ -190,6 +220,7 @@ pub struct BlockCommunity {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The block community response.
pub struct BlockCommunityResponse {
pub community_view: CommunityView,
pub blocked: bool,
Expand All @@ -198,6 +229,7 @@ pub struct BlockCommunityResponse {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Transfer a community to a new owner.
pub struct TransferCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
Expand Down
5 changes: 5 additions & 0 deletions crates/api_common/src/custom_emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use url::Url;
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a custom emoji.
pub struct CreateCustomEmoji {
pub category: String,
pub shortcode: String,
Expand All @@ -22,6 +23,7 @@ pub struct CreateCustomEmoji {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Edit a custom emoji.
pub struct EditCustomEmoji {
pub id: CustomEmojiId,
pub category: String,
Expand All @@ -35,6 +37,7 @@ pub struct EditCustomEmoji {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Delete a custom emoji.
pub struct DeleteCustomEmoji {
pub id: CustomEmojiId,
pub auth: Sensitive<String>,
Expand All @@ -43,6 +46,7 @@ pub struct DeleteCustomEmoji {
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for deleting a custom emoji.
pub struct DeleteCustomEmojiResponse {
pub id: CustomEmojiId,
pub success: bool,
Expand All @@ -51,6 +55,7 @@ pub struct DeleteCustomEmojiResponse {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A response for a custom emoji.
pub struct CustomEmojiResponse {
pub custom_emoji: CustomEmojiView,
}
Loading

0 comments on commit 784a3b3

Please sign in to comment.