mostro_client/cli/
dm_to_user.rs

1use crate::parser::common::{
2    print_info_line, print_key_value, print_section_header, print_success_message,
3};
4use crate::{db::Order, util::send_gift_wrap_dm};
5use anyhow::Result;
6use nostr_sdk::prelude::*;
7use sqlx::SqlitePool;
8use uuid::Uuid;
9
10pub async fn execute_dm_to_user(
11    receiver: PublicKey,
12    client: &Client,
13    order_id: &Uuid,
14    message: &str,
15    pool: &SqlitePool,
16) -> Result<()> {
17    // Get the order
18    let order = Order::get_by_id(pool, &order_id.to_string())
19        .await
20        .map_err(|_| anyhow::anyhow!("order {} not found", order_id))?;
21    // Get the trade keys
22    let trade_keys = match order.trade_keys.as_ref() {
23        Some(trade_keys) => Keys::parse(trade_keys)?,
24        None => anyhow::bail!("No trade_keys found for this order"),
25    };
26
27    // Send the DM
28    print_section_header("💬 Direct Message to User");
29    print_key_value("📋", "Order ID", &order_id.to_string());
30    print_key_value("🔑", "Trade Keys", &trade_keys.public_key().to_hex());
31    print_key_value("🎯", "Recipient", &receiver.to_string());
32    print_key_value("💬", "Message", message);
33    print_info_line("💡", "Sending gift wrap message...");
34    println!();
35
36    send_gift_wrap_dm(client, &trade_keys, &receiver, message).await?;
37
38    print_success_message("Gift wrap message sent successfully!");
39
40    Ok(())
41}