Skip to content

Commit

Permalink
improve example snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastix committed Nov 5, 2024
1 parent c8083fe commit 90dc8b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/Examples/request-events-filtered-with-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use swentel\nostr\Filter\Filter;
use swentel\nostr\Message\RequestMessage;
use swentel\nostr\Relay\Relay;
use swentel\nostr\RelayResponse\RelayResponse;
use swentel\nostr\RelayResponse\RelayResponseEvent;
use swentel\nostr\Request\Request;
use swentel\nostr\Subscription\Subscription;

Expand Down Expand Up @@ -57,10 +59,12 @@
*/
foreach ($response as $relayUrl => $relayResponses) {
print 'Received ' . count($response[$relayUrl]) . ' message(s) received from relay ' . $relayUrl . PHP_EOL;
/** @var \swentel\nostr\RelayResponse\RelayResponseEvent $message */
/** @var RelayResponse $relayResponse */
foreach ($relayResponses as $relayResponse) {
if (isset($relayResponse->event->content)) {
print $relayResponse->event->content . PHP_EOL;
if ($relayResponse instanceof RelayResponseEvent) {
if (isset($relayResponse->event->content)) {
print $relayResponse->event->content . PHP_EOL;
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Examples/request-events-with-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
$request = new Request($relay, $requestMessage);
$response = $request->send();

foreach ($response as $relay => $messages) {
foreach ($response as $relay => $relayResponses) {
print 'Received ' . count($response[$relay]) . ' message(s) received from relay ' . $relay . PHP_EOL;
foreach ($messages as $message) {
print $message->type . ': ' . $message->message . PHP_EOL;
if ($message instanceof RelayResponseEvent) {
$rawEvent = $message->event;
foreach ($relayResponses as $relayResponse) {
print 'Relay response ' . $relayResponse->type . ': ' . $relayResponse->message . PHP_EOL;
if ($relayResponse instanceof RelayResponseEvent) {
$rawEvent = $relayResponse->event;
$event = new Event();
$event->setId($rawEvent->id);
$event->setPublicKey($rawEvent->pubkey);
Expand Down

0 comments on commit 90dc8b9

Please sign in to comment.