From 51c03766b73eea1f62a04b89262333279250803a Mon Sep 17 00:00:00 2001 From: Sebastix Date: Tue, 2 Jul 2024 22:31:09 +0200 Subject: [PATCH] Add field ids and setter method setIds to Filter class so we can fetch events with id's --- src/Filter/Filter.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 870a908..6a208e2 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -11,7 +11,7 @@ class Filter implements FilterInterface /** * A list of event ids */ - public array $id; + public array $ids; /** * A list of lowercase pubkeys, the pubkey of an event must be one of these @@ -48,6 +48,18 @@ class Filter implements FilterInterface */ public int $limit; + /** + * Set the ids for filtering multiple events. + * + * @param array $ids + * @return $this + */ + public function setIds(array $ids): static + { + $this->ids = $ids; + return $this; + } + /** * Set the authors for the Filter object. * @@ -55,8 +67,8 @@ class Filter implements FilterInterface */ public function setAuthors(array $pubkeys): static { - foreach($pubkeys as $key) { - if(!$this->isLowercaseHex($key)) { + foreach ($pubkeys as $key) { + if (!$this->isLowercaseHex($key)) { throw new \RuntimeException("Author pubkeys must be an array of 64-character lowercase hex values"); } } @@ -82,8 +94,8 @@ public function setKinds(array $kinds): static */ public function setLowercaseETags(array $etags): static { - foreach($etags as $tag) { - if(!$this->isLowercaseHex($tag)) { + foreach ($etags as $tag) { + if (!$this->isLowercaseHex($tag)) { throw new \RuntimeException("#e tags must be an array of 64-character lowercase hex values"); } } @@ -99,8 +111,8 @@ public function setLowercaseETags(array $etags): static public function setLowercasePTags(array $ptags): static { // Check IF array contain exact 64-character lowercase hex values - foreach($ptags as $tag) { - if(!$this->isLowercaseHex($tag)) { + foreach ($ptags as $tag) { + if (!$this->isLowercaseHex($tag)) { throw new \RuntimeException("#p tags must be an array of 64-character lowercase hex values"); } } @@ -178,9 +190,9 @@ public function toArray(): array { $array = []; foreach (get_object_vars($this) as $key => $val) { - if($key === 'etags') { + if ($key === 'etags') { $array['#e'] = $val; - } elseif($key === 'ptags') { + } elseif ($key === 'ptags') { $array['#p'] = $val; } else { $array[$key] = $val;