From 871b56b79f0a15e2671e47757f953185ea23a22d Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 9 Jan 2022 14:12:55 +0200 Subject: [PATCH] fix initial post sending --- src/application/controller/api/post/add.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/application/controller/api/post/add.php b/src/application/controller/api/post/add.php index 875d2ba..5471a9b 100644 --- a/src/application/controller/api/post/add.php +++ b/src/application/controller/api/post/add.php @@ -7,17 +7,20 @@ $response = [ if (isset($_SESSION['userName'])) { - if (!$userPosts = $_twister->getPosts([$_SESSION['userName']], 1)) { + // Get post index + $postK = 1; - $response = [ - 'success' => false, - 'message' => _('Could not receive last user post') - ]; + if ($userPosts = $_twister->getPosts([$_SESSION['userName']], 1)) { + + if (isset($userPosts[0]['userpost']['k'])) { + $postK = Filter::int($userPosts[0]['userpost']['k']) + 1; + } + + } - } else if (isset($userPosts[0]['userpost']['k']) && - $result = $_twister->newPostMessage($_SESSION['userName'], - Filter::int($userPosts[0]['userpost']['k']) + 1, - Filter::post($_POST['message']))) { + if ($postK && $result = $_twister->newPostMessage($_SESSION['userName'], + $postK, + Filter::post($_POST['message']))) { $response = [ 'success' => true,