]> Untitled Git - lemmy.git/blobdiff - crates/api_common/src/community.rs
add new flag to api (#3363)
[lemmy.git] / crates / api_common / src / community.rs
index 129b149adfe17c44d2080f95e84efd3b4cf9aa5d..ff6ed1271a54963793e622e52776e95d9272a2b9 100644 (file)
-use lemmy_db_schema::{CommunityId, PersonId};
-use lemmy_db_views_actor::{
-  community_follower_view::CommunityFollowerView,
-  community_moderator_view::CommunityModeratorView,
-  community_view::CommunityView,
-  person_view::PersonViewSafe,
+use crate::sensitive::Sensitive;
+use lemmy_db_schema::{
+  newtypes::{CommunityId, LanguageId, PersonId},
+  source::site::Site,
+  ListingType,
+  SortType,
 };
+use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
 use serde::{Deserialize, Serialize};
-
-#[derive(Deserialize)]
+use serde_with::skip_serializing_none;
+#[cfg(feature = "full")]
+use ts_rs::TS;
+
+#[skip_serializing_none]
+#[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 star_trek@xyz.tld
   pub name: Option<String>,
-  pub auth: Option<String>,
+  pub auth: Option<Sensitive<String>>,
 }
 
-#[derive(Serialize)]
+#[skip_serializing_none]
+#[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>,
   pub moderators: Vec<CommunityModeratorView>,
-  pub online: usize,
+  pub discussion_languages: Vec<LanguageId>,
 }
 
-#[derive(Deserialize)]
+#[skip_serializing_none]
+#[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>,
-  pub auth: String,
+  /// Whether to restrict posting only to moderators.
+  pub posting_restricted_to_mods: Option<bool>,
+  pub discussion_languages: Option<Vec<LanguageId>>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
+#[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>,
 }
 
-#[derive(Deserialize, Debug)]
+#[skip_serializing_none]
+#[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<String>,
-  pub sort: Option<String>,
+  pub type_: Option<ListingType>,
+  pub sort: Option<SortType>,
+  pub show_nsfw: Option<bool>,
   pub page: Option<i64>,
   pub limit: Option<i64>,
-  pub auth: Option<String>,
+  pub auth: Option<Sensitive<String>>,
 }
 
-#[derive(Serialize, Debug)]
+#[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>,
 }
 
-#[derive(Deserialize, Clone)]
+#[skip_serializing_none]
+#[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,
@@ -59,75 +102,133 @@ pub struct BanFromCommunity {
   pub remove_data: Option<bool>,
   pub reason: Option<String>,
   pub expires: Option<i64>,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
+#[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: PersonViewSafe,
+  pub person_view: PersonView,
   pub banned: bool,
 }
 
-#[derive(Deserialize)]
+#[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,
   pub added: bool,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
+#[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>,
 }
 
-#[derive(Deserialize)]
+#[skip_serializing_none]
+#[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>,
-  pub auth: String,
+  /// Whether to restrict posting only to moderators.
+  pub posting_restricted_to_mods: Option<bool>,
+  pub discussion_languages: Option<Vec<LanguageId>>,
+  pub auth: Sensitive<String>,
+}
+
+#[skip_serializing_none]
+#[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,
+  pub reason: Option<String>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[skip_serializing_none]
+#[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,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[skip_serializing_none]
+#[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,
   pub reason: Option<String>,
   pub expires: Option<i64>,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[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,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
-pub struct GetFollowedCommunities {
-  pub auth: String,
+#[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,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize)]
-pub struct GetFollowedCommunitiesResponse {
-  pub communities: Vec<CommunityFollowerView>,
+#[skip_serializing_none]
+#[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,
 }
 
-#[derive(Deserialize)]
+#[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,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }