1 #[cfg(feature = "full")]
2 use crate::schema::{community, community_follower, community_moderator, community_person_ban};
4 newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
5 source::placeholder_apub_url,
7 use serde::{Deserialize, Serialize};
8 use serde_with::skip_serializing_none;
9 #[cfg(feature = "full")]
11 use typed_builder::TypedBuilder;
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))]
19 pub struct Community {
22 /// A longer title, that can contain other characters, and doesn't have to be unique.
24 /// A sidebar / markdown description.
25 pub description: Option<String>,
26 /// Whether the community is removed by a mod.
28 pub published: chrono::NaiveDateTime,
29 pub updated: Option<chrono::NaiveDateTime>,
30 /// Whether the community has been deleted by its creator.
32 /// Whether its an NSFW community.
34 /// The federated actor_id.
36 /// Whether the community is local.
39 pub private_key: Option<String>,
41 pub public_key: String,
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")]
53 pub shared_inbox_url: Option<DbUrl>,
54 /// Whether the community is hidden.
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
61 pub moderators_url: Option<DbUrl>,
62 /// Url where featured posts collection is served over Activitypub
64 pub featured_url: Option<DbUrl>,
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 {
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>,
97 pub instance_id: InstanceId,
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>,
127 #[derive(PartialEq, Eq, Debug)]
128 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
131 diesel(belongs_to(crate::source::community::Community))
133 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
134 pub struct CommunityModerator {
136 pub community_id: CommunityId,
137 pub person_id: PersonId,
138 pub published: chrono::NaiveDateTime,
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,
149 #[derive(PartialEq, Eq, Debug)]
150 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
153 diesel(belongs_to(crate::source::community::Community))
155 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
156 pub struct CommunityPersonBan {
158 pub community_id: CommunityId,
159 pub person_id: PersonId,
160 pub published: chrono::NaiveDateTime,
161 pub expires: Option<chrono::NaiveDateTime>,
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>>,
173 #[derive(PartialEq, Eq, Debug)]
174 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
177 diesel(belongs_to(crate::source::community::Community))
179 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
180 pub struct CommunityFollower {
182 pub community_id: CommunityId,
183 pub person_id: PersonId,
184 pub published: chrono::NaiveDateTime,
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,