mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-21 16:41:09 +00:00
Add published timestamps, sort notifications
This commit is contained in:
parent
d075d15b50
commit
733abdef96
14 changed files with 44 additions and 17 deletions
|
@ -1 +1,7 @@
|
|||
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;
|
|
@ -1 +1,7 @@
|
|||
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;
|
|
@ -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)?;
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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<Vec<Self>> {
|
||||
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();
|
||||
|
||||
|
|
|
@ -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<Utc>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct DbEditForm {
|
|||
pub summary: String,
|
||||
pub article_id: ArticleId,
|
||||
pub previous_version_id: EditVersion,
|
||||
pub created: DateTime<Utc>,
|
||||
pub published: DateTime<Utc>,
|
||||
}
|
||||
|
||||
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())?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -59,6 +59,7 @@ pub struct DbArticle {
|
|||
pub local: bool,
|
||||
pub protected: bool,
|
||||
pub approved: bool,
|
||||
pub published: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// 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<Utc>,
|
||||
pub published: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[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<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
@ -256,6 +258,15 @@ pub enum Notification {
|
|||
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)]
|
||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Identifiable))]
|
||||
#[cfg_attr(feature = "ssr", diesel(table_name = instance, check_for_backend(diesel::pg::Pg)))]
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn ArticleHistory() -> impl IntoView {
|
|||
{edit.edit.summary}
|
||||
</a>
|
||||
<p>
|
||||
{render_date_time(edit.edit.created)}" by "
|
||||
{render_date_time(edit.edit.published)}" by "
|
||||
{user_link(&edit.creator)}
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -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! {
|
||||
<h2 class="text-xl font-bold font-serif my-2">{label}</h2>
|
||||
|
|
Loading…
Reference in a new issue