From c190ced5425620783c30e7baa76966270d282b33 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 22 Dec 2023 04:29:33 +0200 Subject: [PATCH] implement getPostK method --- README.md | 1 + src/Client.php | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40fbcac..fa113e5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Currently not documented, please visit src/Client.php for details * getBlockHash * getBlock * getPosts +* getPostK * follow * unFollow * getFollowing diff --git a/src/Client.php b/src/Client.php index 072703e..aa994ea 100644 --- a/src/Client.php +++ b/src/Client.php @@ -332,7 +332,7 @@ class Client ); } - public function newPostMessage(string $userName, int $k, string $message, array &$errors = []): ?array + public function newPostMessage(string $userName, string $message, ?int $k = null, array &$errors = []): ?array { return $this->_exec( '/', @@ -343,7 +343,7 @@ class Client 'params' => [ $userName, - $k, + $this->getPostK($userName, $k), $message ], 'id' => time() @@ -352,7 +352,7 @@ class Client ); } - public function newRetwistMessage(string $userName, int $k, string $sigUserPost, array $userPost, string $comment, array &$errors = []): ?array + public function newRetwistMessage(string $userName, string $sigUserPost, array $userPost, string $comment, ?int $k = null, array &$errors = []): ?array { return $this->_exec( '/', @@ -363,7 +363,7 @@ class Client 'params' => [ $userName, - $k, + $this->getPostK($userName, $k), [ 'sig_userpost' => $sigUserPost, 'userpost' => $userPost, @@ -375,4 +375,19 @@ class Client $errors ); } + + public function getPostK(string $userName, ?int $k = null): ?int + { + if (is_null($k)) + { + if (null === $posts = $this->getPosts([$userName], 1)) + { + return null; + } + + return isset($posts['result'][0]['userpost']['k']) ? (int) $posts['result'][0]['userpost']['k'] + 1 : 1; + } + + return $k; + } } \ No newline at end of file