fix: add orders to direct_messages table

This commit is contained in:
Vlad Stan 2023-03-24 16:55:23 +02:00
parent b0890b8ebb
commit c583af3c33
2 changed files with 11 additions and 11 deletions

View file

@ -78,7 +78,7 @@ def order_from_json(s: str) -> Tuple[Optional[Any], Optional[str]]:
try: try:
order = json.loads(s) order = json.loads(s)
return ( return (
(order, None) if (type(order) is dict) and "items" in order else (None, s) (order, s) if (type(order) is dict) and "items" in order else (None, s)
) )
except ValueError: except ValueError:
return None, s return None, s

View file

@ -272,22 +272,22 @@ async def _handle_dirrect_message(
) -> Optional[str]: ) -> Optional[str]:
order, text_msg = order_from_json(msg) order, text_msg = order_from_json(msg)
try: try:
dm = PartialDirectMessage(
event_id=event_id,
event_created_at=event_created_at,
message=text_msg,
public_key=from_pubkey,
incoming=True,
)
await create_direct_message(merchant_id, dm)
if order: if order:
order["public_key"] = from_pubkey order["public_key"] = from_pubkey
order["merchant_public_key"] = merchant_public_key order["merchant_public_key"] = merchant_public_key
order["event_id"] = event_id order["event_id"] = event_id
order["event_created_at"] = event_created_at order["event_created_at"] = event_created_at
return await _handle_new_order(PartialOrder(**order)) return await _handle_new_order(PartialOrder(**order))
else:
dm = PartialDirectMessage( return None
event_id=event_id,
event_created_at=event_created_at,
message=text_msg,
public_key=from_pubkey,
incoming=True,
)
await create_direct_message(merchant_id, dm)
return None
except Exception as ex: except Exception as ex:
logger.warning(ex) logger.warning(ex)
return None return None