diff options
Diffstat (limited to 'src/channel/repo/broadcast.rs')
| -rw-r--r-- | src/channel/repo/broadcast.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/channel/repo/broadcast.rs b/src/channel/repo/broadcast.rs index 3ca7396..ff16cd0 100644 --- a/src/channel/repo/broadcast.rs +++ b/src/channel/repo/broadcast.rs @@ -3,8 +3,8 @@ use sqlx::{sqlite::Sqlite, SqliteConnection, Transaction}; use crate::{ clock::DateTime, repo::{ - channel, - login::{self, Login, Logins}, + channel::Channel, + login::{self, Login}, message, }, }; @@ -32,15 +32,13 @@ pub struct Message { impl<'c> Broadcast<'c> { pub async fn create( &mut self, - sender: &login::Id, - channel: &channel::Id, + sender: &Login, + channel: &Channel, body: &str, sent_at: &DateTime, ) -> Result<Message, sqlx::Error> { let id = message::Id::generate(); - let sender = Logins::from(&mut *self.0).by_id(sender).await?; - let message = sqlx::query!( r#" insert into message @@ -54,18 +52,15 @@ impl<'c> Broadcast<'c> { "#, id, sender.id, - channel, + channel.id, body, sent_at, ) - .map(|row| { - debug_assert!(row.sender == sender.id); - Message { - id: row.id, - sender: sender.clone(), - body: row.body, - sent_at: row.sent_at, - } + .map(|row| Message { + id: row.id, + sender: sender.clone(), + body: row.body, + sent_at: row.sent_at, }) .fetch_one(&mut *self.0) .await?; @@ -75,7 +70,7 @@ impl<'c> Broadcast<'c> { pub async fn replay( &mut self, - channel: &channel::Id, + channel: &Channel, resume_at: Option<&DateTime>, ) -> Result<Vec<Message>, sqlx::Error> { let messages = sqlx::query!( @@ -92,7 +87,7 @@ impl<'c> Broadcast<'c> { and coalesce(sent_at > $2, true) order by sent_at asc "#, - channel, + channel.id, resume_at, ) .map(|row| Message { |
