From d8eec5de4206d1c134b4d4894f273d78dd0ab46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Tue, 19 Dec 2023 18:25:19 -0300 Subject: [PATCH] Publish nip33 event to update dispute status --- src/app/admin_take_dispute.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/admin_take_dispute.rs b/src/app/admin_take_dispute.rs index d33e70d3..41f71497 100644 --- a/src/app/admin_take_dispute.rs +++ b/src/app/admin_take_dispute.rs @@ -1,3 +1,4 @@ +use crate::nip33::new_event; use crate::util::send_dm; use anyhow::Result; @@ -7,6 +8,7 @@ use mostro_core::order::Order; use nostr_sdk::prelude::*; use sqlx::{Pool, Sqlite}; use sqlx_crud::Crud; +use tracing::info; pub async fn admin_take_dispute_action( msg: Message, @@ -20,7 +22,11 @@ pub async fn admin_take_dispute_action( Some(dispute) => dispute, None => { // We create a Message - let message = Message::cant_do(None, None, None); + let message = Message::cant_do( + None, + None, + Some(Content::TextMessage("Dispute not found".to_string())), + ); let message = message.as_json()?; send_dm(client, my_keys, &event.pubkey, message).await?; @@ -34,7 +40,11 @@ pub async fn admin_take_dispute_action( // TODO: solvers also can take disputes if event.pubkey.to_string() != my_keys.public_key().to_string() { // We create a Message - let message = Message::cant_do(None, None, None); + let message = Message::cant_do( + None, + None, + Some(Content::TextMessage("Not allowed".to_string())), + ); let message = message.as_json()?; send_dm(client, my_keys, &event.pubkey, message).await?; @@ -47,7 +57,7 @@ pub async fn admin_take_dispute_action( dispute.taken_at = Timestamp::now().as_i64(); // Save it to DB dispute.update(pool).await?; - + info!("Dispute {} taken by {}", dispute_id, event.pubkey); // We create a Message for admin let message = Message::new_dispute( Some(dispute_id), @@ -59,5 +69,15 @@ pub async fn admin_take_dispute_action( // Send the message send_dm(client, my_keys, &event.pubkey, message.clone()).await?; + // We create a tag to show status of the dispute + let tags = vec![ + ("s".to_string(), "InProgress".to_string()), + ("data_label".to_string(), "dispute".to_string()), + ]; + // nip33 kind with dispute id as identifier + let event = new_event(my_keys, "", dispute_id.to_string(), tags)?; + info!("Dispute event to be published: {event:#?}"); + client.send_event(event).await?; + Ok(()) }