]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/person.rs
1500e89831842614df9dd5154caca4073d365d50
[lemmy.git] / crates / db_schema / src / source / person.rs
1 use crate::newtypes::{DbUrl, InstanceId, PersonId};
2 #[cfg(feature = "full")]
3 use crate::schema::{person, person_follower};
4 use serde::{Deserialize, Serialize};
5 use serde_with::skip_serializing_none;
6 #[cfg(feature = "full")]
7 use ts_rs::TS;
8 use typed_builder::TypedBuilder;
9
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 = person))]
14 #[cfg_attr(feature = "full", ts(export))]
15 /// A person.
16 pub struct Person {
17   pub id: PersonId,
18   pub name: String,
19   /// A shorter display name.
20   pub display_name: Option<String>,
21   /// A URL for an avatar.
22   pub avatar: Option<DbUrl>,
23   /// Whether the person is banned.
24   pub banned: bool,
25   pub published: chrono::NaiveDateTime,
26   pub updated: Option<chrono::NaiveDateTime>,
27   /// The federated actor_id.
28   pub actor_id: DbUrl,
29   /// An optional bio, in markdown.
30   pub bio: Option<String>,
31   /// Whether the person is local to our site.
32   pub local: bool,
33   #[serde(skip)]
34   pub private_key: Option<String>,
35   #[serde(skip)]
36   pub public_key: String,
37   #[serde(skip)]
38   pub last_refreshed_at: chrono::NaiveDateTime,
39   /// A URL for a banner.
40   pub banner: Option<DbUrl>,
41   /// Whether the person is deleted.
42   pub deleted: bool,
43   #[serde(skip_serializing)]
44   pub inbox_url: DbUrl,
45   #[serde(skip)]
46   pub shared_inbox_url: Option<DbUrl>,
47   /// A matrix id, usually given an @person:matrix.org
48   pub matrix_user_id: Option<String>,
49   /// Whether the person is an admin.
50   pub admin: bool,
51   /// Whether the person is a bot account.
52   pub bot_account: bool,
53   /// When their ban, if it exists, expires, if at all.
54   pub ban_expires: Option<chrono::NaiveDateTime>,
55   pub instance_id: InstanceId,
56 }
57
58 #[derive(Clone, TypedBuilder)]
59 #[builder(field_defaults(default))]
60 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
61 #[cfg_attr(feature = "full", diesel(table_name = person))]
62 pub struct PersonInsertForm {
63   #[builder(!default)]
64   pub name: String,
65   #[builder(!default)]
66   pub public_key: String,
67   #[builder(!default)]
68   pub instance_id: InstanceId,
69   pub display_name: Option<String>,
70   pub avatar: Option<DbUrl>,
71   pub banned: Option<bool>,
72   pub published: Option<chrono::NaiveDateTime>,
73   pub updated: Option<chrono::NaiveDateTime>,
74   pub actor_id: Option<DbUrl>,
75   pub bio: Option<String>,
76   pub local: Option<bool>,
77   pub private_key: Option<String>,
78   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
79   pub banner: Option<DbUrl>,
80   pub deleted: Option<bool>,
81   pub inbox_url: Option<DbUrl>,
82   pub shared_inbox_url: Option<DbUrl>,
83   pub matrix_user_id: Option<String>,
84   pub admin: Option<bool>,
85   pub bot_account: Option<bool>,
86   pub ban_expires: Option<chrono::NaiveDateTime>,
87 }
88
89 #[derive(Clone, TypedBuilder)]
90 #[cfg_attr(feature = "full", derive(AsChangeset))]
91 #[cfg_attr(feature = "full", diesel(table_name = person))]
92 #[builder(field_defaults(default))]
93 pub struct PersonUpdateForm {
94   pub display_name: Option<Option<String>>,
95   pub avatar: Option<Option<DbUrl>>,
96   pub banned: Option<bool>,
97   pub updated: Option<Option<chrono::NaiveDateTime>>,
98   pub actor_id: Option<DbUrl>,
99   pub bio: Option<Option<String>>,
100   pub local: Option<bool>,
101   pub public_key: Option<String>,
102   pub private_key: Option<Option<String>>,
103   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
104   pub banner: Option<Option<DbUrl>>,
105   pub deleted: Option<bool>,
106   pub inbox_url: Option<DbUrl>,
107   pub shared_inbox_url: Option<Option<DbUrl>>,
108   pub matrix_user_id: Option<Option<String>>,
109   pub admin: Option<bool>,
110   pub bot_account: Option<bool>,
111   pub ban_expires: Option<Option<chrono::NaiveDateTime>>,
112 }
113
114 #[derive(PartialEq, Eq, Debug)]
115 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
116 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
117 #[cfg_attr(feature = "full", diesel(table_name = person_follower))]
118 pub struct PersonFollower {
119   pub id: i32,
120   pub person_id: PersonId,
121   pub follower_id: PersonId,
122   pub published: chrono::NaiveDateTime,
123   pub pending: bool,
124 }
125
126 #[derive(Clone)]
127 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
128 #[cfg_attr(feature = "full", diesel(table_name = person_follower))]
129 pub struct PersonFollowerForm {
130   pub person_id: PersonId,
131   pub follower_id: PersonId,
132   pub pending: bool,
133 }