fix: filter and notifications
This commit is contained in:
parent
d106879a09
commit
62737e7a79
3 changed files with 13 additions and 16 deletions
|
|
@ -68,8 +68,8 @@ class NostrClient:
|
||||||
await self.send_req_queue.put(["EVENT", e.dict()])
|
await self.send_req_queue.put(["EVENT", e.dict()])
|
||||||
|
|
||||||
async def subscribe_to_direct_messages(self, public_key: str, since: int):
|
async def subscribe_to_direct_messages(self, public_key: str, since: int):
|
||||||
in_messages_filter = {"kind": 4, "#p": [public_key]}
|
in_messages_filter = {"kinds": [4], "#p": [public_key]}
|
||||||
out_messages_filter = {"kind": 4, "authors": [public_key]}
|
out_messages_filter = {"kinds": [4], "authors": [public_key]}
|
||||||
if since and since != 0:
|
if since and since != 0:
|
||||||
in_messages_filter["since"] = since
|
in_messages_filter["since"] = since
|
||||||
out_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):
|
async def subscribe_to_merchant_events(self, public_key: str, since: int):
|
||||||
stall_filter = {"kind": 30017, "authors": [public_key]}
|
stall_filter = {"kinds": [30017], "authors": [public_key]}
|
||||||
product_filter = {"kind": 30018, "authors": [public_key]}
|
product_filter = {"kinds": [30018], "authors": [public_key]}
|
||||||
|
|
||||||
await self.send_req_queue.put(
|
await self.send_req_queue.put(
|
||||||
["REQ", f"stall-events:{public_key}", stall_filter]
|
["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):
|
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:
|
if since and since != 0:
|
||||||
profile_filter["since"] = since + 1
|
profile_filter["since"] = since + 1
|
||||||
|
|
||||||
|
|
|
||||||
14
services.py
14
services.py
|
|
@ -315,6 +315,11 @@ async def _handle_dirrect_message(
|
||||||
incoming=True,
|
incoming=True,
|
||||||
)
|
)
|
||||||
await create_direct_message(merchant_id, dm)
|
await create_direct_message(merchant_id, dm)
|
||||||
|
await websocketUpdater(
|
||||||
|
merchant_id,
|
||||||
|
json.dumps({"type": "new-direct-message", "customerPubkey": from_pubkey}),
|
||||||
|
)
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -322,11 +327,6 @@ async def _handle_dirrect_message(
|
||||||
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))
|
||||||
|
|
||||||
await websocketUpdater(
|
|
||||||
merchant_id,
|
|
||||||
json.dumps({"type": "new-direct-message", "customerPubkey": from_pubkey}),
|
|
||||||
)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(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)
|
merchant.id, Customer(merchant_id=merchant.id, public_key=event.pubkey)
|
||||||
)
|
)
|
||||||
await nostr_client.subscribe_to_user_profile(event.pubkey, 0)
|
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):
|
async def _handle_customer_profile_update(event: NostrEvent):
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ const merchant = async () => {
|
||||||
type: 'positive',
|
type: 'positive',
|
||||||
message: 'Merchant Created!'
|
message: 'Merchant Created!'
|
||||||
})
|
})
|
||||||
|
this.waitForNotifications()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +109,7 @@ const merchant = async () => {
|
||||||
this.orderPubkey = customerPubkey
|
this.orderPubkey = customerPubkey
|
||||||
},
|
},
|
||||||
waitForNotifications: async function () {
|
waitForNotifications: async function () {
|
||||||
|
if (!this.merchant) return
|
||||||
try {
|
try {
|
||||||
const scheme = location.protocol === 'http:' ? 'ws' : 'wss'
|
const scheme = location.protocol === 'http:' ? 'ws' : 'wss'
|
||||||
const port = location.port ? `:${location.port}` : ''
|
const port = location.port ? `:${location.port}` : ''
|
||||||
|
|
@ -122,7 +124,6 @@ const merchant = async () => {
|
||||||
message: 'New Order'
|
message: 'New Order'
|
||||||
})
|
})
|
||||||
await this.$refs.orderListRef.addOrder(data)
|
await this.$refs.orderListRef.addOrder(data)
|
||||||
} else if (data.type === 'new-customer') {
|
|
||||||
} else if (data.type === 'new-direct-message') {
|
} else if (data.type === 'new-direct-message') {
|
||||||
await this.$refs.directMessagesRef.handleNewMessage(data)
|
await this.$refs.directMessagesRef.handleNewMessage(data)
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +132,7 @@ const merchant = async () => {
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: 'Failed to watch for updated',
|
message: 'Failed to watch for updates',
|
||||||
caption: `${error}`
|
caption: `${error}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue