summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-25 00:33:16 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-25 00:56:48 -0400
commit5423ec3937a4e28f3958a71b3db7498a4c427dc1 (patch)
tree8fc8531086c1691b0a9fc0a5ddb615d913dc6448 /src/ui
parenteae0edb57e9ade7c73affb78baf2ae267b6290b8 (diff)
Tests for purged channels and messages.
This required a re-think of the `.immediately()` combinator, to generalize it to cases where a message is _not_ expected. That (more or less immediately) suggested some mixed combinators, particularly for stream futures (futures of `Option<T>`).
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/mime.rs5
-rw-r--r--src/ui/routes/ch/channel.rs19
2 files changed, 13 insertions, 11 deletions
diff --git a/src/ui/mime.rs b/src/ui/mime.rs
index 9c724f0..7818ac1 100644
--- a/src/ui/mime.rs
+++ b/src/ui/mime.rs
@@ -1,7 +1,10 @@
use mime::Mime;
use unix_path::Path;
-// Extremely manual; using `std::path` here would result in platform-dependent behaviour when it's not appropriate (the URLs passed here always use `/` and are parsed like URLs). Using `unix_path` might be an option, but it's not clearly
+// Extremely manual; using `std::path` here would result in platform-dependent
+// behaviour when it's not appropriate (the URLs passed here always use `/` and
+// are parsed like URLs). Using `unix_path` might be an option, but it's not
+// clearly
pub fn from_path<P>(path: P) -> Result<Mime, mime::FromStrError>
where
P: AsRef<Path>,
diff --git a/src/ui/routes/ch/channel.rs b/src/ui/routes/ch/channel.rs
index a338f1f..a854f14 100644
--- a/src/ui/routes/ch/channel.rs
+++ b/src/ui/routes/ch/channel.rs
@@ -6,7 +6,7 @@ pub mod get {
use crate::{
app::App,
- channel,
+ channel::{self, app},
error::Internal,
token::extract::Identity,
ui::{
@@ -21,18 +21,14 @@ pub mod get {
Path(channel): Path<channel::Id>,
) -> Result<Asset, Error> {
let _ = identity.ok_or(Error::NotLoggedIn)?;
- app.channels()
- .get(&channel)
- .await
- .map_err(Error::internal)?
- .ok_or(Error::NotFound)?;
+ app.channels().get(&channel).await.map_err(Error::from)?;
Assets::index().map_err(Error::Internal)
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
- #[error("requested channel not found")]
+ #[error("channel not found")]
NotFound,
#[error("not logged in")]
NotLoggedIn,
@@ -40,9 +36,12 @@ pub mod get {
Internal(Internal),
}
- impl Error {
- fn internal(err: impl Into<Internal>) -> Self {
- Self::Internal(err.into())
+ impl From<app::Error> for Error {
+ fn from(error: app::Error) -> Self {
+ match error {
+ app::Error::NotFound(_) | app::Error::Deleted(_) => Self::NotFound,
+ other => Self::Internal(other.into()),
+ }
}
}