1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-24 00:11:09 +00:00

Add published timestamps, sort notifications

This commit is contained in:
Felix Ableitner 2024-11-13 10:56:23 +01:00
parent d075d15b50
commit 733abdef96
14 changed files with 44 additions and 17 deletions

View file

@ -1 +1,7 @@
alter table article drop column approved; 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;

View file

@ -1 +1,7 @@
alter table article add column approved bool not null default true; 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;

View file

@ -242,7 +242,7 @@ pub(in crate::backend::api) async fn fork_article(
article_id: article.id, article_id: article.id,
hash: e.hash, hash: e.hash,
previous_version_id: e.previous_version_id, previous_version_id: e.previous_version_id,
created: Utc::now(), published: Utc::now(),
}; };
DbEdit::create(&form, &data)?; DbEdit::create(&form, &data)?;
} }

View file

@ -182,6 +182,7 @@ pub(crate) async fn list_notifications(
.map(Notification::ArticleApprovalRequired), .map(Notification::ArticleApprovalRequired),
) )
} }
notifications.sort_by(|a, b| a.published().cmp(b.published()));
Ok(Json(notifications)) Ok(Json(notifications))
} }

View file

@ -157,7 +157,7 @@ impl DbArticle {
.inner_join(instance::table) .inner_join(instance::table)
.filter(article::dsl::approved.eq(true)) .filter(article::dsl::approved.eq(true))
.group_by(article::dsl::id) .group_by(article::dsl::id)
.order_by(max(edit::dsl::created).desc()) .order_by(max(edit::dsl::published).desc())
.select(article::all_columns) .select(article::all_columns)
.into_boxed(); .into_boxed();
@ -204,10 +204,8 @@ impl DbArticle {
pub fn list_approval_required(data: &IbisData) -> MyResult<Vec<Self>> { pub fn list_approval_required(data: &IbisData) -> MyResult<Vec<Self>> {
let mut conn = data.db_pool.get()?; let mut conn = data.db_pool.get()?;
let query = article::table let query = article::table
.inner_join(edit::table)
.group_by(article::dsl::id) .group_by(article::dsl::id)
.filter(article::dsl::approved.eq(false)) .filter(article::dsl::approved.eq(false))
.order_by(max(edit::dsl::created).desc())
.select(article::all_columns) .select(article::all_columns)
.into_boxed(); .into_boxed();

View file

@ -15,6 +15,7 @@ use crate::{
}, },
}; };
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use chrono::{DateTime, Utc};
use diesel::{ use diesel::{
delete, delete,
insert_into, insert_into,
@ -42,6 +43,7 @@ pub struct DbConflict {
pub creator_id: PersonId, pub creator_id: PersonId,
pub article_id: ArticleId, pub article_id: ArticleId,
pub previous_version_id: EditVersion, pub previous_version_id: EditVersion,
pub published: DateTime<Utc>,
} }
#[derive(Debug, Clone, Insertable)] #[derive(Debug, Clone, Insertable)]
@ -117,6 +119,7 @@ impl DbConflict {
summary: self.summary.clone(), summary: self.summary.clone(),
article: original_article.clone(), article: original_article.clone(),
previous_version_id: original_article.latest_edit_version(data)?, previous_version_id: original_article.latest_edit_version(data)?,
published: self.published,
})) }))
} }
} }

View file

@ -28,7 +28,7 @@ pub struct DbEditForm {
pub summary: String, pub summary: String,
pub article_id: ArticleId, pub article_id: ArticleId,
pub previous_version_id: EditVersion, pub previous_version_id: EditVersion,
pub created: DateTime<Utc>, pub published: DateTime<Utc>,
} }
impl DbEditForm { impl DbEditForm {
@ -50,7 +50,7 @@ impl DbEditForm {
article_id: original_article.id, article_id: original_article.id,
previous_version_id, previous_version_id,
summary, summary,
created: Utc::now(), published: Utc::now(),
}) })
} }
@ -97,7 +97,7 @@ impl DbEdit {
Ok(edit::table Ok(edit::table
.inner_join(person::table) .inner_join(person::table)
.filter(edit::article_id.eq(article.id)) .filter(edit::article_id.eq(article.id))
.order(edit::created) .order(edit::published)
.get_results(conn.deref_mut())?) .get_results(conn.deref_mut())?)
} }
} }

View file

