summaryrefslogtreecommitdiff
path: root/src/channel/app.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-09-17 19:06:20 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-09-17 19:06:20 -0400
commit921f38a73e5d58a5a6077477a8b52d2705798f55 (patch)
tree895eee6c31a9e6003e4d199e32eb04bcb32f8f11 /src/channel/app.rs
parente6be82157fe718570aa13ab12803ee39083b8dff (diff)
Express record dependencies through types.
This provides a convenient place to _stick_ "not found" errors, though actually introducing them will come in a later commit.
Diffstat (limited to 'src/channel/app.rs')
-rw-r--r--src/channel/app.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/channel/app.rs b/src/channel/app.rs
index b0b63b3..29d9c09 100644
--- a/src/channel/app.rs
+++ b/src/channel/app.rs
@@ -55,13 +55,14 @@ impl<'a> Channels<'a> {
sent_at: &DateTime,
) -> Result<(), BoxedError> {
let mut tx = self.db.begin().await?;
+ let channel = tx.channels().by_id(channel).await?;
let message = tx
.broadcast()
- .create(&login.id, channel, body, sent_at)
+ .create(login, &channel, body, sent_at)
.await?;
tx.commit().await?;
- self.broadcaster.broadcast(channel, message);
+ self.broadcaster.broadcast(&channel.id, message);
Ok(())
}
@@ -71,6 +72,9 @@ impl<'a> Channels<'a> {
resume_at: Option<&DateTime>,
) -> Result<impl Stream<Item = Result<broadcast::Message, BoxedError>> + 'static, BoxedError>
{
+ let mut tx = self.db.begin().await?;
+ let channel = tx.channels().by_id(channel).await?;
+
fn skip_stale<E>(
resume_at: Option<&DateTime>,
) -> impl for<'m> FnMut(&'m broadcast::Message) -> future::Ready<Result<bool, E>> {
@@ -85,12 +89,11 @@ impl<'a> Channels<'a> {
let live_messages = self
.broadcaster
- .listen(channel)
+ .listen(&channel.id)
.map_err(BoxedError::from)
.try_skip_while(skip_stale(resume_at));
- let mut tx = self.db.begin().await?;
- let stored_messages = tx.broadcast().replay(channel, resume_at).await?;
+ let stored_messages = tx.broadcast().replay(&channel, resume_at).await?;
tx.commit().await?;
let stored_messages = stream::iter(stored_messages).map(Ok);