diff --git a/apb/src/types/object/mod.rs b/apb/src/types/object/mod.rs index 6af39ad1..7abdeaa8 100644 --- a/apb/src/types/object/mod.rs +++ b/apb/src/types/object/mod.rs @@ -66,6 +66,9 @@ pub trait Object : Base { fn bcc(&self) -> Node { Node::Empty } fn media_type(&self) -> Option<&str> { None } // also in link fn duration(&self) -> Option<&str> { None } // TODO how to parse xsd:duration ? + + // TODO i really need this but it isn't part of AP! + fn sensitive(&self) -> Option { None } } pub trait ObjectMut : BaseMut { @@ -102,6 +105,8 @@ pub trait ObjectMut : BaseMut { fn set_bcc(self, val: Node) -> Self; fn set_media_type(self, val: Option<&str>) -> Self; // also in link fn set_duration(self, val: Option<&str>) -> Self; // TODO how to parse xsd:duration ? + + fn set_sensitive(self, val: Option) -> Self; } #[cfg(feature = "unstructured")] @@ -139,6 +144,8 @@ impl Object for serde_json::Value { crate::getter! { duration -> &str } crate::getter! { url -> node Self::Link } + crate::getter! { sensitive -> bool } + // TODO Mastodon doesn't use a "context" field on the object but makes up a new one!! fn context(&self) -> Node<::Object> { match self.get("context") { @@ -186,4 +193,6 @@ impl ObjectMut for serde_json::Value { crate::setter! { duration -> &str } crate::setter! { url -> node Self::Link } crate::setter! { context -> node ::Object } + + crate::setter! { sensitive -> bool } } diff --git a/src/migrations/m20240424_000001_add_sensitive_field.rs b/src/migrations/m20240424_000001_add_sensitive_field.rs new file mode 100644 index 00000000..1ec8fbd7 --- /dev/null +++ b/src/migrations/m20240424_000001_add_sensitive_field.rs @@ -0,0 +1,45 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Objects::Table) + .add_column( + ColumnDef::new(Objects::Sensitive) + .boolean() + .not_null() + .default(false) + ) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Objects::Table) + .drop_column(Objects::Sensitive) + .to_owned() + ) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Objects { + Table, + Sensitive, +} + diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index 9396eba3..9b0f2e87 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -11,6 +11,7 @@ mod m20240325_000001_add_deliveries; mod m20240325_000002_add_system_key; mod m20240418_000001_add_statuses_and_reply_to; mod m20240421_000001_add_attachments; +mod m20240424_000001_add_sensitive_field; pub struct Migrator; @@ -29,6 +30,7 @@ impl MigratorTrait for Migrator { Box::new(m20240325_000002_add_system_key::Migration), Box::new(m20240418_000001_add_statuses_and_reply_to::Migration), Box::new(m20240421_000001_add_attachments::Migration), + Box::new(m20240424_000001_add_sensitive_field::Migration), ] } } diff --git a/src/model/object.rs b/src/model/object.rs index 1101a510..3087b120 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -25,6 +25,8 @@ pub struct Model { pub to: Audience, pub bto: Audience, pub published: ChronoDateTimeUtc, + + pub sensitive: bool, } impl Model { @@ -46,6 +48,8 @@ impl Model { bto: object.bto().into(), cc: object.cc().into(), bcc: object.bcc().into(), + + sensitive: object.sensitive().unwrap_or(false), }) } @@ -64,6 +68,7 @@ impl Model { .set_bto(apb::Node::Empty) .set_cc(apb::Node::links(self.cc.0.clone())) .set_bcc(apb::Node::Empty) + .set_sensitive(Some(self.sensitive)) } }