From 9bd6d9862b1c243def02200bca2cfbf578ad2a2f Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 4 Oct 2024 14:10:55 -0400 Subject: Clean up naming and semantics of history accessors. --- src/message/repo.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/message/repo.rs') 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 { 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, ) -> Result, 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 { -- cgit v1.2.3