diff --git a/src/migrations/m20240316_000001_create_table.rs b/src/migrations/m20240316_000001_create_table.rs index e0a31f0a..c37b3f17 100644 --- a/src/migrations/m20240316_000001_create_table.rs +++ b/src/migrations/m20240316_000001_create_table.rs @@ -77,6 +77,10 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Objects::Summary).string().null()) .col(ColumnDef::new(Objects::Content).string().null()) .col(ColumnDef::new(Objects::Context).string().null()) + .col(ColumnDef::new(Objects::To).json().null()) + .col(ColumnDef::new(Objects::Bto).json().null()) + .col(ColumnDef::new(Objects::Cc).json().null()) + .col(ColumnDef::new(Objects::Bcc).json().null()) .col(ColumnDef::new(Objects::Published).string().not_null()) .to_owned() ).await?; @@ -148,5 +152,9 @@ enum Objects { Summary, Content, Context, + Cc, + Bcc, + To, + Bto, Published, } diff --git a/src/model/activity.rs b/src/model/activity.rs index 5a288ba1..1e8b8054 100644 --- a/src/model/activity.rs +++ b/src/model/activity.rs @@ -1,22 +1,8 @@ -use sea_orm::{entity::prelude::*, FromJsonQueryResult}; +use sea_orm::entity::prelude::*; use crate::{activitypub::jsonld::LD, activitystream::{link::Link, object::{activity::{Activity, ActivityMut, ActivityType}, actor::Actor, Object, ObjectMut, ObjectType}, Base, BaseMut, BaseType, Node}}; -#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, FromJsonQueryResult)] -pub struct Audience(pub Vec); - -impl From> for Audience { - fn from(value: Node) -> Self { - Audience( - match value { - Node::Empty => vec![], - Node::Link(l) => vec![l.href().to_string()], - Node::Object(o) => if let Some(id) = o.id() { vec![id.to_string()] } else { vec![] }, - Node::Array(arr) => arr.into_iter().filter_map(|l| Some(l.id()?.to_string())).collect(), - } - ) - } -} +use super::Audience; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "activities")] @@ -26,8 +12,8 @@ pub struct Model { pub id: String, pub activity_type: ActivityType, - pub actor: String, // TODO relates to USER - pub object: Option, // TODO relates to NOTES maybe????? maybe other tables?????? + pub actor: String, + pub object: Option, pub target: Option, // TODO relates to USER maybe?? pub cc: Audience, diff --git a/src/model/mod.rs b/src/model/mod.rs index 06471309..862e22ec 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -7,5 +7,20 @@ pub mod faker; #[error("missing required field: '{0}'")] pub struct FieldError(pub &'static str); +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, sea_orm::FromJsonQueryResult)] +pub struct Audience(pub Vec); + +use crate::activitystream::{Link, Node}; +impl From> for Audience { + fn from(value: Node) -> Self { + Audience( + match value { + Node::Empty => vec![], + Node::Link(l) => vec![l.href().to_string()], + Node::Object(o) => if let Some(id) = o.id() { vec![id.to_string()] } else { vec![] }, + Node::Array(arr) => arr.into_iter().filter_map(|l| Some(l.id()?.to_string())).collect(), + } + ) } } + diff --git a/src/model/object.rs b/src/model/object.rs index 9735286d..d34e957f 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -1,6 +1,8 @@ use sea_orm::entity::prelude::*; -use crate::{activitypub::jsonld::LD, activitystream::{object::{ObjectMut, ObjectType}, BaseMut, BaseType, Node}}; +use crate::{activitypub::jsonld::LD, activitystream::{object::{ObjectMut, ObjectType}, BaseMut, BaseType, Link, Node}}; + +use super::Audience; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "objects")] @@ -14,6 +16,10 @@ pub struct Model { pub summary: Option, pub content: Option, pub context: Option, + pub cc: Audience, + pub bcc: Audience, + pub to: Audience, + pub bto: Audience, pub published: ChronoDateTimeUtc, } @@ -91,6 +97,22 @@ impl crate::activitystream::object::Object for Model { Node::maybe_link(self.context.clone()) } + fn to(&self) -> Node { + Node::links(self.to.0.clone()) + } + + fn bto(&self) -> Node { + Node::links(self.bto.0.clone()) + } + + fn cc(&self) -> Node { + Node::links(self.cc.0.clone()) + } + + fn bcc(&self) -> Node { + Node::links(self.bcc.0.clone()) + } + fn published (&self) -> Option> { Some(self.published) } @@ -107,6 +129,10 @@ impl Model { content: object.content().map(|x| x.to_string()), context: object.context().id().map(|x| x.to_string()), published: object.published().ok_or(super::FieldError("published"))?, + to: object.to().into(), + bto: object.bto().into(), + cc: object.cc().into(), + bcc: object.bcc().into(), }) } }