diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-07-01 01:42:38 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-07-03 21:47:41 -0400 |
| commit | b4db819ef8daa583a165aed01eb3d70d98e37fc8 (patch) | |
| tree | 81f18139d11f6f197f90958a7a28a83aab6c14cf /src/message/repo.rs | |
| parent | b3ce81945621e9026e687b590e7aa541008575ac (diff) | |
Prevent sending messages to deleted channels.
I've opted to make it clear in the error message which scenario - deleted vs. non-existant - a channel falls into. This isn't particularly consistent with the rest of the API, so we might need to review this decision later, but it's at least relatively harmless if it's mistaken. (Formally, they're both 404s, so clients that go by error code won't notice.)
Diffstat (limited to 'src/message/repo.rs')
| -rw-r--r-- | src/message/repo.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/message/repo.rs b/src/message/repo.rs index 9a4f72f..e753134 100644 --- a/src/message/repo.rs +++ b/src/message/repo.rs @@ -2,7 +2,7 @@ use sqlx::{SqliteConnection, Transaction, sqlite::Sqlite}; use super::{Body, History, Id, snapshot::Message}; use crate::{ - channel, + channel::{self, Channel}, clock::DateTime, event::{Instant, Sequence}, user::{self, User}, @@ -23,13 +23,12 @@ pub struct Messages<'t>(&'t mut SqliteConnection); impl Messages<'_> { pub async fn create( &mut self, - channel: &channel::History, + channel: &Channel, sender: &User, sent: &Instant, body: &Body, ) -> Result<History, sqlx::Error> { let id = Id::generate(); - let channel_id = channel.id(); let message = sqlx::query!( r#" @@ -45,7 +44,7 @@ impl Messages<'_> { body as "body: Body" "#, id, - channel_id, + channel.id, sender.id, sent.at, sent.sequence, |
