From ba191cabbce5e741fa72a0e9213f76681d52e2d2 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 16 Feb 2023 17:54:47 +0200 Subject: [PATCH] feat: do not broadcast direct messages in AUTH mode --- models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/models.py b/models.py index 7f29bf2..3953010 100644 --- a/models.py +++ b/models.py @@ -173,6 +173,10 @@ class NostrEvent(BaseModel): def is_auth_response_event(self) -> bool: return self.kind == 22242 + @property + def is_direct_message(self) -> bool: + return self.kind == 4 + @property def is_delete_event(self) -> bool: return self.kind == 5 @@ -206,6 +210,12 @@ class NostrEvent(BaseModel): def tag_values(self, tag_name: str) -> List[str]: return [t[1] for t in self.tags if t[0] == tag_name] + def has_tag_value(self, tag_name: str, tag_value: str) -> bool: + return tag_value in self.tag_values(tag_name) + + def is_direct_message_for_pubkey(self, pubkey: str) -> bool: + return self.is_direct_message and self.has_tag_value("p", pubkey) + @classmethod def from_row(cls, row: Row) -> "NostrEvent": return cls(**dict(row))