This splits notedeck into crates, separating the browser chrome and individual apps: * notedeck: binary file, browser chrome * notedeck_columns: our columns app * enostr: same as before We still need to do more work to cleanly separate the chrome apis from the app apis. Soon I will create notedeck-notebook to see what makes sense to be shared between the apps. Some obvious ones that come to mind: 1. ImageCache We will likely want to move this to the notedeck crate, as most apps will want some kind of image cache. In web browsers, web pages do not need to worry about this, so we will likely have to do something similar 2. Ndb Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely copied to each app. This will simplify things. In the future we might want to create an abstraction over this? Maybe each app shouldn't have access to the same database... we assume the data in DBs are all public anyways, but if we have unwrapped giftwraps that could be a problem. 3. RelayPool / Subscription Manager The browser should probably maintain these. Then apps can use ken's high level subscription manager api and not have to worry about connection pool details 4. Accounts Accounts and key management should be handled by the chrome. Apps should only have a simple signer interface. That's all for now, just something to think about! Signed-off-by: William Casarin <jb55@jb55.com>
127 lines
3.0 KiB
Rust
127 lines
3.0 KiB
Rust
use std::{fmt, io};
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
|
pub enum FilterError {
|
|
EmptyContactList,
|
|
}
|
|
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
pub enum SubscriptionError {
|
|
//#[error("No active subscriptions")]
|
|
NoActive,
|
|
|
|
/// When a timeline has an unexpected number
|
|
/// of active subscriptions. Should only happen if there
|
|
/// is a bug in notedeck
|
|
//#[error("Unexpected subscription count")]
|
|
UnexpectedSubscriptionCount(i32),
|
|
}
|
|
|
|
impl Error {
|
|
pub fn unexpected_sub_count(c: i32) -> Self {
|
|
Error::SubscriptionError(SubscriptionError::UnexpectedSubscriptionCount(c))
|
|
}
|
|
|
|
pub fn no_active_sub() -> Self {
|
|
Error::SubscriptionError(SubscriptionError::NoActive)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for SubscriptionError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::NoActive => write!(f, "No active subscriptions"),
|
|
Self::UnexpectedSubscriptionCount(c) => {
|
|
write!(f, "Unexpected subscription count: {}", c)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
TimelineNotFound,
|
|
LoadFailed,
|
|
SubscriptionError(SubscriptionError),
|
|
Filter(FilterError),
|
|
Io(io::Error),
|
|
Nostr(enostr::Error),
|
|
Ndb(nostrdb::Error),
|
|
Image(image::error::ImageError),
|
|
Generic(String),
|
|
}
|
|
|
|
impl Error {
|
|
pub fn empty_contact_list() -> Self {
|
|
Error::Filter(FilterError::EmptyContactList)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for FilterError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::EmptyContactList => {
|
|
write!(f, "empty contact list")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::SubscriptionError(e) => {
|
|
write!(f, "{e}")
|
|
}
|
|
Self::TimelineNotFound => write!(f, "Timeline not found"),
|
|
Self::LoadFailed => {
|
|
write!(f, "load failed")
|
|
}
|
|
Self::Filter(e) => {
|
|
write!(f, "{e}")
|
|
}
|
|
Self::Nostr(e) => write!(f, "{e}"),
|
|
Self::Ndb(e) => write!(f, "{e}"),
|
|
Self::Image(e) => write!(f, "{e}"),
|
|
Self::Generic(e) => write!(f, "{e}"),
|
|
Self::Io(e) => write!(f, "{e}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<String> for Error {
|
|
fn from(s: String) -> Self {
|
|
Error::Generic(s)
|
|
}
|
|
}
|
|
|
|
impl From<nostrdb::Error> for Error {
|
|
fn from(e: nostrdb::Error) -> Self {
|
|
Error::Ndb(e)
|
|
}
|
|
}
|
|
|
|
impl From<image::error::ImageError> for Error {
|
|
fn from(err: image::error::ImageError) -> Self {
|
|
Error::Image(err)
|
|
}
|
|
}
|
|
|
|
impl From<enostr::Error> for Error {
|
|
fn from(err: enostr::Error) -> Self {
|
|
Error::Nostr(err)
|
|
}
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
fn from(err: io::Error) -> Self {
|
|
Error::Io(err)
|
|
}
|
|
}
|
|
|
|
impl From<FilterError> for Error {
|
|
fn from(err: FilterError) -> Self {
|
|
Error::Filter(err)
|
|
}
|
|
}
|