Fix REQ message handling to support multiple filter subscriptions (#34)
This fix addresses an issue where REQ messages with multiple filters were being rejected by the relay. Notably: The nostrmarket extension's "Refresh from Nostr" functionality sends a single REQ message containing 4 different filter subscriptions: - Direct Messages (kinds: [4]) - Stalls (kinds: [30017]) - Products (kinds: [30018]) - Profile (kinds: [0]) Changes: - Changed validation from `len(data) != 3` to `len(data) < 3` to allow multiple filters - Added loop to process all filters in a single REQ message (data[2:]) - Accumulate responses from all filters before returning This ensures compatibility with clients that batch multiple subscription filters in a single REQ message, which is a valid pattern according to NIP-01.
This commit is contained in:
parent
5a1a400f45
commit
687d7b89c1
1 changed files with 8 additions and 2 deletions
|
|
@ -115,9 +115,15 @@ class NostrClientConnection:
|
||||||
await self._handle_event(event)
|
await self._handle_event(event)
|
||||||
return []
|
return []
|
||||||
if message_type == NostrEventType.REQ:
|
if message_type == NostrEventType.REQ:
|
||||||
if len(data) != 3:
|
if len(data) < 3:
|
||||||
return []
|
return []
|
||||||
return await self._handle_request(data[1], NostrFilter.parse_obj(data[2]))
|
subscription_id = data[1]
|
||||||
|
# Handle multiple filters in REQ message
|
||||||
|
responses = []
|
||||||
|
for filter_data in data[2:]:
|
||||||
|
response = await self._handle_request(subscription_id, NostrFilter.parse_obj(filter_data))
|
||||||
|
responses.extend(response)
|
||||||
|
return responses
|
||||||
if message_type == NostrEventType.CLOSE:
|
if message_type == NostrEventType.CLOSE:
|
||||||
self._handle_close(data[1])
|
self._handle_close(data[1])
|
||||||
if message_type == NostrEventType.AUTH:
|
if message_type == NostrEventType.AUTH:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue