Skip to content

Commit

Permalink
Publish nip33 event to update dispute status
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Dec 19, 2023
1 parent f7d38ee commit d8eec5d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::nip33::new_event;
use crate::util::send_dm;

use anyhow::Result;
Expand All @@ -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,
Expand All @@ -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?;

Expand All @@ -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?;

Expand All @@ -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),
Expand All @@ -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(())
}

0 comments on commit d8eec5d

Please sign in to comment.