feat: sensitive field

this is not part of activitystreams afaik and should not be in apub but
it's quite convenient to do it this way sooooooooooo for now will do
This commit is contained in:
əlemi 2024-04-24 05:19:39 +02:00
parent abf4e8b370
commit 3156b8d2d2
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 61 additions and 0 deletions

View file

@ -66,6 +66,9 @@ pub trait Object : Base {
fn bcc(&self) -> Node<Self::Link> { 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<bool> { None }
}
pub trait ObjectMut : BaseMut {
@ -102,6 +105,8 @@ pub trait ObjectMut : BaseMut {
fn set_bcc(self, val: Node<Self::Link>) -> 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<bool>) -> 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<<Self as Object>::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 <Self as Object>::Object }
crate::setter! { sensitive -> bool }
}

View file

@ -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,
}

View file

@ -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),
]
}
}

View file

@ -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))
}
}