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, 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>,
128 #[derive(PartialEq, Eq, Debug)]
129 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
132 diesel(belongs_to(crate::source::community::Community))
134 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
135 pub struct CommunityModerator {
137 pub community_id: CommunityId,
138 pub person_id: PersonId,
139 pub published: chrono::NaiveDateTime,
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,
150 #[derive(PartialEq, Eq, Debug)]
151 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
154 diesel(belongs_to(crate::source::community::Community))
156 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
157 pub struct CommunityPersonBan {
159 pub community_id: CommunityId,
160 pub person_id: PersonId,
161 pub published: chrono::NaiveDateTime,
162 pub expires: Option<chrono::NaiveDateTime>,
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>>,
174 #[derive(PartialEq, Eq, Debug)]
175 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
178 diesel(belongs_to(crate::source::community::Community))
180 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
181 pub struct CommunityFollower {
183 pub community_id: CommunityId,
184 pub person_id: PersonId,
185 pub published: chrono::NaiveDateTime,
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,