From a15e3d580124f561864c6a39f1e035eb1b3aab13 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Mon, 30 Jun 2025 22:00:57 -0400 Subject: Rename "channel" to "conversation" within the server. I've split this from the schema and API changes because, frankly, it's huge. Annoyingly so. There are no semantic changes in this, it's all symbol changes, but there are a _lot_ of them because the term "channel" leaks all over everything in a service whose primary role is managing messages sent to channels (now, conversations). I found a buggy test while working on this! It's not fixed in this commit, because it felt mean to hide a real change in the middle of this much chaff. --- src/ui/handlers/channel.rs | 58 --------------------------------------- src/ui/handlers/conversation.rs | 61 +++++++++++++++++++++++++++++++++++++++++ src/ui/handlers/mod.rs | 4 +-- 3 files changed, 63 insertions(+), 60 deletions(-) delete mode 100644 src/ui/handlers/channel.rs create mode 100644 src/ui/handlers/conversation.rs (limited to 'src/ui') diff --git a/src/ui/handlers/channel.rs b/src/ui/handlers/channel.rs deleted file mode 100644 index d3199dd..0000000 --- a/src/ui/handlers/channel.rs +++ /dev/null @@ -1,58 +0,0 @@ -use axum::{ - extract::{Path, State}, - response::{self, IntoResponse, Redirect}, -}; - -use crate::{ - app::App, - channel::{self, app}, - error::Internal, - token::extract::Identity, - ui::{ - assets::{Asset, Assets}, - error::NotFound, - }, -}; - -pub async fn handler( - State(app): State, - identity: Option, - Path(channel): Path, -) -> Result { - let _ = identity.ok_or(Error::NotLoggedIn)?; - app.channels().get(&channel).await.map_err(Error::from)?; - - Assets::index().map_err(Error::Internal) -} - -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("channel not found")] - NotFound, - #[error("not logged in")] - NotLoggedIn, - #[error("{0}")] - Internal(Internal), -} - -impl From for Error { - fn from(error: app::Error) -> Self { - match error { - app::Error::NotFound(_) | app::Error::Deleted(_) => Self::NotFound, - other => Self::Internal(other.into()), - } - } -} - -impl IntoResponse for Error { - fn into_response(self) -> response::Response { - match self { - Self::NotFound => match Assets::index() { - Ok(asset) => NotFound(asset).into_response(), - Err(internal) => internal.into_response(), - }, - Self::NotLoggedIn => Redirect::temporary("/login").into_response(), - Self::Internal(error) => error.into_response(), - } - } -} diff --git a/src/ui/handlers/conversation.rs b/src/ui/handlers/conversation.rs new file mode 100644 index 0000000..f1bb319 --- /dev/null +++ b/src/ui/handlers/conversation.rs @@ -0,0 +1,61 @@ +use axum::{ + extract::{Path, State}, + response::{self, IntoResponse, Redirect}, +}; + +use crate::{ + app::App, + conversation::{self, app}, + error::Internal, + token::extract::Identity, + ui::{ + assets::{Asset, Assets}, + error::NotFound, + }, +}; + +pub async fn handler( + State(app): State, + identity: Option, + Path(conversation): Path, +) -> Result { + let _ = identity.ok_or(Error::NotLoggedIn)?; + app.conversations() + .get(&conversation) + .await + .map_err(Error::from)?; + + Assets::index().map_err(Error::Internal) +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("conversation not found")] + NotFound, + #[error("not logged in")] + NotLoggedIn, + #[error("{0}")] + Internal(Internal), +} + +impl From for Error { + fn from(error: app::Error) -> Self { + match error { + app::Error::NotFound(_) | app::Error::Deleted(_) => Self::NotFound, + other => Self::Internal(other.into()), + } + } +} + +impl IntoResponse for Error { + fn into_response(self) -> response::Response { + match self { + Self::NotFound => match Assets::index() { + Ok(asset) => NotFound(asset).into_response(), + Err(internal) => internal.into_response(), + }, + Self::NotLoggedIn => Redirect::temporary("/login").into_response(), + Self::Internal(error) => error.into_response(), + } + } +} diff --git a/src/ui/handlers/mod.rs b/src/ui/handlers/mod.rs index 5bfd0d6..ed0c14e 100644 --- a/src/ui/handlers/mod.rs +++ b/src/ui/handlers/mod.rs @@ -1,5 +1,5 @@ mod asset; -mod channel; +mod conversation; mod index; mod invite; mod login; @@ -7,7 +7,7 @@ mod me; mod setup; pub use asset::handler as asset; -pub use channel::handler as channel; +pub use conversation::handler as conversation; pub use index::handler as index; pub use invite::handler as invite; pub use login::handler as login; -- cgit v1.2.3