diff --git a/migrations/2024-11-12-131724_article-approval/down.sql b/migrations/2024-11-12-131724_article-approval/down.sql index fbe1f23..18d5121 100644 --- a/migrations/2024-11-12-131724_article-approval/down.sql +++ b/migrations/2024-11-12-131724_article-approval/down.sql @@ -1 +1,7 @@ -alter table article drop column approved; \ No newline at end of file +alter table article drop column approved; + +alter table article drop column published; + +alter table conflict drop column published; + +alter table edit rename column published to created; \ No newline at end of file diff --git a/migrations/2024-11-12-131724_article-approval/up.sql b/migrations/2024-11-12-131724_article-approval/up.sql index f2d63ea..3d60114 100644 --- a/migrations/2024-11-12-131724_article-approval/up.sql +++ b/migrations/2024-11-12-131724_article-approval/up.sql @@ -1 +1,7 @@ -alter table article add column approved bool not null default true; \ No newline at end of file +alter table article add column approved bool not null default true; + +alter table article add column published timestamptz not null default now(); + +alter table conflict add column published timestamptz not null default now(); + +alter table edit rename column created to published; \ No newline at end of file diff --git a/src/backend/api/article.rs b/src/backend/api/article.rs index 8028230..cf62f86 100644 --- a/src/backend/api/article.rs +++ b/src/backend/api/article.rs @@ -242,7 +242,7 @@ pub(in crate::backend::api) async fn fork_article( article_id: article.id, hash: e.hash, previous_version_id: e.previous_version_id, - created: Utc::now(), + published: Utc::now(), }; DbEdit::create(&form, &data)?; } diff --git a/src/backend/api/user.rs b/src/backend/api/user.rs index 1c2b96c..73c8054 100644 --- a/src/backend/api/user.rs +++ b/src/backend/api/user.rs @@ -182,6 +182,7 @@ pub(crate) async fn list_notifications( .map(Notification::ArticleApprovalRequired), ) } + notifications.sort_by(|a, b| a.published().cmp(b.published())); Ok(Json(notifications)) } diff --git a/src/backend/database/article.rs b/src/backend/database/article.rs index 887dbba..c8a5743 100644 --- a/src/backend/database/article.rs +++ b/src/backend/database/article.rs @@ -157,7 +157,7 @@ impl DbArticle { .inner_join(instance::table) .filter(article::dsl::approved.eq(true)) .group_by(article::dsl::id) - .order_by(max(edit::dsl::created).desc()) + .order_by(max(edit::dsl::published).desc()) .select(article::all_columns) .into_boxed(); @@ -204,10 +204,8 @@ impl DbArticle { pub fn list_approval_required(data: &IbisData) -> MyResult> { let mut conn = data.db_pool.get()?; let query = article::table - .inner_join(edit::table) .group_by(article::dsl::id) .filter(article::dsl::approved.eq(false)) - .order_by(max(edit::dsl::created).desc()) .select(article::all_columns) .into_boxed(); diff --git a/src/backend/database/conflict.rs b/src/backend/database/conflict.rs index 9556a4d..b34916c 100644 --- a/src/backend/database/conflict.rs +++ b/src/backend/database/conflict.rs @@ -15,6 +15,7 @@ use crate::{ }, }; use activitypub_federation::config::Data; +use chrono::{DateTime, Utc}; use diesel::{ delete, insert_into, @@ -42,6 +43,7 @@ pub struct DbConflict { pub creator_id: PersonId, pub article_id: ArticleId, pub previous_version_id: EditVersion, + pub published: DateTime, } #[derive(Debug, Clone, Insertable)] @@ -117,6 +119,7 @@ impl DbConflict { summary: self.summary.clone(), article: original_article.clone(), previous_version_id: original_article.latest_edit_version(data)?, + published: self.published, })) } } diff --git a/src/backend/database/edit.rs b/src/backend/database/edit.rs index 30a3b90..997fcec 100644 --- a/src/backend/database/edit.rs +++ b/src/backend/database/edit.rs @@ -28,7 +28,7 @@ pub struct DbEditForm { pub summary: String, pub article_id: ArticleId, pub previous_version_id: EditVersion, - pub created: DateTime, + pub published: DateTime, } impl DbEditForm { @@ -50,7 +50,7 @@ impl DbEditForm { article_id: original_article.id, previous_version_id, summary, - created: Utc::now(), + published: Utc::now(), }) } @@ -97,7 +97,7 @@ impl DbEdit { Ok(edit::table .inner_join(person::table) .filter(edit::article_id.eq(article.id)) - .order(edit::created) + .order(edit::published) .get_results(conn.deref_mut())?) } } diff --git a/src/backend/database/schema.rs b/src/backend/database/schema.rs index 1affb5a..579f077 100644 --- a/src/backend/database/schema.rs +++ b/src/backend/database/schema.rs @@ -11,6 +11,7 @@ diesel::table! { local -> Bool, protected -> Bool, approved -> Bool, + published -> Timestamptz, } } @@ -23,6 +24,7 @@ diesel::table! { creator_id -> Int4, article_id -> Int4, previous_version_id -> Uuid, + published -> Timestamptz, } } @@ -37,7 +39,7 @@ diesel::table! { summary -> Text, article_id -> Int4, previous_version_id -> Uuid, - created -> Timestamptz, + published -> Timestamptz, } } diff --git a/src/backend/federation/activities/mod.rs b/src/backend/federation/activities/mod.rs index 5ea0c08..b6c5ee4 100644 --- a/src/backend/federation/activities/mod.rs +++ b/src/backend/federation/activities/mod.rs @@ -56,7 +56,7 @@ pub async fn submit_article_update( summary: form.summary, article_id: form.article_id, previous_version_id: form.previous_version_id, - created: Utc::now(), + published: Utc::now(), }; let instance = DbInstance::read(original_article.instance_id, data)?; UpdateRemoteArticle::send(edit, instance, data).await?; diff --git a/src/backend/federation/objects/edit.rs b/src/backend/federation/objects/edit.rs index b472e3d..2559cce 100644 --- a/src/backend/federation/objects/edit.rs +++ b/src/backend/federation/objects/edit.rs @@ -63,7 +63,7 @@ impl Object for DbEdit { previous_version: self.previous_version_id, object: article.article.ap_id, attributed_to: creator.ap_id, - published: self.created, + published: self.published, }) } @@ -94,7 +94,7 @@ impl Object for DbEdit { article_id: article.id, hash: json.version, previous_version_id: json.previous_version, - created: json.published, + published: json.published, }; let edit = DbEdit::create(&form, data)?; Ok(edit) diff --git a/src/backend/utils.rs b/src/backend/utils.rs index 3f76918..89014f7 100644 --- a/src/backend/utils.rs +++ b/src/backend/utils.rs @@ -68,7 +68,7 @@ mod test { summary: String::new(), article_id: ArticleId(0), previous_version_id: Default::default(), - created: Utc::now(), + published: Utc::now(), }, creator: DbPerson { id: PersonId(0), diff --git a/src/common/mod.rs b/src/common/mod.rs index ce0d9c4..44bc823 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -59,6 +59,7 @@ pub struct DbArticle { pub local: bool, pub protected: bool, pub approved: bool, + pub published: DateTime, } /// Represents a single change to the article. @@ -82,7 +83,7 @@ pub struct DbEdit { pub article_id: ArticleId, /// First edit of an article always has `EditVersion::default()` here pub previous_version_id: EditVersion, - pub created: DateTime, + pub published: DateTime, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] @@ -248,6 +249,7 @@ pub struct ApiConflict { pub summary: String, pub article: DbArticle, pub previous_version_id: EditVersion, + pub published: DateTime, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -256,6 +258,15 @@ pub enum Notification { ArticleApprovalRequired(DbArticle), } +impl Notification { + pub fn published(&self) -> &DateTime { + match self { + Notification::EditConflict(api_conflict) => &api_conflict.published, + Notification::ArticleApprovalRequired(db_article) => &db_article.published, + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Identifiable))] #[cfg_attr(feature = "ssr", diesel(table_name = instance, check_for_backend(diesel::pg::Pg)))] diff --git a/src/frontend/pages/article/history.rs b/src/frontend/pages/article/history.rs index a0cf4d9..96774c9 100644 --- a/src/frontend/pages/article/history.rs +++ b/src/frontend/pages/article/history.rs @@ -41,7 +41,7 @@ pub fn ArticleHistory() -> impl IntoView { {edit.edit.summary}

- {render_date_time(edit.edit.created)}" by " + {render_date_time(edit.edit.published)}" by " {user_link(&edit.creator)}

diff --git a/src/frontend/pages/diff.rs b/src/frontend/pages/diff.rs index b72b01c..4d2ea4b 100644 --- a/src/frontend/pages/diff.rs +++ b/src/frontend/pages/diff.rs @@ -30,7 +30,7 @@ pub fn EditDiff() -> impl IntoView { let label = format!( "{} ({})", edit.edit.summary, - render_date_time(edit.edit.created), + render_date_time(edit.edit.published), ); view! {

{label}