use lemmy_db_schema::{ newtypes::{CommunityId, LanguageId, PersonId}, source::site::Site, CommunityVisibility, ListingType, SortType, }; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView}; 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))] /// Get a community. Must provide either an id, or a name. pub struct GetCommunity { pub id: Option, /// Example: star_trek , or star_trek@xyz.tld pub name: Option, } #[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, pub moderators: Vec, pub discussion_languages: Vec, } #[skip_serializing_none] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] /// 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, /// An icon URL. pub icon: Option, /// A banner URL. pub banner: Option, /// Whether its an NSFW community. pub nsfw: Option, /// Whether to restrict posting only to moderators. pub posting_restricted_to_mods: Option, pub discussion_languages: Option>, pub visibility: Option, } #[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, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Fetches a list of communities. pub struct ListCommunities { pub type_: Option, pub sort: Option, pub show_nsfw: Option, pub page: Option, pub limit: Option, } #[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, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[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, pub ban: bool, /// Optionally remove or restore all their data. Useful for new troll accounts. /// If ban is true, then this means remove. If ban is false, it means restore. pub remove_or_restore_data: Option, pub reason: Option, /// A time that the ban will expire, in unix epoch seconds. /// /// An i64 unix timestamp is used for a simpler API client implementation. pub expires: Option, } #[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, } #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[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, } #[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, } #[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 community. pub struct EditCommunity { pub community_id: CommunityId, /// A longer title. pub title: Option, /// A longer sidebar, or description of your community, in markdown. pub description: Option, /// An icon URL. pub icon: Option, /// A banner URL. pub banner: Option, /// Whether its an NSFW community. pub nsfw: Option, /// Whether to restrict posting only to moderators. pub posting_restricted_to_mods: Option, pub discussion_languages: Option>, pub visibility: 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))] /// Hide a community from the main view. pub struct HideCommunity { pub community_id: CommunityId, pub hidden: 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))] /// Delete your own community. pub struct DeleteCommunity { pub community_id: CommunityId, 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 community (only doable by moderators). pub struct RemoveCommunity { pub community_id: CommunityId, pub removed: bool, pub reason: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[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, } #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[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, } #[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(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[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, }