From 2f0b77e8fd02a137047c8975a573626cd76310ff Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 9 Oct 2024 01:43:34 -0400 Subject: Return a flat message list on boot, not nested lists by channel. This is a bit easier to compute, and sets us up nicely for pulling message boot out of the `/api/boot` response entirely. --- src/message/repo.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/message/repo.rs') diff --git a/src/message/repo.rs b/src/message/repo.rs index 0560f4a..71c6d10 100644 --- a/src/message/repo.rs +++ b/src/message/repo.rs @@ -112,6 +112,41 @@ impl<'c> Messages<'c> { Ok(messages) } + pub async fn all(&mut self, resume_at: ResumePoint) -> Result, sqlx::Error> { + let messages = sqlx::query!( + r#" + select + channel as "channel: channel::Id", + sender as "sender: login::Id", + id as "id: Id", + body, + sent_at as "sent_at: DateTime", + sent_sequence as "sent_sequence: Sequence" + from message + where coalesce(sent_sequence <= $2, true) + order by sent_sequence + "#, + resume_at, + ) + .map(|row| History { + message: Message { + sent: Instant { + at: row.sent_at, + sequence: row.sent_sequence, + }, + channel: row.channel, + sender: row.sender, + id: row.id, + body: row.body, + }, + deleted: None, + }) + .fetch_all(&mut *self.0) + .await?; + + Ok(messages) + } + async fn by_id(&mut self, message: &Id) -> Result { let message = sqlx::query!( r#" -- cgit v1.2.3