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 typed_builder::TypedBuilder;
7 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", diesel(table_name = community))]
10 pub struct Community {
14 pub description: Option<String>,
16 pub published: chrono::NaiveDateTime,
17 pub updated: Option<chrono::NaiveDateTime>,
22 pub private_key: Option<String>,
23 pub public_key: String,
24 pub last_refreshed_at: chrono::NaiveDateTime,
25 pub icon: Option<DbUrl>,
26 pub banner: Option<DbUrl>,
27 pub followers_url: DbUrl,
29 pub shared_inbox_url: Option<DbUrl>,
31 pub posting_restricted_to_mods: bool,
32 pub instance_id: InstanceId,
35 /// A safe representation of community, without the sensitive info
36 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
37 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
38 #[cfg_attr(feature = "full", diesel(table_name = community))]
39 pub struct CommunitySafe {
43 pub description: Option<String>,
45 pub published: chrono::NaiveDateTime,
46 pub updated: Option<chrono::NaiveDateTime>,
51 pub icon: Option<DbUrl>,
52 pub banner: Option<DbUrl>,
54 pub posting_restricted_to_mods: bool,
55 pub instance_id: InstanceId,
58 #[derive(Debug, Clone, TypedBuilder)]
59 #[builder(field_defaults(default))]
60 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
61 #[cfg_attr(feature = "full", diesel(table_name = community))]
62 pub struct CommunityInsertForm {
67 pub description: Option<String>,
68 pub removed: Option<bool>,
69 pub published: Option<chrono::NaiveDateTime>,
70 pub updated: Option<chrono::NaiveDateTime>,
71 pub deleted: Option<bool>,
72 pub nsfw: Option<bool>,
73 pub actor_id: Option<DbUrl>,
74 pub local: Option<bool>,
75 pub private_key: Option<String>,
76 pub public_key: String,
77 pub last_refreshed_at: Option<chrono::NaiveDateTime>,
78 pub icon: Option<DbUrl>,
79 pub banner: Option<DbUrl>,
80 pub followers_url: Option<DbUrl>,
81 pub inbox_url: Option<DbUrl>,
82 pub shared_inbox_url: Option<DbUrl>,
83 pub hidden: Option<bool>,
84 pub posting_restricted_to_mods: Option<bool>,
86 pub instance_id: InstanceId,
89 #[derive(Debug, Clone, TypedBuilder)]
90 #[builder(field_defaults(default))]
91 #[cfg_attr(feature = "full", derive(AsChangeset))]
92 #[cfg_attr(feature = "full", diesel(table_name = community))]
93 pub struct CommunityUpdateForm {
94 pub title: Option<String>,
95 pub description: Option<Option<String>>,
96 pub removed: Option<bool>,
97 pub published: Option<chrono::NaiveDateTime>,
98 pub updated: Option<Option<chrono::NaiveDateTime>>,
99 pub deleted: Option<bool>,
100 pub nsfw: Option<bool>,
101 pub actor_id: Option<DbUrl>,
102 pub local: Option<bool>,
103 pub public_key: Option<String>,
104 pub private_key: Option<Option<String>>,
105 pub last_refreshed_at: Option<chrono::NaiveDateTime>,
106 pub icon: Option<Option<DbUrl>>,
107 pub banner: Option<Option<DbUrl>>,
108 pub followers_url: Option<DbUrl>,
109 pub inbox_url: Option<DbUrl>,
110 pub shared_inbox_url: Option<Option<DbUrl>>,
111 pub hidden: Option<bool>,
112 pub posting_restricted_to_mods: Option<bool>,
115 #[derive(PartialEq, Eq, Debug)]
116 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
119 diesel(belongs_to(crate::source::community::Community))
121 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
122 pub struct CommunityModerator {
124 pub community_id: CommunityId,
125 pub person_id: PersonId,
126 pub published: chrono::NaiveDateTime,
130 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
131 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
132 pub struct CommunityModeratorForm {
133 pub community_id: CommunityId,
134 pub person_id: PersonId,
137 #[derive(PartialEq, Eq, Debug)]
138 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
141 diesel(belongs_to(crate::source::community::Community))
143 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
144 pub struct CommunityPersonBan {
146 pub community_id: CommunityId,
147 pub person_id: PersonId,
148 pub published: chrono::NaiveDateTime,
149 pub expires: Option<chrono::NaiveDateTime>,
153 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
154 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
155 pub struct CommunityPersonBanForm {
156 pub community_id: CommunityId,
157 pub person_id: PersonId,
158 pub expires: Option<Option<chrono::NaiveDateTime>>,
161 #[derive(PartialEq, Eq, Debug)]
162 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
165 diesel(belongs_to(crate::source::community::Community))
167 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
168 pub struct CommunityFollower {
170 pub community_id: CommunityId,
171 pub person_id: PersonId,
172 pub published: chrono::NaiveDateTime,
173 pub pending: Option<bool>,
177 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
178 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
179 pub struct CommunityFollowerForm {
180 pub community_id: CommunityId,
181 pub person_id: PersonId,