From 155e3a701e33d526f6af4fe308917c421751bb4b Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 20 Feb 2023 15:51:17 -0500 Subject: [PATCH] Add DislikedBy Mastodon compatible endpoint in the Friendica API space --- .../Api/Friendica/Statuses/DislikedBy.php | 62 +++++++++++++++++++ static/routes.config.php | 1 + 2 files changed, 63 insertions(+) create mode 100644 src/Module/Api/Friendica/Statuses/DislikedBy.php diff --git a/src/Module/Api/Friendica/Statuses/DislikedBy.php b/src/Module/Api/Friendica/Statuses/DislikedBy.php new file mode 100644 index 0000000000..81860bc40c --- /dev/null +++ b/src/Module/Api/Friendica/Statuses/DislikedBy.php @@ -0,0 +1,62 @@ +. + * + */ + +namespace Friendica\Module\Api\Friendica\Statuses; + +use Friendica\Core\System; +use Friendica\DI; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Module\BaseApi; +use Friendica\Protocol\Activity; + +/** + * @see https://docs.joinmastodon.org/methods/statuses/ + */ +class DislikedBy extends BaseApi +{ + /** + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + protected function rawContent(array $request = []) + { + $uid = self::getCurrentUserID(); + + if (empty($this->parameters['id'])) { + DI::mstdnError()->UnprocessableEntity(); + } + + $id = $this->parameters['id']; + if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { + DI::mstdnError()->RecordNotFound(); + } + + $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]); + + $accounts = []; + + while ($activity = Post::fetch($activities)) { + $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); + } + + System::jsonExit($accounts); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index caf24242b3..eb55c64ab5 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -81,6 +81,7 @@ $apiRoutes = [ '/activity/{verb:attendmaybe|attendno|attendyes|dislike|like|unattendmaybe|unattendno|unattendyes|undislike|unlike}[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Activity::class, [ R::POST]], '/statuses/{id:\d+}/dislike' => [Module\Api\Friendica\Statuses\Dislike::class, [ R::POST]], + '/statuses/{id:\d+}/disliked_by' => [Module\Api\Friendica\Statuses\DislikedBy::class, [R::GET ]], '/statuses/{id:\d+}/undislike' => [Module\Api\Friendica\Statuses\Undislike::class, [ R::POST]], '/notification/seen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification\Seen::class, [ R::POST]], '/notification[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification::class, [R::GET ]], -- 2.39.5