summaryrefslogtreecommitdiff
path: root/src/message/repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/message/repo.rs')
-rw-r--r--src/message/repo.rs15
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 {