summaryrefslogtreecommitdiff
path: root/src/channel/app.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-09 23:46:16 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-10 19:32:49 -0400
commitd17ce92f815fa145fa56307a7e9b3993e0f4270d (patch)
treea23ba5a37984397607386a5c1e30f6619d62bace /src/channel/app.rs
parent03f8d9ad603a4e523a0e2a0e60ad62c8725f0875 (diff)
Return an instance of the client when opening a channel URL directly.
Diffstat (limited to 'src/channel/app.rs')
-rw-r--r--src/channel/app.rs12
1 files changed, 11 insertions, 1 deletions
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<Option<Channel>, 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?;