Skip to content

Commit

Permalink
Add field ids and setter method setIds to Filter class so we can fetc…
Browse files Browse the repository at this point in the history
…h events with id's
  • Loading branch information
Sebastix committed Jul 2, 2024
1 parent dad5acf commit 51c0376
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,15 +48,27 @@ 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.
*
* @param array $pubkey The array of authors to set.
*/
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");
}
}
Expand All @@ -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");
}
}
Expand All @@ -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");
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 51c0376

Please sign in to comment.