diff --git a/nostr/nostr_client.py b/nostr/nostr_client.py index 965c827..b788072 100644 --- a/nostr/nostr_client.py +++ b/nostr/nostr_client.py @@ -68,8 +68,8 @@ class NostrClient: await self.send_req_queue.put(["EVENT", e.dict()]) async def subscribe_to_direct_messages(self, public_key: str, since: int): - in_messages_filter = {"kind": 4, "#p": [public_key]} - out_messages_filter = {"kind": 4, "authors": [public_key]} + in_messages_filter = {"kinds": [4], "#p": [public_key]} + out_messages_filter = {"kinds": [4], "authors": [public_key]} if since and since != 0: in_messages_filter["since"] = since out_messages_filter["since"] = since @@ -82,8 +82,8 @@ class NostrClient: ) async def subscribe_to_merchant_events(self, public_key: str, since: int): - stall_filter = {"kind": 30017, "authors": [public_key]} - product_filter = {"kind": 30018, "authors": [public_key]} + stall_filter = {"kinds": [30017], "authors": [public_key]} + product_filter = {"kinds": [30018], "authors": [public_key]} await self.send_req_queue.put( ["REQ", f"stall-events:{public_key}", stall_filter] @@ -93,7 +93,7 @@ class NostrClient: ) async def subscribe_to_user_profile(self, public_key: str, since: int): - profile_filter = {"kind": 0, "authors": [public_key]} + profile_filter = {"kinds": [0], "authors": [public_key]} if since and since != 0: profile_filter["since"] = since + 1 diff --git a/services.py b/services.py index 827960b..6a878ed 100644 --- a/services.py +++ b/services.py @@ -315,6 +315,11 @@ async def _handle_dirrect_message( incoming=True, ) await create_direct_message(merchant_id, dm) + await websocketUpdater( + merchant_id, + json.dumps({"type": "new-direct-message", "customerPubkey": from_pubkey}), + ) + if order: order["public_key"] = from_pubkey order["merchant_public_key"] = merchant_public_key @@ -322,11 +327,6 @@ async def _handle_dirrect_message( order["event_created_at"] = event_created_at return await _handle_new_order(PartialOrder(**order)) - await websocketUpdater( - merchant_id, - json.dumps({"type": "new-direct-message", "customerPubkey": from_pubkey}), - ) - return None except Exception as ex: logger.warning(ex) @@ -355,10 +355,6 @@ async def _handle_new_customer(event, merchant): merchant.id, Customer(merchant_id=merchant.id, public_key=event.pubkey) ) await nostr_client.subscribe_to_user_profile(event.pubkey, 0) - await websocketUpdater( - merchant.id, - json.dumps({"type": "new-customer"}), - ) async def _handle_customer_profile_update(event: NostrEvent): diff --git a/static/js/index.js b/static/js/index.js index 2a8c6be..6593430 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -85,6 +85,7 @@ const merchant = async () => { type: 'positive', message: 'Merchant Created!' }) + this.waitForNotifications() } catch (error) { LNbits.utils.notifyApiError(error) } @@ -108,6 +109,7 @@ const merchant = async () => { this.orderPubkey = customerPubkey }, waitForNotifications: async function () { + if (!this.merchant) return try { const scheme = location.protocol === 'http:' ? 'ws' : 'wss' const port = location.port ? `:${location.port}` : '' @@ -122,7 +124,6 @@ const merchant = async () => { message: 'New Order' }) await this.$refs.orderListRef.addOrder(data) - } else if (data.type === 'new-customer') { } else if (data.type === 'new-direct-message') { await this.$refs.directMessagesRef.handleNewMessage(data) } @@ -131,7 +132,7 @@ const merchant = async () => { this.$q.notify({ timeout: 5000, type: 'warning', - message: 'Failed to watch for updated', + message: 'Failed to watch for updates', caption: `${error}` }) }