caracal 0.4.1

Nostr client for Gemini
use nostr::EventId;
pub use windmark_titanesque::context::RouteContext;

#[derive(Debug)]
pub enum Action {
    Empty,
    Go,
    New,
    Reuse,
    Reconnect,
    Unknown,
}

pub trait RouteGenie {
    fn draft_id(&self) -> Option<String>;
    fn event_id(&self) -> Option<EventId>;
    fn action(&self) -> Action;
    fn hashtag(&self) -> Option<String>;
}

impl RouteGenie for RouteContext {
    fn event_id(&self) -> Option<EventId> {
        self.parameters
            .get("event_id")
            .and_then(|id| EventId::parse(id).ok())
    }

    fn hashtag(&self) -> Option<String> {
        self.parameters.get("hashtag").map(str::to_string)
    }

    fn draft_id(&self) -> Option<String> {
        self.parameters.get("draft_id").map(str::to_string)
    }

    fn action(&self) -> Action {
        match self.parameters.get("action") {
            None => Action::Empty,
            Some("new") => Action::New,
            Some("reuse") => Action::Reuse,
            Some("reconnect") => Action::Reconnect,
            Some(_) => Action::Unknown,
        }
    }
}