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")]
8 use typed_builder::TypedBuilder;
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))]
16 pub struct Community {
19 /// A longer title, that can contain other characters, and doesn't have to be unique.
21 /// A sidebar / markdown description.
22 pub description: Option<String>,
23 /// Whether the community is removed by a mod.
25 pub published: chrono::NaiveDateTime,
26 pub updated: Option<chrono::NaiveDateTime>,
27 /// Whether the community has been deleted by its creator.
29 /// Whether its an NSFW community.
31 /// The federated actor_id.
33 /// Whether the community is local.
36 pub private_key: Option<String>,
38 pub public_key: String,
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)]
50 pub shared_inbox_url: Option<DbUrl>,
51 /// Whether the community is hidden.
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
58 pub moderators_url: Option<DbUrl>,
59 /// Url where featured posts collection is served over Activitypub
61 pub featured_url: Option<DbUrl>,
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 {
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>,
94 pub instance_id: InstanceId,
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>,
125 #[derive(PartialEq, Eq, Debug)]
126 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
129 diesel(belongs_to(crate::source::community::Community))
131 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
132 pub struct CommunityModerator {
134 pub community_id: CommunityId,
135 pub person_id: PersonId,
136 pub published: chrono::NaiveDateTime,
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,
147 #[derive(PartialEq, Eq, Debug)]
148 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
151 diesel(belongs_to(crate::source::community::Community))
153 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
154 pub struct CommunityPersonBan {
156 pub community_id: CommunityId,
157 pub person_id: PersonId,
158 pub published: chrono::NaiveDateTime,
159 pub expires: Option<chrono::NaiveDateTime>,
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>>,
171 #[derive(PartialEq, Eq, Debug)]
172 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
175 diesel(belongs_to(crate::source::community::Community))
177 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
178 pub struct CommunityFollower {
180 pub community_id: CommunityId,
181 pub person_id: PersonId,
182 pub published: chrono::NaiveDateTime,
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,