3 schema::{person, person_alias_1, person_alias_2},
7 use chrono::NaiveDateTime;
8 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
9 use lemmy_apub_lib::traits::{ActorType, ApubObject};
10 use lemmy_utils::LemmyError;
11 use serde::{Deserialize, Serialize};
14 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
15 #[table_name = "person"]
19 pub display_name: Option<String>,
20 pub avatar: Option<DbUrl>,
22 pub published: chrono::NaiveDateTime,
23 pub updated: Option<chrono::NaiveDateTime>,
25 pub bio: Option<String>,
27 pub private_key: Option<String>,
28 pub public_key: Option<String>,
29 pub last_refreshed_at: chrono::NaiveDateTime,
30 pub banner: Option<DbUrl>,
33 pub shared_inbox_url: Option<DbUrl>,
34 pub matrix_user_id: Option<String>,
36 pub bot_account: bool,
39 /// A safe representation of person, without the sensitive info
40 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
41 #[table_name = "person"]
42 pub struct PersonSafe {
45 pub display_name: Option<String>,
46 pub avatar: Option<DbUrl>,
48 pub published: chrono::NaiveDateTime,
49 pub updated: Option<chrono::NaiveDateTime>,
51 pub bio: Option<String>,
53 pub banner: Option<DbUrl>,
56 pub shared_inbox_url: Option<DbUrl>,
57 pub matrix_user_id: Option<String>,
59 pub bot_account: bool,
62 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
63 #[table_name = "person_alias_1"]
64 pub struct PersonAlias1 {
67 pub display_name: Option<String>,
68 pub avatar: Option<DbUrl>,
70 pub published: chrono::NaiveDateTime,
71 pub updated: Option<chrono::NaiveDateTime>,
73 pub bio: Option<String>,
75 pub private_key: Option<String>,
76 pub public_key: Option<String>,
77 pub last_refreshed_at: chrono::NaiveDateTime,
78 pub banner: Option<DbUrl>,
81 pub shared_inbox_url: Option<DbUrl>,
82 pub matrix_user_id: Option<String>,
84 pub bot_account: bool,
87 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
88 #[table_name = "person_alias_1"]
89 pub struct PersonSafeAlias1 {
92 pub display_name: Option<String>,
93 pub avatar: Option<DbUrl>,
95 pub published: chrono::NaiveDateTime,
96 pub updated: Option<chrono::NaiveDateTime>,
98 pub bio: Option<String>,
100 pub banner: Option<DbUrl>,
102 pub inbox_url: DbUrl,
103 pub shared_inbox_url: Option<DbUrl>,
104 pub matrix_user_id: Option<String>,
106 pub bot_account: bool,
109 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
110 #[table_name = "person_alias_2"]
111 pub struct PersonAlias2 {
114 pub display_name: Option<String>,
115 pub avatar: Option<DbUrl>,
117 pub published: chrono::NaiveDateTime,
118 pub updated: Option<chrono::NaiveDateTime>,
120 pub bio: Option<String>,
122 pub private_key: Option<String>,
123 pub public_key: Option<String>,
124 pub last_refreshed_at: chrono::NaiveDateTime,
125 pub banner: Option<DbUrl>,
127 pub inbox_url: DbUrl,
128 pub shared_inbox_url: Option<DbUrl>,
129 pub matrix_user_id: Option<String>,
131 pub bot_account: bool,
134 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
135 #[table_name = "person_alias_1"]
136 pub struct PersonSafeAlias2 {
139 pub display_name: Option<String>,
140 pub avatar: Option<DbUrl>,
142 pub published: chrono::NaiveDateTime,
143 pub updated: Option<chrono::NaiveDateTime>,
145 pub bio: Option<String>,
147 pub banner: Option<DbUrl>,
149 pub inbox_url: DbUrl,
150 pub shared_inbox_url: Option<DbUrl>,
151 pub matrix_user_id: Option<String>,
153 pub bot_account: bool,
156 #[derive(Insertable, AsChangeset, Clone, Default)]
157 #[table_name = "person"]
158 pub struct PersonForm {
160 pub display_name: Option<Option<String>>,
161 pub avatar: Option<Option<DbUrl>>,
162 pub banned: Option<bool>,
163 pub published: Option<chrono::NaiveDateTime>,
164 pub updated: Option<chrono::NaiveDateTime>,
165 pub actor_id: Option<DbUrl>,
166 pub bio: Option<Option<String>>,
167 pub local: Option<bool>,
168 pub private_key: Option<Option<String>>,
169 pub public_key: Option<Option<String>>,
170 pub last_refreshed_at: Option<chrono::NaiveDateTime>,
171 pub banner: Option<Option<DbUrl>>,
172 pub deleted: Option<bool>,
173 pub inbox_url: Option<DbUrl>,
174 pub shared_inbox_url: Option<Option<DbUrl>>,
175 pub matrix_user_id: Option<Option<String>>,
176 pub admin: Option<bool>,
177 pub bot_account: Option<bool>,
180 impl ApubObject for Person {
181 type DataType = PgConnection;
183 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
184 Some(self.last_refreshed_at)
187 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
188 use crate::schema::person::dsl::*;
189 let object_id: DbUrl = object_id.into();
192 .filter(deleted.eq(false))
193 .filter(actor_id.eq(object_id))
199 fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
200 use crate::schema::person::dsl::*;
201 diesel::update(person.find(self.id))
202 .set((deleted.eq(true), updated.eq(naive_now())))
203 .get_result::<Self>(conn)?;
208 impl ActorType for Person {
209 fn is_local(&self) -> bool {
212 fn actor_id(&self) -> Url {
213 self.actor_id.to_owned().into_inner()
215 fn name(&self) -> String {
219 fn public_key(&self) -> Option<String> {
220 self.public_key.to_owned()
223 fn private_key(&self) -> Option<String> {
224 self.private_key.to_owned()
227 fn inbox_url(&self) -> Url {
228 self.inbox_url.clone().into()
231 fn shared_inbox_url(&self) -> Option<Url> {
232 self.shared_inbox_url.clone().map(|s| s.into_inner())