diff --git a/src/main.rs b/src/main.rs index baae471..317a700 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ include!("macros.rs"); pub mod config; pub mod error; pub mod globals; +pub mod nostr; pub mod reply; pub mod store; pub mod tls; @@ -223,8 +224,12 @@ impl WebSocketService { match message { Message::Text(msg) => { log::debug!("{}: <= {}", self.peer, msg); - let reply = NostrReply::Notice("error: Not Yet Implemented".to_string()); - self.websocket.send(Message::text(reply.as_json())).await?; + // This is defined in nostr.rs + if let Err(e) = self.handle_nostr_message(msg).await { + log::error!("{e}"); + let reply = NostrReply::Notice(format!("error: {}", e)); + self.websocket.send(Message::text(reply.as_json())).await?; + } } Message::Binary(msg) => { let reply = NostrReply::Notice( diff --git a/src/nostr.rs b/src/nostr.rs new file mode 100644 index 0000000..5ff31de --- /dev/null +++ b/src/nostr.rs @@ -0,0 +1,14 @@ +use crate::error::Error; +use crate::reply::NostrReply; +use crate::WebSocketService; +use futures::SinkExt; +use hyper_tungstenite::tungstenite::Message; + +impl WebSocketService { + pub async fn handle_nostr_message(&mut self, msg: String) -> Result<(), Error> { + log::warn!("Received unhandled text message: {}", msg); + let reply = NostrReply::Notice("NIP-01 is not yet fully supported".to_owned()); + self.websocket.send(Message::text(reply.as_json())).await?; + Ok(()) + } +}