diff --git a/src/main.rs b/src/main.rs index e82186c..b859adc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,7 +102,7 @@ async fn main() -> Result<()> { match valid_invoice { Ok(_) => { - send_order_id_cmd(&client, &my_key, mostro_key, takesell_message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, takesell_message, true).await?; std::process::exit(0); } Err(e) => println!("{}", e), @@ -122,7 +122,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, takebuy_message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, takebuy_message, false).await?; std::process::exit(0); } Some(cli::Commands::GetDm { since }) => { @@ -158,7 +158,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, message, false).await?; std::process::exit(0); } Some(cli::Commands::Neworder { @@ -214,7 +214,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, message, false).await?; std::process::exit(0); } None => {} diff --git a/src/types.rs b/src/types.rs index d591df5..cb2a667 100644 --- a/src/types.rs +++ b/src/types.rs @@ -100,6 +100,7 @@ pub struct Message { pub enum Content { Order(Order), PaymentRequest(String), + PayHoldInvoice(Order, String), } #[allow(dead_code)] diff --git a/src/util.rs b/src/util.rs index 002cf9e..916ebd7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,6 @@ +use crate::types::Content; use crate::types::Kind as Orderkind; +use crate::types::Message; use crate::types::Order; use crate::types::Status; use anyhow::{Error, Result}; @@ -30,7 +32,7 @@ pub async fn send_dm( info!("Sending event: {event:#?}"); // This will update relay send event to wait for tranmission. if let Some(_wait_mes) = wait_for_connection { - let opts = Options::new().wait_for_send(true); + let opts = Options::new().wait_for_send(false); client.update_opts(opts); } client.send_event(event).await?; @@ -71,7 +73,7 @@ pub async fn connect_nostr() -> Result { for r in relays.into_iter() { client.add_relay(r, None).await?; } - let opts = Options::new().wait_for_connection(true); + let opts = Options::new().wait_for_connection(false); client.update_opts(opts); // Connect to relays and keep connection alive @@ -85,14 +87,40 @@ pub async fn send_order_id_cmd( my_key: &Keys, mostro_pubkey: XOnlyPublicKey, message: String, + wait_for_dm_ans: bool, ) -> Result<()> { // Send dm to mostro pub id - send_dm(client, my_key, &mostro_pubkey, message, Some(true)).await?; + send_dm(client, my_key, &mostro_pubkey, message, Some(false)).await?; let mut notifications = client.notifications(); while let Ok(notification) = notifications.recv().await { - if let RelayPoolNotification::Message( + if wait_for_dm_ans { + let dm = get_direct_messages(client, mostro_pubkey, my_key, 1).await; + + for el in dm.iter() { + match Message::from_json(&el.0) { + Ok(m) => { + if let Some(Content::PayHoldInvoice(ord, inv)) = m.content { + println!("NEW MESSAGE:"); + println!( + "Mostro sent you this hold invoice for order id: {}", + ord.id.unwrap() + ); + println!(); + println!("Pay this invoice --> {}", inv); + println!();println!(); + } + } + Err(_) => { + println!("NEW MESSAGE:"); + println!("Mostro sent you this message --> {}", el.0); + println!();println!(); + } + } + } + break; + } else if let RelayPoolNotification::Message( _, RelayMessage::Ok { event_id: _,