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