diff options
| author | Kit La Touche <kit@transneptune.net> | 2024-10-04 22:39:08 -0400 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2024-10-04 22:39:08 -0400 |
| commit | 9926f91762154be9f26ef12518545da049ed422c (patch) | |
| tree | 3137b9c34d848900855f94351337afd22f4a69e6 /src/message/repo.rs | |
| parent | 9430825290ba345201546e35578891468da87265 (diff) | |
| parent | 9bd6d9862b1c243def02200bca2cfbf578ad2a2f (diff) | |
Merge branch 'main' into feature-frontend
Diffstat (limited to 'src/message/repo.rs')
| -rw-r--r-- | src/message/repo.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/message/repo.rs b/src/message/repo.rs index fc835c8..2ca409d 100644 --- a/src/message/repo.rs +++ b/src/message/repo.rs @@ -23,12 +23,13 @@ pub struct Messages<'t>(&'t mut SqliteConnection); impl<'c> Messages<'c> { pub async fn create( &mut self, - channel: &Channel, + channel: &channel::History, sender: &Login, sent: &Instant, body: &str, ) -> Result<History, sqlx::Error> { let id = Id::generate(); + let channel_id = channel.id(); let message = sqlx::query!( r#" @@ -40,7 +41,7 @@ impl<'c> Messages<'c> { body "#, id, - channel.id, + channel_id, sender.id, sent.at, sent.sequence, @@ -49,7 +50,10 @@ impl<'c> Messages<'c> { .map(|row| History { message: Message { sent: *sent, - channel: channel.clone(), + // Use "as created" here as we don't care about providing a perfectly up-to-date + // representation of the channel. The `name` is informational (and the ID, which is + // normative, is fixed over time). + channel: channel.as_created(), sender: sender.clone(), id: row.id, body: row.body, @@ -64,9 +68,10 @@ impl<'c> Messages<'c> { pub async fn in_channel( &mut self, - channel: &Channel, + channel: &channel::History, resume_at: Option<Sequence>, ) -> Result<Vec<History>, sqlx::Error> { + let channel_id = channel.id(); let messages = sqlx::query!( r#" select @@ -85,7 +90,7 @@ impl<'c> Messages<'c> { and coalesce(message.sent_sequence <= $2, true) order by message.sent_sequence "#, - channel.id, + channel_id, resume_at, ) .map(|row| History { |
