]> git.mxchange.org Git - friendica.git/commitdiff
API: Fixed the bookmarking
authorMichael <heluecht@pirati.ca>
Tue, 8 Mar 2022 22:38:06 +0000 (22:38 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 8 Mar 2022 22:38:06 +0000 (22:38 +0000)
src/Module/Api/Mastodon/Statuses/Bookmark.php
src/Module/Api/Mastodon/Statuses/Unbookmark.php

index f33b88728af3ec6cb1b619e1ec995972c34af3ba..95a072889c3c9969f0fc77dcaf134408cdcdccfc 100644 (file)
@@ -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());
index 9dc9e73f9009e4c53b0b88bb4da5af48b8fe9a3e..103fac04afaa4891569b81cc71fb8a0a7acfc44e 100644 (file)
@@ -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());