diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-04 14:10:55 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-04 14:10:55 -0400 |
| commit | 9bd6d9862b1c243def02200bca2cfbf578ad2a2f (patch) | |
| tree | 44d20c937eee728e9b33ff093b3945a3ab2593dd /src/message/repo.rs | |
| parent | 7f12fd41c2941a55a6437f24e4f780104a718790 (diff) | |
Clean up naming and semantics of history accessors.
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 { |
