diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-09 01:43:34 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-09 11:45:31 -0400 |
| commit | 2f0b77e8fd02a137047c8975a573626cd76310ff (patch) | |
| tree | 481d82e99cf8aad8fe256d8186ae72bcee23bf9f /src/message/repo.rs | |
| parent | ba96974bdebd6d4ec345907d49944b5ee644ed47 (diff) | |
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.
Diffstat (limited to 'src/message/repo.rs')
| -rw-r--r-- | src/message/repo.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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<Vec<History>, 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<History, sqlx::Error> { let message = sqlx::query!( r#" |
