fix expiration handling (#32)
This commit is contained in:
parent
3c52d5d49d
commit
08070257f8
1 changed files with 12 additions and 1 deletions
13
nwcp.py
13
nwcp.py
|
|
@ -378,6 +378,17 @@ class NWCServiceProvider:
|
|||
sent_events.append(res)
|
||||
return sent_events
|
||||
|
||||
def _extract_expiration_from_tags(self, tags: list) -> int:
|
||||
expiration = -1
|
||||
for tag in tags:
|
||||
try:
|
||||
if tag[0] == "expiration" and len(tag) > 1:
|
||||
expiration = int(tag[1])
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
return expiration
|
||||
|
||||
async def _on_event_message(self, msg):
|
||||
if not self.sub:
|
||||
return
|
||||
|
|
@ -387,7 +398,7 @@ class NWCServiceProvider:
|
|||
if not self._verify_event(event):
|
||||
raise Exception("Invalid event signature")
|
||||
tags = event["tags"]
|
||||
expiration = int(next((tag for tag in tags if tag[0] == "expiration"), -1))
|
||||
expiration = self._extract_expiration_from_tags(tags)
|
||||
# Handle event expiration if the relay doesn't support nip 40
|
||||
if expiration > 0 and expiration < int(time.time()):
|
||||
logger.debug("Event expired")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue