]> git.mxchange.org Git - friendica.git/commitdiff
API: Many item related endpoints added
authorMichael <heluecht@pirati.ca>
Sat, 15 May 2021 10:08:47 +0000 (10:08 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 15 May 2021 10:08:47 +0000 (10:08 +0000)
17 files changed:
doc/API-Mastodon.md
src/Factory/Api/Mastodon/Status.php
src/Module/Api/Mastodon/Notifications.php
src/Module/Api/Mastodon/Notifications/Clear.php [new file with mode: 0644]
src/Module/Api/Mastodon/Notifications/Dismiss.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses.php
src/Module/Api/Mastodon/Statuses/Bookmark.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Favourite.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Mute.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Pin.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Reblog.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Unbookmark.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Unfavourite.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Unmute.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Unpin.php [new file with mode: 0644]
src/Module/Api/Mastodon/Statuses/Unreblog.php [new file with mode: 0644]
static/routes.config.php

index 9a50d9e59823c45e5aa5fea348af0962efc0efce..cf5eaa923b77ef054d46a5e6dfdf45affed341bd 100644 (file)
@@ -84,11 +84,24 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
 - [`GET /api/v1/mutes`](https://docs.joinmastodon.org/methods/accounts/mutes/)
 - [`GET /api/v1/notifications`](https://docs.joinmastodon.org/methods/notifications/)
 - [`GET /api/v1/notifications/:id`](https://docs.joinmastodon.org/methods/notifications/)
+- [`POST /api/v1/notifications/clear`](https://docs.joinmastodon.org/methods/notifications/)
+- [`POST /api/v1/notifications/:id/dismiss`](https://docs.joinmastodon.org/methods/notifications/)
 - [`GET /api/v1/preferences`](https://docs.joinmastodon.org/methods/accounts/preferences/)
 - [`GET /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
+- [`DELETE /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
 - [`GET /api/v1/statuses/:id/context`](https://docs.joinmastodon.org/methods/statuses/)
 - [`GET /api/v1/statuses/:id/reblogged_by`](https://docs.joinmastodon.org/methods/statuses/)
 - [`GET /api/v1/statuses/:id/favourited_by`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/favourite`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/unfavourite`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/reblog`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/unreblog`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/bookmark`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/unbookmark`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/mute`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/unmute`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/pin`](https://docs.joinmastodon.org/methods/statuses/)
+- [`POST /api/v1/statuses/:id/unpin`](https://docs.joinmastodon.org/methods/statuses/)
 - [`GET /api/v1/suggestions`](https://docs.joinmastodon.org/methods/accounts/suggestions/)
 - [`GET /api/v1/timelines/home`](https://docs.joinmastodon.org/methods/timelines/)
 - [`GET /api/v1/timelines/list/:id`](https://docs.joinmastodon.org/methods/timelines/)
@@ -111,20 +124,7 @@ These emdpoints are planned to be implemented
 - [`GET /api/v1/instance/activity`](https://docs.joinmastodon.org/methods/instance#weekly-activity)
 - [`POST /api/v1/media`](https://docs.joinmastodon.org/methods/statuses/media/)
 - [`PUT /api/v1/media/:id`](https://docs.joinmastodon.org/methods/statuses/media/)
-- [`POST /api/v1/notifications/clear`](https://docs.joinmastodon.org/methods/notifications/)
-- [`POST /api/v1/notifications/:id/dismiss`](https://docs.joinmastodon.org/methods/notifications/)
 - [`POST /api/v1/statuses`](https://docs.joinmastodon.org/methods/statuses/)
-- [`DELETE /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/favourite`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/unfavourite`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/reblog`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/unreblog`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/bookmark`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/unbookmark`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/mute`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/unmute`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/pin`](https://docs.joinmastodon.org/methods/statuses/)
-- [`POST /api/v1/statuses/:id/unpin`](https://docs.joinmastodon.org/methods/statuses/)
 - [`GET /api/v1/timelines/direct`](https://docs.joinmastodon.org/methods/timelines/)
 
 ## Non supportable endpoints
index 866cfe8027af2684cf09c47082394e75c28a650a..cc8b7e6d87d6ee8bcbc3f56ca8ef6729244338c0 100644 (file)
@@ -71,14 +71,14 @@ class Status extends BaseFactory
                $account = DI::mstdnAccount()->createFromContactId($item['author-id']);
 
                $counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT], [], false),
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)], [], false),
-                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)], [], false)
+                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], [], false),
+                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false], [], false),
+                       Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false], [], false)
                );
 
                $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
-                       Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]),
-                       Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]),
+                       Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false]),
+                       Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false]),
                        Post\ThreadUser::getIgnored($uriId, $uid),
                        (bool)$item['starred'],
                        Post\ThreadUser::getPinned($uriId, $uid)
index 8252de7c2ad45afc7054caf3c86212eb23c80ccc..e01951722dd633aa9e438e0740dec0e5a83a1a12 100644 (file)
@@ -29,7 +29,7 @@ use Friendica\Model\Notification;
 use Friendica\Module\BaseApi;
 
 /**
- * @see https://docs.joinmastodon.org/methods/accounts/mutes/
+ * @see https://docs.joinmastodon.org/methods/notifications/
  */
 class Notifications extends BaseApi
 {
diff --git a/src/Module/Api/Mastodon/Notifications/Clear.php b/src/Module/Api/Mastodon/Notifications/Clear.php
new file mode 100644 (file)
index 0000000..5e0c53d
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Notifications;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/notifications/
+ */
+class Clear extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               DBA::update('notify', ['seen' => true], ['uid' => $uid]);
+
+               System::jsonExit([]);
+       }
+}
diff --git a/src/Module/Api/Mastodon/Notifications/Dismiss.php b/src/Module/Api/Mastodon/Notifications/Dismiss.php
new file mode 100644 (file)
index 0000000..e8faa30
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Notifications;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/notifications/
+ */
+class Dismiss extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               DBA::update('notify', ['seen' => true], ['uid' => $uid, 'id' => $parameters['id']]);
+
+               System::jsonExit([]);
+       }
+}
index afaf1598600ae13f36fc7337f9474a109e67fc65..974c58bd3ffa47dd0325fe41537a061c017d0dfb 100644 (file)
 
 namespace Friendica\Module\Api\Mastodon;
 
+use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Module\BaseApi;
 
 /**
@@ -38,7 +41,23 @@ class Statuses extends BaseApi
 
        public static function delete(array $parameters = [])
        {
-               self::unsupported('delete');
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $parameters['id'], 'uid' => $uid]);
+               if (empty($item['id'])) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if (!Item::markForDeletionById($item['id'])) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               System::jsonExit([]);
        }
 
        /**
diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php
new file mode 100644 (file)
index 0000000..5935759
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Bookmark extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be bookmarked'));
+               }
+
+               Item::update(['starred' => true], ['id' => $item['id']]);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Favourite.php b/src/Module/Api/Mastodon/Statuses/Favourite.php
new file mode 100644 (file)
index 0000000..74892d9
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Favourite extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               Item::performActivity($item['id'], 'like', $uid);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Mute.php b/src/Module/Api/Mastodon/Statuses/Mute.php
new file mode 100644 (file)
index 0000000..ee35784
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Mute extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be muted'));
+               }
+
+               Post\ThreadUser::setIgnored($parameters['id'], $uid, true);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Pin.php b/src/Module/Api/Mastodon/Statuses/Pin.php
new file mode 100644 (file)
index 0000000..a4336a8
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Pin extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be pinned'));
+               }
+
+               Post\ThreadUser::setPinned($parameters['id'], $uid, true);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Reblog.php b/src/Module/Api/Mastodon/Statuses/Reblog.php
new file mode 100644 (file)
index 0000000..cdd788d
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Content\ContactSelector;
+use Friendica\Core\Protocol;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Reblog extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'network'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
+               }
+
+               Item::performActivity($item['id'], 'announce', $uid);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php
new file mode 100644 (file)
index 0000000..d0bfa4b
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Unbookmark extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be unbookmarked'));
+               }
+
+               Item::update(['starred' => false], ['id' => $item['id']]);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Unfavourite.php b/src/Module/Api/Mastodon/Statuses/Unfavourite.php
new file mode 100644 (file)
index 0000000..528ef69
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Unfavourite extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               Item::performActivity($item['id'], 'unlike', $uid);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Unmute.php b/src/Module/Api/Mastodon/Statuses/Unmute.php
new file mode 100644 (file)
index 0000000..9d57dba
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Unmute extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be unmuted'));
+               }
+
+               Post\ThreadUser::setIgnored($parameters['id'], $uid, false);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Unpin.php b/src/Module/Api/Mastodon/Statuses/Unpin.php
new file mode 100644 (file)
index 0000000..ec427d3
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Unpin extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting post can be pinned'));
+               }
+
+               Post\ThreadUser::setPinned($parameters['id'], $uid, false);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
diff --git a/src/Module/Api/Mastodon/Statuses/Unreblog.php b/src/Module/Api/Mastodon/Statuses/Unreblog.php
new file mode 100644 (file)
index 0000000..1296b72
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Statuses;
+
+use Friendica\Content\ContactSelector;
+use Friendica\Core\Protocol;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/statuses/
+ */
+class Unreblog extends BaseApi
+{
+       public static function post(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               if (empty($parameters['id'])) {
+                       DI::mstdnError()->UnprocessableEntity();
+               }
+
+               $item = Post::selectFirstForUser($uid, ['id', 'network'], ['uri-id' => $parameters['id'], 'uid' => [$uid, 0]]);
+               if (!DBA::isResult($item)) {
+                       DI::mstdnError()->RecordNotFound();
+               }
+
+               if (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));
+               }
+
+               Item::performActivity($item['id'], 'unannounce', $uid);
+
+               System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid)->toArray());
+       }
+}
index 7c33d56745773032e18d5847e788ad02f0b9f045..1d8d996ef501bfe2451be01cf09bfe55790a55bc 100644 (file)
@@ -117,8 +117,8 @@ return [
                        '/mutes'                             => [Module\Api\Mastodon\Mutes::class,                    [R::GET         ]],
                        '/notifications'                     => [Module\Api\Mastodon\Notifications::class,            [R::GET         ]],
                        '/notifications/{id:\d+}'            => [Module\Api\Mastodon\Notifications::class,            [R::GET         ]],
-                       '/notifications/clear'               => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/notifications/{id:\d+}/dismiss'    => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
+                       '/notifications/clear'               => [Module\Api\Mastodon\Notifications\Clear::class,      [        R::POST]],
+                       '/notifications/{id:\d+}/dismiss'    => [Module\Api\Mastodon\Notifications\Dismiss::class,    [        R::POST]],
                        '/polls/{id:\d+}'                    => [Module\Api\Mastodon\Unimplemented::class,            [R::GET         ]], // not supported
                        '/polls/{id:\d+}/votes'              => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // not supported
                        '/preferences'                       => [Module\Api\Mastodon\Preferences::class,              [R::GET         ]],
@@ -130,16 +130,16 @@ return [
                        '/statuses/{id:\d+}/context'         => [Module\Api\Mastodon\Statuses\Context::class,         [R::GET         ]],
                        '/statuses/{id:\d+}/reblogged_by'    => [Module\Api\Mastodon\Statuses\RebloggedBy::class,     [R::GET         ]],
                        '/statuses/{id:\d+}/favourited_by'   => [Module\Api\Mastodon\Statuses\FavouritedBy::class,    [R::GET         ]],
-                       '/statuses/{id:\d+}/favourite'       => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/unfavourite'     => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/reblog'          => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/unreblog'        => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/bookmark'        => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/unbookmark'      => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/mute'            => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/unmute'          => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/pin'             => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
-                       '/statuses/{id:\d+}/unpin'           => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]], // @todo
+                       '/statuses/{id:\d+}/favourite'       => [Module\Api\Mastodon\Statuses\Favourite::class,       [        R::POST]],
+                       '/statuses/{id:\d+}/unfavourite'     => [Module\Api\Mastodon\Statuses\Unfavourite::class,     [        R::POST]],
+                       '/statuses/{id:\d+}/reblog'          => [Module\Api\Mastodon\Statuses\Reblog::class,          [        R::POST]],
+                       '/statuses/{id:\d+}/unreblog'        => [Module\Api\Mastodon\Statuses\Unreblog::class,        [        R::POST]],
+                       '/statuses/{id:\d+}/bookmark'        => [Module\Api\Mastodon\Statuses\Bookmark::class,        [        R::POST]],
+                       '/statuses/{id:\d+}/unbookmark'      => [Module\Api\Mastodon\Statuses\Unbookmark::class,      [        R::POST]],
+                       '/statuses/{id:\d+}/mute'            => [Module\Api\Mastodon\Statuses\Mute::class,            [        R::POST]],
+                       '/statuses/{id:\d+}/unmute'          => [Module\Api\Mastodon\Statuses\Unmute::class,          [        R::POST]],
+                       '/statuses/{id:\d+}/pin'             => [Module\Api\Mastodon\Statuses\Pin::class,             [        R::POST]],
+                       '/statuses/{id:\d+}/unpin'           => [Module\Api\Mastodon\Statuses\Unpin::class,           [        R::POST]],
                        '/suggestions'                       => [Module\Api\Mastodon\Suggestions::class,              [R::GET         ]],
                        '/suggestions/{id:\d+}'              => [Module\Api\Mastodon\Unimplemented::class,            [R::DELETE      ]], // not implemented
                        '/timelines/direct'                  => [Module\Api\Mastodon\Unimplemented::class,            [R::GET         ]], // @todo