From 2fe0a631af837043f47223d46abb816c946c57e0 Mon Sep 17 00:00:00 2001 From: Sebastix Date: Thu, 4 Jul 2024 16:11:25 +0200 Subject: [PATCH] * add backwards compatibility in the __construct() of relay for the $message argument which was used in version < 1.2.4 * fix WebsocketClient response (message) which returned an array instead of a string for the json_decode function --- src/Application/Client.php | 2 +- src/Relay/Relay.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Application/Client.php b/src/Application/Client.php index c5ad8e2..ccc7b04 100644 --- a/src/Application/Client.php +++ b/src/Application/Client.php @@ -93,6 +93,6 @@ public function run($args): void protected function showHelp($message): void { print "\n[error] " . $message . "\n\nUsage:\n"; - print "nostr-php --content \"Hello world!\" --key /home/path/to/nostr-private.key --relay wss://nostr.pleb.network\n\n"; + print "bin/nostr-php --content \"Hello world!\" --key /home/path/to/nostr-private.key --relay wss://nostr.pleb.network\n\n"; } } diff --git a/src/Relay/Relay.php b/src/Relay/Relay.php index 93ebe9a..74fa7c0 100644 --- a/src/Relay/Relay.php +++ b/src/Relay/Relay.php @@ -38,9 +38,13 @@ class Relay implements RelayInterface * @param string $websocket * The socket URL. */ - public function __construct(string $websocket) + public function __construct(string $websocket, MessageInterface $message = null) { $this->url = $websocket; + // Backwards compatibility for version <1.2.4 + if ($message !== null) { + $this->setMessage($message); + } } /** @@ -87,7 +91,7 @@ public function send(): CommandResultInterface $client->text($this->payload); $response = $client->receive(); $client->disconnect(); - $response = json_decode($response); + $response = json_decode($response->getContent()); if ($response[0] === 'NOTICE') { throw new \RuntimeException($response[1]); }