@@ -16,11 +16,7 @@ use crate::{
1616use sqlx:: SqlitePool ;
1717
1818/// Execute logic of command answer
19- pub async fn print_commands_results (
20- message : & MessageKind ,
21- mut order : Option < Order > ,
22- ctx : & Context ,
23- ) -> Result < ( ) > {
19+ pub async fn print_commands_results ( message : & MessageKind , ctx : & Context ) -> Result < ( ) > {
2420 // Do the logic for the message response
2521 match message. action {
2622 Action :: NewOrder => {
@@ -48,7 +44,8 @@ pub async fn print_commands_results(
4844 // this is the case where the buyer adds an invoice to a takesell order
4945 Action :: WaitingSellerToPay => {
5046 println ! ( "Now we should wait for the seller to pay the invoice" ) ;
51- if let Some ( mut order) = order. take ( ) {
47+ if let Some ( order_id) = & message. id {
48+ let mut order = Order :: get_by_id ( & ctx. pool , & order_id. to_string ( ) ) . await ?;
5249 match order
5350 . set_status ( Status :: WaitingPayment . to_string ( ) )
5451 . save ( & ctx. pool )
@@ -199,6 +196,27 @@ pub async fn print_commands_results(
199196 Err ( anyhow:: anyhow!( "No trade index found in message" ) )
200197 }
201198 }
199+ Action :: DisputeInitiatedByYou => {
200+ if let Some ( Payload :: Dispute ( dispute_id, _) ) = & message. payload {
201+ println ! ( "Dispute initiated successfully with ID: {}" , dispute_id) ;
202+ if let Some ( order_id) = & message. id {
203+ let mut order = Order :: get_by_id ( & ctx. pool , & order_id. to_string ( ) ) . await ?;
204+ // Update order status to disputed if we have the order
205+ match order
206+ . set_status ( Status :: Dispute . to_string ( ) )
207+ . save ( & ctx. pool )
208+ . await
209+ {
210+ Ok ( _) => println ! ( "Order status updated to Dispute" ) ,
211+ Err ( e) => println ! ( "Failed to update order status: {}" , e) ,
212+ }
213+ }
214+ Ok ( ( ) )
215+ } else {
216+ println ! ( "Warning: Dispute initiated but received unexpected payload structure" ) ;
217+ Ok ( ( ) )
218+ }
219+ }
202220 Action :: HoldInvoicePaymentSettled => {
203221 println ! ( "Hold invoice payment settled" ) ;
204222 Ok ( ( ) )
@@ -226,15 +244,21 @@ pub async fn parse_dm_events(
226244 let unwrapped_gift = match nip59:: extract_rumor ( pubkey, dm) . await {
227245 Ok ( u) => u,
228246 Err ( e) => {
229- eprintln ! ( "Warning: Could not decrypt gift wrap (event {}): {}" , dm. id, e) ;
247+ eprintln ! (
248+ "Warning: Could not decrypt gift wrap (event {}): {}" ,
249+ dm. id, e
250+ ) ;
230251 continue ;
231252 }
232253 } ;
233254 let ( message, _) : ( Message , Option < String > ) =
234255 match serde_json:: from_str ( & unwrapped_gift. rumor . content ) {
235256 Ok ( msg) => msg,
236257 Err ( e) => {
237- eprintln ! ( "Warning: Could not parse message content (event {}): {}" , dm. id, e) ;
258+ eprintln ! (
259+ "Warning: Could not parse message content (event {}): {}" ,
260+ dm. id, e
261+ ) ;
238262 continue ;
239263 }
240264 } ;
0 commit comments