@ -11,6 +11,7 @@ diesel::table! {
local -> Bool, local -> Bool,
protected -> Bool, protected -> Bool,
approved -> Bool, approved -> Bool,
published -> Timestamptz,
} }
} }
@ -23,6 +24,7 @@ diesel::table! {
creator_id -> Int4, creator_id -> Int4,
article_id -> Int4, article_id -> Int4,
previous_version_id -> Uuid, previous_version_id -> Uuid,
published -> Timestamptz,
} }
} }
@ -37,7 +39,7 @@ diesel::table! {
summary -> Text, summary -> Text,
article_id -> Int4, article_id -> Int4,
previous_version_id -> Uuid, previous_version_id -> Uuid,
created -> Timestamptz, published -> Timestamptz,
} }
} }

View file

@ -56,7 +56,7 @@ pub async fn submit_article_update(
summary: form.summary, summary: form.summary,
article_id: form.article_id, article_id: form.article_id,
previous_version_id: form.previous_version_id, previous_version_id: form.previous_version_id,
created: Utc::now(), published: Utc::now(),
}; };
let instance = DbInstance::read(original_article.instance_id, data)?; let instance = DbInstance::read(original_article.instance_id, data)?;
UpdateRemoteArticle::send(edit, instance, data).await?; UpdateRemoteArticle::send(edit, instance, data).await?;

View file

@ -63,7 +63,7 @@ impl Object for DbEdit {
previous_version: self.previous_version_id, previous_version: self.previous_version_id,
object: article.article.ap_id, object: article.article.ap_id,
attributed_to: creator.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, article_id: article.id,
hash: json.version, hash: json.version,
previous_version_id: json.previous_version, previous_version_id: json.previous_version,
created: json.published, published: json.published,
}; };
let edit = DbEdit::create(&form, data)?; let edit = DbEdit::create(&form, data)?;
Ok(edit) Ok(edit)

View file

@ -68,7 +68,7 @@ mod test {
summary: String::new(), summary: String::new(),
article_id: ArticleId(0), article_id: ArticleId(0),
previous_version_id: Default::default(), previous_version_id: Default::default(),
created: Utc::now(), published: Utc::now(),
}, },
creator: DbPerson { creator: DbPerson {
id: PersonId(0), id: PersonId(0),

View file

@ -59,6 +59,7 @@ pub struct DbArticle {
pub local: bool, pub local: bool,
pub protected: bool, pub protected: bool,
pub approved: bool, pub approved: bool,
pub published: DateTime<Utc>,
} }
/// Represents a single change to the article. /// Represents a single change to the article.
@ -82,7 +83,7 @@ pub struct DbEdit {
pub article_id: ArticleId, pub article_id: ArticleId,
/// First edit of an article always has `EditVersion::default()` here /// First edit of an article always has `EditVersion::default()` here
pub previous_version_id: EditVersion, pub previous_version_id: EditVersion,
pub created: DateTime<Utc>, pub published: DateTime<Utc>,
} }
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
@ -248,6 +249,7 @@ pub struct ApiConflict {
pub summary: String, pub summary: String,
pub article: DbArticle, pub article: DbArticle,
pub previous_version_id: EditVersion, pub previous_version_id: EditVersion,
pub published: DateTime<Utc>,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -256,6 +258,15 @@ pub enum Notification {
ArticleApprovalRequired(DbArticle), ArticleApprovalRequired(DbArticle),
} }
impl Notification {
pub fn published(&self) -> &DateTime<Utc> {
match self {
Notification::EditConflict(api_conflict) => &api_conflict.published,
Notification::ArticleApprovalRequired(db_article) => &db_article.published,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Identifiable))] #[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Identifiable))]
#[cfg_attr(feature = "ssr", diesel(table_name = instance, check_for_backend(diesel::pg::Pg)))] #[cfg_attr(feature = "ssr", diesel(table_name = instance, check_for_backend(diesel::pg::Pg)))]

View file

@ -41,7 +41,7 @@ pub fn ArticleHistory() -> impl IntoView {
{edit.edit.summary} {edit.edit.summary}
</a> </a>
<p> <p>
{render_date_time(edit.edit.created)}" by " {render_date_time(edit.edit.published)}" by "
{user_link(&edit.creator)} {user_link(&edit.creator)}
</p> </p>
</div> </div>

View file

@ -30,7 +30,7 @@ pub fn EditDiff() -> impl IntoView {
let label = format!( let label = format!(
"{} ({})", "{} ({})",
edit.edit.summary, edit.edit.summary,
render_date_time(edit.edit.created), render_date_time(edit.edit.published),
); );
view! { view! {
<h2 class="text-xl font-bold font-serif my-2">{label}</h2> <h2 class="text-xl font-bold font-serif my-2">{label}</h2>