2 schema::{community, community_follower, community_moderator, community_person_ban},
7 use chrono::NaiveDateTime;
8 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
9 use lemmy_apub_lib::traits::{ActorType, ApubObject};
10 use lemmy_utils::LemmyError;
14 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
15 #[table_name = "community"]
16 pub struct Community {
20 pub description: Option<String>,
22 pub published: chrono::NaiveDateTime,
23 pub updated: Option<chrono::NaiveDateTime>,
28 pub private_key: Option<String>,
29 pub public_key: Option<String>,
30 pub last_refreshed_at: chrono::NaiveDateTime,
31 pub icon: Option<DbUrl>,
32 pub banner: Option<DbUrl>,
33 pub followers_url: DbUrl,
35 pub shared_inbox_url: Option<DbUrl>,
38 /// A safe representation of community, without the sensitive info
39 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
40 #[table_name = "community"]
41 pub struct CommunitySafe {
45 pub description: Option<String>,
47 pub published: chrono::NaiveDateTime,
48 pub updated: Option<chrono::NaiveDateTime>,
53 pub icon: Option<DbUrl>,
54 pub banner: Option<DbUrl>,
57 #[derive(Insertable, AsChangeset, Debug, Default)]
58 #[table_name = "community"]
59 pub struct CommunityForm {
62 pub description: Option<String>,
63 pub removed: Option<bool>,
64 pub published: Option<chrono::NaiveDateTime>,
65 pub updated: Option<chrono::NaiveDateTime>,
66 pub deleted: Option<bool>,
67 pub nsfw: Option<bool>,
68 pub actor_id: Option<DbUrl>,
69 pub local: Option<bool>,
70 pub private_key: Option<String>,
71 pub public_key: Option<String>,
72 pub last_refreshed_at: Option<chrono::NaiveDateTime>,
73 pub icon: Option<Option<DbUrl>>,
74 pub banner: Option<Option<DbUrl>>,
75 pub followers_url: Option<DbUrl>,
76 pub inbox_url: Option<DbUrl>,
77 pub shared_inbox_url: Option<Option<DbUrl>>,
80 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
81 #[belongs_to(Community)]
82 #[table_name = "community_moderator"]
83 pub struct CommunityModerator {
85 pub community_id: CommunityId,
86 pub person_id: PersonId,
87 pub published: chrono::NaiveDateTime,
90 #[derive(Insertable, AsChangeset, Clone)]
91 #[table_name = "community_moderator"]
92 pub struct CommunityModeratorForm {
93 pub community_id: CommunityId,
94 pub person_id: PersonId,
97 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
98 #[belongs_to(Community)]
99 #[table_name = "community_person_ban"]
100 pub struct CommunityPersonBan {
102 pub community_id: CommunityId,
103 pub person_id: PersonId,
104 pub published: chrono::NaiveDateTime,
107 #[derive(Insertable, AsChangeset, Clone)]
108 #[table_name = "community_person_ban"]
109 pub struct CommunityPersonBanForm {
110 pub community_id: CommunityId,
111 pub person_id: PersonId,
114 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
115 #[belongs_to(Community)]
116 #[table_name = "community_follower"]
117 pub struct CommunityFollower {
119 pub community_id: CommunityId,
120 pub person_id: PersonId,
121 pub published: chrono::NaiveDateTime,
122 pub pending: Option<bool>,
125 #[derive(Insertable, AsChangeset, Clone)]
126 #[table_name = "community_follower"]
127 pub struct CommunityFollowerForm {
128 pub community_id: CommunityId,
129 pub person_id: PersonId,
133 impl ApubObject for Community {
134 type DataType = PgConnection;
136 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
137 Some(self.last_refreshed_at)
140 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
141 use crate::schema::community::dsl::*;
142 let object_id: DbUrl = object_id.into();
145 .filter(actor_id.eq(object_id))
152 impl ActorType for Community {
153 fn is_local(&self) -> bool {
156 fn actor_id(&self) -> Url {
157 self.actor_id.to_owned().into()
159 fn name(&self) -> String {
162 fn public_key(&self) -> Option<String> {
163 self.public_key.to_owned()
165 fn private_key(&self) -> Option<String> {
166 self.private_key.to_owned()
169 fn inbox_url(&self) -> Url {
170 self.inbox_url.clone().into()
173 fn shared_inbox_url(&self) -> Option<Url> {
174 self.shared_inbox_url.clone().map(|s| s.into_inner())