]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
Split activity table into sent and received parts (fixes #3103) (#3583)
[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, TypedBuilder)]
101 #[builder(field_defaults(default))]
102 #[cfg_attr(feature = "full", derive(AsChangeset))]
103 #[cfg_attr(feature = "full", diesel(table_name = community))]
104 pub struct CommunityUpdateForm {
105   pub title: Option<String>,
106   pub description: Option<Option<String>>,
107   pub removed: Option<bool>,
108   pub published: Option<chrono::NaiveDateTime>,
109   pub updated: Option<Option<chrono::NaiveDateTime>>,
110   pub deleted: Option<bool>,
111   pub nsfw: Option<bool>,
112   pub actor_id: Option<DbUrl>,
113   pub local: Option<bool>,
114   pub public_key: Option<String>,
115   pub private_key: Option<Option<String>>,
116   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
117   pub icon: Option<Option<DbUrl>>,
118   pub banner: Option<Option<DbUrl>>,
119   pub followers_url: Option<DbUrl>,
120   pub inbox_url: Option<DbUrl>,
121   pub shared_inbox_url: Option<Option<DbUrl>>,
122   pub moderators_url: Option<DbUrl>,
123   pub featured_url: Option<DbUrl>,
124   pub hidden: Option<bool>,
125   pub posting_restricted_to_mods: Option<bool>,
126 }
127
128 #[derive(PartialEq, Eq, Debug)]
129 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
130 #[cfg_attr(
131   feature = "full",
132   diesel(belongs_to(crate::source::community::Community))
133 )]
134 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
135 pub struct CommunityModerator {
136   pub id: i32,
137   pub community_id: CommunityId,
138   pub person_id: PersonId,
139   pub published: chrono::NaiveDateTime,
140 }
141
142 #[derive(Clone)]
143 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
144 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
145 pub struct CommunityModeratorForm {
146   pub community_id: CommunityId,
147   pub person_id: PersonId,
148 }
149
150 #[derive(PartialEq, Eq, Debug)]
151 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
152 #[cfg_attr(
153   feature = "full",
154   diesel(belongs_to(crate::source::community::Community))
155 )]
156 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
157 pub struct CommunityPersonBan {
158   pub id: i32,
159   pub community_id: CommunityId,
160   pub person_id: PersonId,
161   pub published: chrono::NaiveDateTime,
162   pub expires: Option<chrono::NaiveDateTime>,
163 }
164
165 #[derive(Clone)]
166 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
167 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
168 pub struct CommunityPersonBanForm {
169   pub community_id: CommunityId,
170   pub person_id: PersonId,
171   pub expires: Option<Option<chrono::NaiveDateTime>>,
172 }
173
174 #[derive(PartialEq, Eq, Debug)]
175 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
176 #[cfg_attr(
177   feature = "full",
178   diesel(belongs_to(crate::source::community::Community))
179 )]
180 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
181 pub struct CommunityFollower {
182   pub id: i32,
183   pub community_id: CommunityId,
184   pub person_id: PersonId,
185   pub published: chrono::NaiveDateTime,
186   pub pending: bool,
187 }
188
189 #[derive(Clone)]
190 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
191 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
192 pub struct CommunityFollowerForm {
193   pub community_id: CommunityId,
194   pub person_id: PersonId,
195   pub pending: bool,
196 }