]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
Fixing missing forms, incorrect user discussion_languages (#2580)
[lemmy.git] / crates / api_common / src / community.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommunityId, LanguageId, PersonId},
4   source::site::Site,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
9 use serde::{Deserialize, Serialize};
10
11 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
12 pub struct GetCommunity {
13   pub id: Option<CommunityId>,
14   /// Example: star_trek , or star_trek@xyz.tld
15   pub name: Option<String>,
16   pub auth: Option<Sensitive<String>>,
17 }
18
19 #[derive(Debug, Serialize, Deserialize, Clone)]
20 pub struct GetCommunityResponse {
21   pub community_view: CommunityView,
22   pub site: Option<Site>,
23   pub moderators: Vec<CommunityModeratorView>,
24   pub online: usize,
25   pub discussion_languages: Vec<LanguageId>,
26   /// Default language used for new posts if none is specified, generated based on community and
27   /// user languages.
28   pub default_post_language: Option<LanguageId>,
29 }
30
31 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
32 pub struct CreateCommunity {
33   pub name: String,
34   pub title: String,
35   pub description: Option<String>,
36   pub icon: Option<String>,
37   pub banner: Option<String>,
38   pub nsfw: Option<bool>,
39   pub posting_restricted_to_mods: Option<bool>,
40   pub discussion_languages: Option<Vec<LanguageId>>,
41   pub auth: Sensitive<String>,
42 }
43
44 #[derive(Debug, Serialize, Deserialize, Clone)]
45 pub struct CommunityResponse {
46   pub community_view: CommunityView,
47   pub discussion_languages: Vec<LanguageId>,
48 }
49
50 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
51 pub struct ListCommunities {
52   pub type_: Option<ListingType>,
53   pub sort: Option<SortType>,
54   pub page: Option<i64>,
55   pub limit: Option<i64>,
56   pub auth: Option<Sensitive<String>>,
57 }
58
59 #[derive(Debug, Serialize, Deserialize, Clone)]
60 pub struct ListCommunitiesResponse {
61   pub communities: Vec<CommunityView>,
62 }
63
64 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
65 pub struct BanFromCommunity {
66   pub community_id: CommunityId,
67   pub person_id: PersonId,
68   pub ban: bool,
69   pub remove_data: Option<bool>,
70   pub reason: Option<String>,
71   pub expires: Option<i64>,
72   pub auth: Sensitive<String>,
73 }
74
75 #[derive(Debug, Serialize, Deserialize, Clone)]
76 pub struct BanFromCommunityResponse {
77   pub person_view: PersonViewSafe,
78   pub banned: bool,
79 }
80
81 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
82 pub struct AddModToCommunity {
83   pub community_id: CommunityId,
84   pub person_id: PersonId,
85   pub added: bool,
86   pub auth: Sensitive<String>,
87 }
88
89 #[derive(Debug, Serialize, Deserialize, Clone)]
90 pub struct AddModToCommunityResponse {
91   pub moderators: Vec<CommunityModeratorView>,
92 }
93
94 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
95 pub struct EditCommunity {
96   pub community_id: CommunityId,
97   pub title: Option<String>,
98   pub description: Option<String>,
99   pub icon: Option<String>,
100   pub banner: Option<String>,
101   pub nsfw: Option<bool>,
102   pub posting_restricted_to_mods: Option<bool>,
103   pub discussion_languages: Option<Vec<LanguageId>>,
104   pub auth: Sensitive<String>,
105 }
106
107 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
108 pub struct HideCommunity {
109   pub community_id: CommunityId,
110   pub hidden: bool,
111   pub reason: Option<String>,
112   pub auth: Sensitive<String>,
113 }
114
115 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
116 pub struct DeleteCommunity {
117   pub community_id: CommunityId,
118   pub deleted: bool,
119   pub auth: Sensitive<String>,
120 }
121
122 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
123 pub struct RemoveCommunity {
124   pub community_id: CommunityId,
125   pub removed: bool,
126   pub reason: Option<String>,
127   pub expires: Option<i64>,
128   pub auth: Sensitive<String>,
129 }
130
131 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
132 pub struct FollowCommunity {
133   pub community_id: CommunityId,
134   pub follow: bool,
135   pub auth: Sensitive<String>,
136 }
137
138 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
139 pub struct BlockCommunity {
140   pub community_id: CommunityId,
141   pub block: bool,
142   pub auth: Sensitive<String>,
143 }
144
145 #[derive(Debug, Serialize, Deserialize, Clone)]
146 pub struct BlockCommunityResponse {
147   pub community_view: CommunityView,
148   pub blocked: bool,
149 }
150
151 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
152 pub struct TransferCommunity {
153   pub community_id: CommunityId,
154   pub person_id: PersonId,
155   pub auth: Sensitive<String>,
156 }