]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
Merge pull request #1516 from LemmyNet/move_matrix_and_admin_to_person
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::{
2   schema::{community, community_follower, community_moderator, community_person_ban},
3   CommunityId,
4   DbUrl,
5   PersonId,
6 };
7 use serde::Serialize;
8
9 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
10 #[table_name = "community"]
11 pub struct Community {
12   pub id: CommunityId,
13   pub name: String,
14   pub title: String,
15   pub description: Option<String>,
16   pub creator_id: PersonId,
17   pub removed: bool,
18   pub published: chrono::NaiveDateTime,
19   pub updated: Option<chrono::NaiveDateTime>,
20   pub deleted: bool,
21   pub nsfw: bool,
22   pub actor_id: DbUrl,
23   pub local: bool,
24   pub private_key: Option<String>,
25   pub public_key: Option<String>,
26   pub last_refreshed_at: chrono::NaiveDateTime,
27   pub icon: Option<DbUrl>,
28   pub banner: Option<DbUrl>,
29   pub followers_url: DbUrl,
30   pub inbox_url: DbUrl,
31   pub shared_inbox_url: Option<DbUrl>,
32 }
33
34 /// A safe representation of community, without the sensitive info
35 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
36 #[table_name = "community"]
37 pub struct CommunitySafe {
38   pub id: CommunityId,
39   pub name: String,
40   pub title: String,
41   pub description: Option<String>,
42   pub creator_id: PersonId,
43   pub removed: bool,
44   pub published: chrono::NaiveDateTime,
45   pub updated: Option<chrono::NaiveDateTime>,
46   pub deleted: bool,
47   pub nsfw: bool,
48   pub actor_id: DbUrl,
49   pub local: bool,
50   pub icon: Option<DbUrl>,
51   pub banner: Option<DbUrl>,
52 }
53
54 #[derive(Insertable, AsChangeset, Debug, Default)]
55 #[table_name = "community"]
56 pub struct CommunityForm {
57   pub name: String,
58   pub title: String,
59   pub description: Option<String>,
60   pub creator_id: PersonId,
61   pub removed: Option<bool>,
62   pub published: Option<chrono::NaiveDateTime>,
63   pub updated: Option<chrono::NaiveDateTime>,
64   pub deleted: Option<bool>,
65   pub nsfw: Option<bool>,
66   pub actor_id: Option<DbUrl>,
67   pub local: Option<bool>,
68   pub private_key: Option<String>,
69   pub public_key: Option<String>,
70   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
71   pub icon: Option<Option<DbUrl>>,
72   pub banner: Option<Option<DbUrl>>,
73   pub followers_url: Option<DbUrl>,
74   pub inbox_url: Option<DbUrl>,
75   pub shared_inbox_url: Option<Option<DbUrl>>,
76 }
77
78 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
79 #[belongs_to(Community)]
80 #[table_name = "community_moderator"]
81 pub struct CommunityModerator {
82   pub id: i32,
83   pub community_id: CommunityId,
84   pub person_id: PersonId,
85   pub published: chrono::NaiveDateTime,
86 }
87
88 #[derive(Insertable, AsChangeset, Clone)]
89 #[table_name = "community_moderator"]
90 pub struct CommunityModeratorForm {
91   pub community_id: CommunityId,
92   pub person_id: PersonId,
93 }
94
95 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
96 #[belongs_to(Community)]
97 #[table_name = "community_person_ban"]
98 pub struct CommunityPersonBan {
99   pub id: i32,
100   pub community_id: CommunityId,
101   pub person_id: PersonId,
102   pub published: chrono::NaiveDateTime,
103 }
104
105 #[derive(Insertable, AsChangeset, Clone)]
106 #[table_name = "community_person_ban"]
107 pub struct CommunityPersonBanForm {
108   pub community_id: CommunityId,
109   pub person_id: PersonId,
110 }
111
112 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
113 #[belongs_to(Community)]
114 #[table_name = "community_follower"]
115 pub struct CommunityFollower {
116   pub id: i32,
117   pub community_id: CommunityId,
118   pub person_id: PersonId,
119   pub published: chrono::NaiveDateTime,
120   pub pending: Option<bool>,
121 }
122
123 #[derive(Insertable, AsChangeset, Clone)]
124 #[table_name = "community_follower"]
125 pub struct CommunityFollowerForm {
126   pub community_id: CommunityId,
127   pub person_id: PersonId,
128   pub pending: bool,
129 }