2024-03-16 03:27:36 +01:00
|
|
|
use sea_orm::entity::prelude::*;
|
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
use crate::activitystream::{node::InsertStr, object::{Actor, ActorType}, Base, BaseType, Object, ObjectType};
|
2024-03-16 05:45:58 +01:00
|
|
|
|
2024-03-16 03:27:36 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
|
|
|
#[sea_orm(table_name = "users")]
|
|
|
|
pub struct Model {
|
|
|
|
#[sea_orm(primary_key)]
|
|
|
|
/// must be user@instance.org, even if local! TODO bad design...
|
|
|
|
pub id: String,
|
2024-03-16 05:45:58 +01:00
|
|
|
|
|
|
|
pub actor_type: ActorType,
|
|
|
|
|
|
|
|
pub name: String,
|
2024-03-16 03:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
|
|
pub enum Relation {}
|
|
|
|
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
impl Base for Model {
|
2024-03-16 03:27:36 +01:00
|
|
|
fn id(&self) -> Option<&str> {
|
|
|
|
Some(&self.id)
|
|
|
|
}
|
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
fn base_type(&self) -> Option<BaseType> {
|
|
|
|
Some(BaseType::Object(ObjectType::Actor(self.actor_type)))
|
2024-03-16 05:45:58 +01:00
|
|
|
}
|
2024-03-19 06:49:21 +01:00
|
|
|
}
|
2024-03-16 05:45:58 +01:00
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
impl Object for Model {
|
2024-03-16 03:27:36 +01:00
|
|
|
fn name (&self) -> Option<&str> {
|
2024-03-16 05:45:58 +01:00
|
|
|
Some(&self.name)
|
2024-03-16 03:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-16 20:09:06 +01:00
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
impl Actor for Model {
|
|
|
|
fn actor_type(&self) -> Option<ActorType> {
|
|
|
|
Some(self.actor_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 20:09:06 +01:00
|
|
|
impl Model {
|
2024-03-19 06:49:21 +01:00
|
|
|
pub fn new(object: &impl Actor) -> Result<Self, super::FieldError> {
|
2024-03-16 20:09:06 +01:00
|
|
|
Ok(Model {
|
|
|
|
id: object.id().ok_or(super::FieldError("id"))?.to_string(),
|
2024-03-19 06:49:21 +01:00
|
|
|
actor_type: object.actor_type().ok_or(super::FieldError("type"))?,
|
2024-03-16 20:09:06 +01:00
|
|
|
name: object.name().ok_or(super::FieldError("name"))?.to_string(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-03-19 06:49:21 +01:00
|
|
|
|
|
|
|
impl super::ToJson for Model {
|
|
|
|
fn json(&self) -> serde_json::Value {
|
|
|
|
let mut map = serde_json::Map::new();
|
|
|
|
map.insert_str("id", Some(&self.id));
|
|
|
|
map.insert_str("type", Some(self.actor_type.as_ref()));
|
|
|
|
map.insert_str("name", Some(&self.name));
|
|
|
|
serde_json::Value::Object(map)
|
|
|
|
}
|
|
|
|
}
|