Skip to content

Commit

Permalink
implement getPostK method
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Dec 22, 2023
1 parent d05455f commit c190ced
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Currently not documented, please visit src/Client.php for details
* getBlockHash
* getBlock
* getPosts
* getPostK
* follow
* unFollow
* getFollowing
Expand Down
23 changes: 19 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function sendNewUserTransaction(string $userName, array &$errors = []): ?
);
}

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(
'/',
Expand All @@ -343,7 +343,7 @@ public function newPostMessage(string $userName, int $k, string $message, array
'params' =>
[
$userName,
$k,
$this->getPostK($userName, $k),
$message
],
'id' => time()
Expand All @@ -352,7 +352,7 @@ public function newPostMessage(string $userName, int $k, string $message, array
);
}

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(
'/',
Expand All @@ -363,7 +363,7 @@ public function newRetwistMessage(string $userName, int $k, string $sigUserPost,
'params' =>
[
$userName,
$k,
$this->getPostK($userName, $k),
[
'sig_userpost' => $sigUserPost,
'userpost' => $userPost,
Expand All @@ -375,4 +375,19 @@ public function newRetwistMessage(string $userName, int $k, string $sigUserPost,
$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;
}
}

0 comments on commit c190ced

Please sign in to comment.