diff --git a/src/migrations/m20240502_000001_add_object_updated.rs b/src/migrations/m20240502_000001_add_object_updated.rs new file mode 100644 index 00000000..863c5e04 --- /dev/null +++ b/src/migrations/m20240502_000001_add_object_updated.rs @@ -0,0 +1,40 @@ +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::Updated).date_time().null()) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Objects::Table) + .drop_column(Objects::Updated) + .to_owned() + ) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Objects { + Table, + Updated, +} + diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index fdf2be5e..c5b4dae2 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -13,6 +13,7 @@ mod m20240418_000001_add_statuses_and_reply_to; mod m20240421_000001_add_attachments; mod m20240424_000001_add_sensitive_field; mod m20240429_000001_add_relays_table; +mod m20240502_000001_add_object_updated; pub struct Migrator; @@ -33,6 +34,7 @@ impl MigratorTrait for Migrator { Box::new(m20240421_000001_add_attachments::Migration), Box::new(m20240424_000001_add_sensitive_field::Migration), Box::new(m20240429_000001_add_relays_table::Migration), + Box::new(m20240502_000001_add_object_updated::Migration), ] } } diff --git a/src/model/object.rs b/src/model/object.rs index 0a6a6d42..af2a32bf 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -25,6 +25,7 @@ pub struct Model { pub to: Audience, pub bto: Audience, pub published: ChronoDateTimeUtc, + pub updated: Option, pub sensitive: bool, } @@ -41,6 +42,7 @@ impl Model { context: object.context().id(), in_reply_to: object.in_reply_to().id(), published: object.published().ok_or(super::FieldError("published"))?, + updated: object.updated(), comments: object.replies().get() .map_or(0, |x| x.total_items().unwrap_or(0)) as i64, likes: object.likes().get() @@ -67,6 +69,7 @@ impl Model { .set_context(apb::Node::maybe_link(self.context.clone())) .set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.clone())) .set_published(Some(self.published)) + .set_updated(self.updated) .set_to(apb::Node::links(self.to.0.clone())) .set_bto(apb::Node::Empty) .set_cc(apb::Node::links(self.cc.0.clone())) diff --git a/src/server/inbox.rs b/src/server/inbox.rs index 01b40b56..54644c35 100644 --- a/src/server/inbox.rs +++ b/src/server/inbox.rs @@ -252,6 +252,7 @@ impl apb::server::Inbox for Context { // back up to serde_json::Value because impl Object != impl Actor let actor_model = model::user::Model::new(&object_node)?; let mut update_model = actor_model.into_active_model(); + update_model.updated = sea_orm::Set(chrono::Utc::now()); update_model.reset(model::user::Column::Name); update_model.reset(model::user::Column::Summary); update_model.reset(model::user::Column::Image); @@ -262,6 +263,7 @@ impl apb::server::Inbox for Context { Some(apb::ObjectType::Note) => { let object_model = model::object::Model::new(&object_node)?; let mut update_model = object_model.into_active_model(); + update_model.updated = sea_orm::Set(Some(chrono::Utc::now())); update_model.reset(model::object::Column::Name); update_model.reset(model::object::Column::Summary); update_model.reset(model::object::Column::Content); diff --git a/src/server/outbox.rs b/src/server/outbox.rs index 99918b3a..2db6088a 100644 --- a/src/server/outbox.rs +++ b/src/server/outbox.rs @@ -327,6 +327,7 @@ impl apb::server::Outbox for Context { if actor_model.icon.is_none() { actor_model.icon = old_actor_model.icon } let mut update_model = actor_model.into_active_model(); + update_model.updated = sea_orm::Set(chrono::Utc::now()); update_model.reset(model::user::Column::Name); update_model.reset(model::user::Column::Summary); update_model.reset(model::user::Column::Image); @@ -357,6 +358,7 @@ impl apb::server::Outbox for Context { if object_model.content.is_none() { object_model.content = old_object_model.content } let mut update_model = object_model.into_active_model(); + update_model.updated = sea_orm::Set(Some(chrono::Utc::now())); update_model.reset(model::object::Column::Name); update_model.reset(model::object::Column::Summary); update_model.reset(model::object::Column::Content);