]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
c24a6459784acc81b0cd3fa35f00f19b2663721f
[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 serde_with::skip_serializing_none;
6 #[cfg(feature = "full")]
7 use ts_rs::TS;
8 use typed_builder::TypedBuilder;
9
10 #[skip_serializing_none]
11 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
12 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
13 #[cfg_attr(feature = "full", diesel(table_name = community))]
14 #[cfg_attr(feature = "full", ts(export))]
15 /// A community.
16 pub struct Community {
17   pub id: CommunityId,
18   pub name: String,
19   /// A longer title, that can contain other characters, and doesn't have to be unique.
20   pub title: String,
21   /// A sidebar / markdown description.
22   pub description: Option<String>,
23   /// Whether the community is removed by a mod.
24   pub removed: bool,
25   pub published: chrono::NaiveDateTime,
26   pub updated: Option<chrono::NaiveDateTime>,
27   /// Whether the community has been deleted by its creator.
28   pub deleted: bool,
29   /// Whether its an NSFW community.
30   pub nsfw: bool,
31   /// The federated actor_id.
32   pub actor_id: DbUrl,
33   /// Whether the community is local.
34   pub local: bool,
35   #[serde(skip)]
36   pub private_key: Option<String>,
37   #[serde(skip)]
38   pub public_key: String,
39   #[serde(skip)]
40   pub last_refreshed_at: chrono::NaiveDateTime,
41   /// A URL for an icon.
42   pub icon: Option<DbUrl>,
43   /// A URL for a banner.
44   pub banner: Option<DbUrl>,
45   #[serde(skip_serializing)]
46   pub followers_url: DbUrl,
47   #[serde(skip_serializing)]
48   pub inbox_url: DbUrl,
49   #[serde(skip)]
50   pub shared_inbox_url: Option<DbUrl>,
51   /// Whether the community is hidden.
52   pub hidden: bool,
53   /// Whether posting is restricted to mods only.
54   pub posting_restricted_to_mods: bool,
55   pub instance_id: InstanceId,
56   /// Url where moderators collection is served over Activitypub
57   #[serde(skip)]
58   pub moderators_url: Option<DbUrl>,
59   /// Url where featured posts collection is served over Activitypub
60   #[serde(skip)]
61   pub featured_url: Option<DbUrl>,
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 }