]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
implement language tags for site/community in db and api (#2434)
[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 auth: Sensitive<String>,
41 }
42
43 #[derive(Debug, Serialize, Deserialize, Clone)]
44 pub struct CommunityResponse {
45   pub community_view: CommunityView,
46 }
47
48 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
49 pub struct ListCommunities {
50   pub type_: Option<ListingType>,
51   pub sort: Option<SortType>,
52   pub page: Option<i64>,
53   pub limit: Option<i64>,
54   pub auth: Option<Sensitive<String>>,
55 }
56
57 #[derive(Debug, Serialize, Deserialize, Clone)]
58 pub struct ListCommunitiesResponse {
59   pub communities: Vec<CommunityView>,
60 }
61
62 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
63 pub struct BanFromCommunity {
64   pub community_id: CommunityId,
65   pub person_id: PersonId,
66   pub ban: bool,
67   pub remove_data: Option<bool>,
68   pub reason: Option<String>,
69   pub expires: Option<i64>,
70   pub auth: Sensitive<String>,
71 }
72
73 #[derive(Debug, Serialize, Deserialize, Clone)]
74 pub struct BanFromCommunityResponse {
75   pub person_view: PersonViewSafe,
76   pub banned: bool,
77 }
78
79 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
80 pub struct AddModToCommunity {
81   pub community_id: CommunityId,
82   pub person_id: PersonId,
83   pub added: bool,
84   pub auth: Sensitive<String>,
85 }
86
87 #[derive(Debug, Serialize, Deserialize, Clone)]
88 pub struct AddModToCommunityResponse {
89   pub moderators: Vec<CommunityModeratorView>,
90 }
91
92 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
93 pub struct EditCommunity {
94   pub community_id: CommunityId,
95   pub title: Option<String>,
96   pub description: Option<String>,
97   pub icon: Option<String>,
98   pub banner: Option<String>,
99   pub nsfw: Option<bool>,
100   pub posting_restricted_to_mods: Option<bool>,
101   pub discussion_languages: Option<Vec<LanguageId>>,
102   pub auth: Sensitive<String>,
103 }
104
105 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
106 pub struct HideCommunity {
107   pub community_id: CommunityId,
108   pub hidden: bool,
109   pub reason: Option<String>,
110   pub auth: Sensitive<String>,
111 }
112
113 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
114 pub struct DeleteCommunity {
115   pub community_id: CommunityId,
116   pub deleted: bool,
117   pub auth: Sensitive<String>,
118 }
119
120 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
121 pub struct RemoveCommunity {
122   pub community_id: CommunityId,
123   pub removed: bool,
124   pub reason: Option<String>,
125   pub expires: Option<i64>,
126   pub auth: Sensitive<String>,
127 }
128
129 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
130 pub struct FollowCommunity {
131   pub community_id: CommunityId,
132   pub follow: bool,
133   pub auth: Sensitive<String>,
134 }
135
136 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
137 pub struct BlockCommunity {
138   pub community_id: CommunityId,
139   pub block: bool,
140   pub auth: Sensitive<String>,
141 }
142
143 #[derive(Debug, Serialize, Deserialize, Clone)]
144 pub struct BlockCommunityResponse {
145   pub community_view: CommunityView,
146   pub blocked: bool,
147 }
148
149 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
150 pub struct TransferCommunity {
151   pub community_id: CommunityId,
152   pub person_id: PersonId,
153   pub auth: Sensitive<String>,
154 }