use crate::newtypes::{DbUrl, InstanceId, PersonId}; #[cfg(feature = "full")] use crate::schema::{person, person_follower}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = person))] #[cfg_attr(feature = "full", ts(export))] /// A person. pub struct Person { pub id: PersonId, pub name: String, /// A shorter display name. pub display_name: Option, /// A URL for an avatar. pub avatar: Option, /// Whether the person is banned. pub banned: bool, pub published: chrono::NaiveDateTime, pub updated: Option, /// The federated actor_id. pub actor_id: DbUrl, /// An optional bio, in markdown. pub bio: Option, /// Whether the person is local to our site. pub local: bool, #[serde(skip)] pub private_key: Option, #[serde(skip)] pub public_key: String, #[serde(skip)] pub last_refreshed_at: chrono::NaiveDateTime, /// A URL for a banner. pub banner: Option, /// Whether the person is deleted. pub deleted: bool, #[serde(skip_serializing)] pub inbox_url: DbUrl, #[serde(skip)] pub shared_inbox_url: Option, /// A matrix id, usually given an @person:matrix.org pub matrix_user_id: Option, /// Whether the person is an admin. pub admin: bool, /// Whether the person is a bot account. pub bot_account: bool, /// When their ban, if it exists, expires, if at all. pub ban_expires: Option, pub instance_id: InstanceId, } #[derive(Clone, TypedBuilder)] #[builder(field_defaults(default))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = person))] pub struct PersonInsertForm { #[builder(!default)] pub name: String, #[builder(!default)] pub public_key: String, #[builder(!default)] pub instance_id: InstanceId, pub display_name: Option, pub avatar: Option, pub banned: Option, pub published: Option, pub updated: Option, pub actor_id: Option, pub bio: Option, pub local: Option, pub private_key: Option, pub last_refreshed_at: Option, pub banner: Option, pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option, pub matrix_user_id: Option, pub admin: Option, pub bot_account: Option, pub ban_expires: Option, } #[derive(Clone, TypedBuilder)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = person))] #[builder(field_defaults(default))] pub struct PersonUpdateForm { pub display_name: Option>, pub avatar: Option>, pub banned: Option, pub updated: Option>, pub actor_id: Option, pub bio: Option>, pub local: Option, pub public_key: Option, pub private_key: Option>, pub last_refreshed_at: Option, pub banner: Option>, pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option>, pub matrix_user_id: Option>, pub admin: Option, pub bot_account: Option, pub ban_expires: Option>, } #[derive(PartialEq, Eq, Debug)] #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))] #[cfg_attr(feature = "full", diesel(table_name = person_follower))] pub struct PersonFollower { pub id: i32, pub person_id: PersonId, pub follower_id: PersonId, pub published: chrono::NaiveDateTime, pub pending: bool, } #[derive(Clone)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = person_follower))] pub struct PersonFollowerForm { pub person_id: PersonId, pub follower_id: PersonId, pub pending: bool, }