2024-03-21 20:36:46 +01:00
|
|
|
use sea_orm::entity::prelude::*;
|
2024-03-16 05:45:58 +01:00
|
|
|
|
2024-03-23 06:32:15 +01:00
|
|
|
use crate::activitystream::object::activity::{Activity, ActivityType};
|
2024-03-21 01:09:33 +01:00
|
|
|
|
2024-03-21 20:36:46 +01:00
|
|
|
use super::Audience;
|
2024-03-16 05:45:58 +01:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
|
|
|
#[sea_orm(table_name = "activities")]
|
|
|
|
pub struct Model {
|
|
|
|
#[sea_orm(primary_key)]
|
|
|
|
pub id: String,
|
|
|
|
|
2024-03-19 06:49:21 +01:00
|
|
|
pub activity_type: ActivityType,
|
2024-03-21 20:36:46 +01:00
|
|
|
pub actor: String,
|
|
|
|
pub object: Option<String>,
|
2024-03-21 01:09:33 +01:00
|
|
|
|
2024-03-16 05:45:58 +01:00
|
|
|
pub target: Option<String>, // TODO relates to USER maybe??
|
2024-03-21 01:09:33 +01:00
|
|
|
pub cc: Audience,
|
|
|
|
pub bcc: Audience,
|
|
|
|
pub to: Audience,
|
|
|
|
pub bto: Audience,
|
2024-03-16 05:45:58 +01:00
|
|
|
pub published: ChronoDateTimeUtc,
|
|
|
|
|
|
|
|
// TODO: origin, result, instrument
|
|
|
|
}
|
|
|
|
|
2024-03-23 06:32:15 +01:00
|
|
|
impl Model {
|
|
|
|
pub fn new(activity: &impl Activity) -> Result<Self, super::FieldError> {
|
|
|
|
Ok(Model {
|
|
|
|
id: activity.id().ok_or(super::FieldError("id"))?.to_string(),
|
|
|
|
activity_type: activity.activity_type().ok_or(super::FieldError("type"))?,
|
|
|
|
actor: activity.actor().id().ok_or(super::FieldError("actor"))?.to_string(),
|
|
|
|
object: activity.object().id().map(|x| x.to_string()),
|
|
|
|
target: activity.target().id().map(|x| x.to_string()),
|
|
|
|
published: activity.published().unwrap_or(chrono::Utc::now()),
|
|
|
|
to: activity.to().into(),
|
|
|
|
bto: activity.bto().into(),
|
|
|
|
cc: activity.cc().into(),
|
|
|
|
bcc: activity.bcc().into(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 05:45:58 +01:00
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
2024-03-21 01:09:33 +01:00
|
|
|
pub enum Relation {
|
|
|
|
#[sea_orm(
|
|
|
|
belongs_to = "super::user::Entity",
|
|
|
|
from = "Column::Actor",
|
|
|
|
to = "super::user::Column::Id"
|
|
|
|
)]
|
|
|
|
User,
|
|
|
|
|
|
|
|
#[sea_orm(
|
|
|
|
belongs_to = "super::object::Entity",
|
|
|
|
from = "Column::Object",
|
|
|
|
to = "super::object::Column::Id"
|
|
|
|
)]
|
|
|
|
Object,
|
2024-03-24 04:03:44 +01:00
|
|
|
|
|
|
|
#[sea_orm(has_many = "super::addressing::Entity")]
|
|
|
|
Addressing,
|
2024-03-25 05:07:58 +01:00
|
|
|
|
|
|
|
#[sea_orm(has_many = "super::delivery::Entity")]
|
|
|
|
Delivery,
|
2024-03-21 01:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Related<super::user::Entity> for Entity {
|
|
|
|
fn to() -> RelationDef {
|
|
|
|
Relation::User.def()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Related<super::object::Entity> for Entity {
|
|
|
|
fn to() -> RelationDef {
|
|
|
|
Relation::Object.def()
|
|
|
|
}
|
|
|
|
}
|
2024-03-16 05:45:58 +01:00
|
|
|
|
2024-03-24 04:03:44 +01:00
|
|
|
impl Related<super::addressing::Entity> for Entity {
|
|
|
|
fn to() -> RelationDef {
|
|
|
|
Relation::Addressing.def()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 05:45:58 +01:00
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|