Handle nostr messages in separate module

This commit is contained in:
Mike Dilger committed 2024-02-17 09:53:47 +13:00
1 parent dddc05928c
commit f8c2f54005
2 files changed
+21 -2

No files matched your search

+7 -2
View File
@@ -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(
+14
View File
@@ -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(())
}
}