From dbca8183bb8bf5556da1e6ff24f3d9ccecc0b8e6 Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 31 Mar 2023 19:23:20 +0000 Subject: [PATCH] Order attachments by creation date when new post is created --- CHANGELOG.md | 1 + mitra-models/src/posts/queries.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e661a8..927c34b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Process queued background jobs before re-trying stalled. - Remove activity from queue if handler times out. +- Order attachments by creation date when new post is created. ## [1.19.0] - 2023-03-30 diff --git a/mitra-models/src/posts/queries.rs b/mitra-models/src/posts/queries.rs index 4546c08..6191839 100644 --- a/mitra-models/src/posts/queries.rs +++ b/mitra-models/src/posts/queries.rs @@ -57,9 +57,10 @@ async fn create_post_attachments( // Some attachments were not found return Err(DatabaseError::NotFound("attachment")); }; - let attachments = attachments_rows.iter() + let mut attachments: Vec = attachments_rows.iter() .map(|row| row.try_get("media_attachment")) .collect::>()?; + attachments.sort_by(|a, b| a.created_at.cmp(&b.created_at)); Ok(attachments) }