Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chg(channels): change preview ordering for thread replies in a channel (#1678)

teo8cca637a3516
diff --git a/rust/cloud-storage/channels/.sqlx/query-e07a1b0b46445b02321a5a64420ed6d987af073a0868db4aaf9dd3cd5b78eddd.json b/rust/cloud-storage/channels/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.json
similarity index 80%
rename from rust/cloud-storage/channels/.sqlx/query-e07a1b0b46445b02321a5a64420ed6d987af073a0868db4aaf9dd3cd5b78eddd.json
rename to rust/cloud-storage/channels/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.json
index c95d0e5136..1537df5b97 100644
--- a/rust/cloud-storage/channels/.sqlx/query-e07a1b0b46445b02321a5a64420ed6d987af073a0868db4aaf9dd3cd5b78eddd.json
+++ b/rust/cloud-storage/channels/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n id AS \"id!\", thread_id AS \"thread_id!\", sender_id AS \"sender_id!\",\n content AS \"content!\", created_at AS \"created_at!\", updated_at AS \"updated_at!\",\n edited_at::timestamptz AS \"edited_at?\",\n reply_count AS \"reply_count!\", latest_reply_at AS \"latest_reply_at?\"\n FROM (\n SELECT\n r.id,\n r.thread_id,\n r.sender_id,\n r.content,\n r.created_at,\n r.updated_at,\n r.edited_at,\n COUNT(*) OVER (PARTITION BY r.thread_id) AS reply_count,\n MAX(r.created_at) OVER (PARTITION BY r.thread_id)::timestamptz AS latest_reply_at,\n ROW_NUMBER() OVER (PARTITION BY r.thread_id ORDER BY r.created_at DESC) AS rn\n FROM comms_messages r\n WHERE r.thread_id = ANY($1) AND r.deleted_at IS NULL\n ) sub\n WHERE rn <= $2\n ORDER BY thread_id, created_at ASC\n ",
+ "query": "\n SELECT\n id AS \"id!\", thread_id AS \"thread_id!\", sender_id AS \"sender_id!\",\n content AS \"content!\", created_at AS \"created_at!\", updated_at AS \"updated_at!\",\n edited_at::timestamptz AS \"edited_at?\",\n reply_count AS \"reply_count!\", latest_reply_at AS \"latest_reply_at?\"\n FROM (\n SELECT\n r.id,\n r.thread_id,\n r.sender_id,\n r.content,\n r.created_at,\n r.updated_at,\n r.edited_at,\n COUNT(*) OVER (PARTITION BY r.thread_id) AS reply_count,\n MAX(r.created_at) OVER (PARTITION BY r.thread_id)::timestamptz AS latest_reply_at,\n ROW_NUMBER() OVER (\n PARTITION BY r.thread_id\n ORDER BY r.created_at ASC, r.id ASC\n ) AS rn\n FROM comms_messages r\n WHERE r.thread_id = ANY($1) AND r.deleted_at IS NULL\n ) sub\n WHERE rn <= $2\n ORDER BY thread_id, created_at ASC, id ASC\n ",
"describe": {
"columns": [
{
@@ -67,5 +67,5 @@
null
]
},
- "hash": "e07a1b0b46445b02321a5a64420ed6d987af073a0868db4aaf9dd3cd5b78eddd"
+ "hash": "6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c"
}
diff --git a/rust/cloud-storage/channels/src/domain/models.rs b/rust/cloud-storage/channels/src/domain/models.rs
index dc6a77ff89..f9384ec8ec 100644
--- a/rust/cloud-storage/channels/src/domain/models.rs
+++ b/rust/cloud-storage/channels/src/domain/models.rs
@@ -71,7 +71,7 @@ pub struct ThreadInfo {
pub reply_count: i64,
/// Timestamp of the most recent reply.
pub latest_reply_at: Option<DateTime<Utc>>,
- /// Last N replies for the collapsed thread preview.
+ /// Oldest N replies for the collapsed thread preview.
pub preview: Vec<ThreadReply>,
}
@@ -223,7 +223,7 @@ pub struct ThreadData {
pub reply_count: i64,
/// Timestamp of the latest reply.
pub latest_reply_at: Option<DateTime<Utc>>,
- /// Last N replies for the thread preview (oldest-first).
+ /// Oldest N replies for the thread preview (oldest-first).
pub preview_replies: Vec<ThreadReplyRow>,
}
diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
index e7f0c3bc63..5f66d58d31 100644
--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
@@ -254,12 +254,15 @@ impl ChannelMessagesRepo for PgChannelMessagesRepo {
r.edited_at,
COUNT(*) OVER (PARTITION BY r.thread_id) AS reply_count,
MAX(r.created_at) OVER (PARTITION BY r.thread_id)::timestamptz AS latest_reply_at,
- ROW_NUMBER() OVER (PARTITION BY r.thread_id ORDER BY r.created_at DESC) AS rn
+ ROW_NUMBER() OVER (
+ PARTITION BY r.thread_id
+ ORDER BY r.created_at ASC, r.id ASC
+ ) AS rn
FROM comms_messages r
WHERE r.thread_id = ANY($1) AND r.deleted_at IS NULL
) sub
WHERE rn <= $2
- ORDER BY thread_id, created_at ASC
+ ORDER BY thread_id, created_at ASC, id ASC
"#,
parent_ids,
i64::from(preview_count) as i64,
diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
index fd73cb18d9..78c96bb2e0 100644
--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
@@ -245,9 +245,9 @@ async fn thread_data_preview_count_limits_replies(pool: Pool<Postgres>) -> anyho
2,
"only 2 preview replies returned"
);
- // Preview should be the 2 most recent, in oldest-first order
- assert_eq!(thread.preview_replies[0].content, "reply 3");
- assert_eq!(thread.preview_replies[1].content, "reply 4");
+ // Preview should be the 2 oldest replies, in chronological order
+ assert_eq!(thread.preview_replies[0].content, "reply 1");
+ assert_eq!(thread.preview_replies[1].content, "reply 2");
Ok(())
}