From d17ce92f815fa145fa56307a7e9b3993e0f4270d Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 9 Oct 2024 23:46:16 -0400 Subject: Return an instance of the client when opening a channel URL directly. --- src/channel/app.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/channel/app.rs') diff --git a/src/channel/app.rs b/src/channel/app.rs index cb7ad32..7c0b107 100644 --- a/src/channel/app.rs +++ b/src/channel/app.rs @@ -2,7 +2,7 @@ use chrono::TimeDelta; use itertools::Itertools; use sqlx::sqlite::SqlitePool; -use super::{repo::Provider as _, Channel, Id}; +use super::{repo::Provider as _, Channel, History, Id}; use crate::{ clock::DateTime, db::NotFound, @@ -36,6 +36,16 @@ impl<'a> Channels<'a> { Ok(channel.as_created()) } + // This function is careless with respect to time, and gets you the channel as + // it exists in the specific moment when you call it. + pub async fn get(&self, channel: &Id) -> Result, sqlx::Error> { + let mut tx = self.db.begin().await?; + let channel = tx.channels().by_id(channel).await.optional()?; + tx.commit().await?; + + Ok(channel.iter().flat_map(History::events).collect()) + } + pub async fn delete(&self, channel: &Id, deleted_at: &DateTime) -> Result<(), Error> { let mut tx = self.db.begin().await?; -- cgit v1.2.3