From: Michael Date: Tue, 8 Mar 2022 22:38:06 +0000 (+0000) Subject: API: Fixed the bookmarking X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38fbe281f9f774e8c0c9df1f5d36a8ecee08f34f;p=friendica.git API: Fixed the bookmarking --- diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php index f33b88728a..95a072889c 100644 --- a/src/Module/Api/Mastodon/Statuses/Bookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Bookmark.php @@ -42,7 +42,7 @@ class Bookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectFirst(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -51,6 +51,18 @@ class Bookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked')); } + if ($item['uid'] == 0) { + $stored = Item::storeForUserByUriId($this->parameters['id'], $uid); + if (!empty($stored)) { + $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); + if (!DBA::isResult($item)) { + DI::mstdnError()->RecordNotFound(); + } + } else { + DI::mstdnError()->RecordNotFound(); + } + } + Item::update(['starred' => true], ['id' => $item['id']]); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray()); diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php index 9dc9e73f90..103fac04af 100644 --- a/src/Module/Api/Mastodon/Statuses/Unbookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Unbookmark.php @@ -42,7 +42,7 @@ class Unbookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectFirst(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -51,6 +51,18 @@ class Unbookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked')); } + if ($item['uid'] == 0) { + $stored = Item::storeForUserByUriId($this->parameters['id'], $uid); + if (!empty($stored)) { + $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); + if (!DBA::isResult($item)) { + DI::mstdnError()->RecordNotFound(); + } + } else { + DI::mstdnError()->RecordNotFound(); + } + } + Item::update(['starred' => false], ['id' => $item['id']]); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());