2 schema::{person, person_alias_1, person_alias_2},
6 use chrono::NaiveDateTime;
7 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
8 use lemmy_apub_lib::traits::{ActorType, ApubObject};
9 use lemmy_utils::LemmyError;
13 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
14 #[table_name = "person"]
18 pub display_name: Option<String>,
19 pub avatar: Option<DbUrl>,
21 pub published: chrono::NaiveDateTime,
22 pub updated: Option<chrono::NaiveDateTime>,
24 pub bio: Option<String>,
26 pub private_key: Option<String>,
27 pub public_key: Option<String>,
28 pub last_refreshed_at: chrono::NaiveDateTime,
29 pub banner: Option<DbUrl>,
32 pub shared_inbox_url: Option<DbUrl>,
33 pub matrix_user_id: Option<String>,
35 pub bot_account: bool,
38 /// A safe representation of person, without the sensitive info
39 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
40 #[table_name = "person"]
41 pub struct PersonSafe {
44 pub display_name: Option<String>,
45 pub avatar: Option<DbUrl>,
47 pub published: chrono::NaiveDateTime,
48 pub updated: Option<chrono::NaiveDateTime>,
50 pub bio: Option<String>,
52 pub banner: Option<DbUrl>,
55 pub shared_inbox_url: Option<DbUrl>,
56 pub matrix_user_id: Option<String>,
58 pub bot_account: bool,
61 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
62 #[table_name = "person_alias_1"]
63 pub struct PersonAlias1 {
66 pub display_name: Option<String>,
67 pub avatar: Option<DbUrl>,
69 pub published: chrono::NaiveDateTime,
70 pub updated: Option<chrono::NaiveDateTime>,
72 pub bio: Option<String>,
74 pub private_key: Option<String>,
75 pub public_key: Option<String>,
76 pub last_refreshed_at: chrono::NaiveDateTime,
77 pub banner: Option<DbUrl>,
80 pub shared_inbox_url: Option<DbUrl>,
81 pub matrix_user_id: Option<String>,
83 pub bot_account: bool,
86 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
87 #[table_name = "person_alias_1"]
88 pub struct PersonSafeAlias1 {
91 pub display_name: Option<String>,
92 pub avatar: Option<DbUrl>,
94 pub published: chrono::NaiveDateTime,
95 pub updated: Option<chrono::NaiveDateTime>,
97 pub bio: Option<String>,
99 pub banner: Option<DbUrl>,
101 pub inbox_url: DbUrl,
102 pub shared_inbox_url: Option<DbUrl>,
103 pub matrix_user_id: Option<String>,
105 pub bot_account: bool,
108 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
109 #[table_name = "person_alias_2"]
110 pub struct PersonAlias2 {
113 pub display_name: Option<String>,
114 pub avatar: Option<DbUrl>,
116 pub published: chrono::NaiveDateTime,
117 pub updated: Option<chrono::NaiveDateTime>,
119 pub bio: Option<String>,
121 pub private_key: Option<String>,
122 pub public_key: Option<String>,
123 pub last_refreshed_at: chrono::NaiveDateTime,
124 pub banner: Option<DbUrl>,
126 pub inbox_url: DbUrl,
127 pub shared_inbox_url: Option<DbUrl>,
128 pub matrix_user_id: Option<String>,
130 pub bot_account: bool,
133 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
134 #[table_name = "person_alias_1"]
135 pub struct PersonSafeAlias2 {
138 pub display_name: Option<String>,
139 pub avatar: Option<DbUrl>,
141 pub published: chrono::NaiveDateTime,
142 pub updated: Option<chrono::NaiveDateTime>,
144 pub bio: Option<String>,
146 pub banner: Option<DbUrl>,
148 pub inbox_url: DbUrl,
149 pub shared_inbox_url: Option<DbUrl>,
150 pub matrix_user_id: Option<String>,
152 pub bot_account: bool,
155 #[derive(Insertable, AsChangeset, Clone, Default)]
156 #[table_name = "person"]
157 pub struct PersonForm {
159 pub display_name: Option<Option<String>>,
160 pub avatar: Option<Option<DbUrl>>,
161 pub banned: Option<bool>,
162 pub published: Option<chrono::NaiveDateTime>,
163 pub updated: Option<chrono::NaiveDateTime>,
164 pub actor_id: Option<DbUrl>,
165 pub bio: Option<Option<String>>,
166 pub local: Option<bool>,
167 pub private_key: Option<Option<String>>,
168 pub public_key: Option<Option<String>>,
169 pub last_refreshed_at: Option<chrono::NaiveDateTime>,
170 pub banner: Option<Option<DbUrl>>,
171 pub deleted: Option<bool>,
172 pub inbox_url: Option<DbUrl>,
173 pub shared_inbox_url: Option<Option<DbUrl>>,
174 pub matrix_user_id: Option<Option<String>>,
175 pub admin: Option<bool>,
176 pub bot_account: Option<bool>,
179 impl ApubObject for Person {
180 type DataType = PgConnection;
182 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
183 Some(self.last_refreshed_at)
186 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
187 use crate::schema::person::dsl::*;
188 let object_id: DbUrl = object_id.into();
191 .filter(deleted.eq(false))
192 .filter(actor_id.eq(object_id))
199 impl ActorType for Person {
200 fn is_local(&self) -> bool {
203 fn actor_id(&self) -> Url {
204 self.actor_id.to_owned().into_inner()
206 fn name(&self) -> String {
210 fn public_key(&self) -> Option<String> {
211 self.public_key.to_owned()
214 fn private_key(&self) -> Option<String> {
215 self.private_key.to_owned()
218 fn inbox_url(&self) -> Url {
219 self.inbox_url.clone().into()
222 fn shared_inbox_url(&self) -> Option<Url> {
223 self.shared_inbox_url.clone().map(|s| s.into_inner())