]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / db_schema / src / source / community.rs
1 #[cfg(feature = "full")]
2 use crate::schema::{community, community_follower, community_moderator, community_person_ban};
3 use crate::{
4   newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
5   source::placeholder_apub_url,
6 };
7 use serde::{Deserialize, Serialize};
8 use serde_with::skip_serializing_none;
9 #[cfg(feature = "full")]
10 use ts_rs::TS;
11 use typed_builder::TypedBuilder;
12
13 #[skip_serializing_none]
14 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
15 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
16 #[cfg_attr(feature = "full", diesel(table_name = community))]
17 #[cfg_attr(feature = "full", ts(export))]
18 /// A community.
19 pub struct Community {
20   pub id: CommunityId,
21   pub name: String,
22   /// A longer title, that can contain other characters, and doesn't have to be unique.
23   pub title: String,
24   /// A sidebar / markdown description.
25   pub description: Option<String>,
26   /// Whether the community is removed by a mod.
27   pub removed: bool,
28   pub published: chrono::NaiveDateTime,
29   pub updated: Option<chrono::NaiveDateTime>,
30   /// Whether the community has been deleted by its creator.
31   pub deleted: bool,
32   /// Whether its an NSFW community.
33   pub nsfw: bool,
34   /// The federated actor_id.
35   pub actor_id: DbUrl,
36   /// Whether the community is local.
37   pub local: bool,
38   #[serde(skip)]
39   pub private_key: Option<String>,
40   #[serde(skip)]
41   pub public_key: String,
42   #[serde(skip)]
43   pub last_refreshed_at: chrono::NaiveDateTime,
44   /// A URL for an icon.
45   pub icon: Option<DbUrl>,
46   /// A URL for a banner.
47   pub banner: Option<DbUrl>,
48   #[serde(skip, default = "placeholder_apub_url")]
49   pub followers_url: DbUrl,
50   #[serde(skip, default = "placeholder_apub_url")]
51   pub inbox_url: DbUrl,
52   #[serde(skip)]
53   pub shared_inbox_url: Option<DbUrl>,
54   /// Whether the community is hidden.
55   pub hidden: bool,
56   /// Whether posting is restricted to mods only.
57   pub posting_restricted_to_mods: bool,
58   pub instance_id: InstanceId,
59   /// Url where moderators collection is served over Activitypub
60   #[serde(skip)]
61   pub moderators_url: Option<DbUrl>,
62   /// Url where featured posts collection is served over Activitypub
63   #[serde(skip)]
64   pub featured_url: Option<DbUrl>,
65 }
66
67 #[derive(Debug, Clone, TypedBuilder)]
68 #[builder(field_defaults(default))]
69 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
70 #[cfg_attr(feature = "full", diesel(table_name = community))]
71 pub struct CommunityInsertForm {
72   #[builder(!default)]
73   pub name: String,
74   #[builder(!default)]
75   pub title: String,
76   pub description: Option<String>,
77   pub removed: Option<bool>,
78   pub published: Option<chrono::NaiveDateTime>,
79   pub updated: Option<chrono::NaiveDateTime>,
80   pub deleted: Option<bool>,
81   pub nsfw: Option<bool>,
82   pub actor_id: Option<DbUrl>,
83   pub local: Option<bool>,
84   pub private_key: Option<String>,
85   pub public_key: String,
86   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
87   pub icon: Option<DbUrl>,
88   pub banner: Option<DbUrl>,
89   pub followers_url: Option<DbUrl>,
90   pub inbox_url: Option<DbUrl>,
91   pub shared_inbox_url: Option<DbUrl>,
92   pub moderators_url: Option<DbUrl>,
93   pub featured_url: Option<DbUrl>,
94   pub hidden: Option<bool>,
95   pub posting_restricted_to_mods: Option<bool>,
96   #[builder(!default)]
97   pub instance_id: InstanceId,
98 }
99
100 #[derive(Debug, Clone, Default)]
101 #[cfg_attr(feature = "full", derive(AsChangeset))]
102 #[cfg_attr(feature = "full", diesel(table_name = community))]
103 pub struct CommunityUpdateForm {
104   pub title: Option<String>,
105   pub description: Option<Option<String>>,
106   pub removed: Option<bool>,
107   pub published: Option<chrono::NaiveDateTime>,
108   pub updated: Option<Option<chrono::NaiveDateTime>>,
109   pub deleted: Option<bool>,
110   pub nsfw: Option<bool>,
111   pub actor_id: Option<DbUrl>,
112   pub local: Option<bool>,
113   pub public_key: Option<String>,
114   pub private_key: Option<Option<String>>,
115   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
116   pub icon: Option<Option<DbUrl>>,
117   pub banner: Option<Option<DbUrl>>,
118   pub followers_url: Option<DbUrl>,
119   pub inbox_url: Option<DbUrl>,
120   pub shared_inbox_url: Option<Option<DbUrl>>,
121   pub moderators_url: Option<DbUrl>,
122   pub featured_url: Option<DbUrl>,
123   pub hidden: Option<bool>,
124   pub posting_restricted_to_mods: Option<bool>,
125 }
126
127 #[derive(PartialEq, Eq, Debug)]
128 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
129 #[cfg_attr(
130   feature = "full",
131   diesel(belongs_to(crate::source::community::Community))
132 )]
133 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
134 pub struct CommunityModerator {
135   pub id: i32,
136   pub community_id: CommunityId,
137   pub person_id: PersonId,
138   pub published: chrono::NaiveDateTime,
139 }
140
141 #[derive(Clone)]
142 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
143 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
144 pub struct CommunityModeratorForm {
145   pub community_id: CommunityId,
146   pub person_id: PersonId,
147 }
148
149 #[derive(PartialEq, Eq, Debug)]
150 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
151 #[cfg_attr(
152   feature = "full",
153   diesel(belongs_to(crate::source::community::Community))
154 )]
155 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
156 pub struct CommunityPersonBan {
157   pub id: i32,
158   pub community_id: CommunityId,
159   pub person_id: PersonId,
160   pub published: chrono::NaiveDateTime,
161   pub expires: Option<chrono::NaiveDateTime>,
162 }
163
164 #[derive(Clone)]
165 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
166 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
167 pub struct CommunityPersonBanForm {
168   pub community_id: CommunityId,
169   pub person_id: PersonId,
170   pub expires: Option<Option<chrono::NaiveDateTime>>,
171 }
172
173 #[derive(PartialEq, Eq, Debug)]
174 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
175 #[cfg_attr(
176   feature = "full",
177   diesel(belongs_to(crate::source::community::Community))
178 )]
179 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
180 pub struct CommunityFollower {
181   pub id: i32,
182   pub community_id: CommunityId,
183   pub person_id: PersonId,
184   pub published: chrono::NaiveDateTime,
185   pub pending: bool,
186 }
187
188 #[derive(Clone)]
189 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
190 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
191 pub struct CommunityFollowerForm {
192   pub community_id: CommunityId,
193   pub person_id: PersonId,
194   pub pending: bool,
195 }