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