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