From 3bbf543d2523abf1c9e4eda0501be73d7975a71d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 19:21:52 +0000 Subject: [PATCH 1/6] API: Some more endpoints --- doc/API-Mastodon.md | 9 ++ src/Model/Post.php | 5 +- src/Module/Api/Mastodon/Blocks.php | 85 ++++++++++++++++ src/Module/Api/Mastodon/Bookmarks.php | 86 ++++++++++++++++ src/Module/Api/Mastodon/Favourited.php | 81 ++++++++++++++++ src/Module/Api/Mastodon/Mutes.php | 85 ++++++++++++++++ src/Module/Api/Mastodon/Statuses/Context.php | 97 +++++++++++++++++++ .../Api/Mastodon/Statuses/FavouritedBy.php | 61 ++++++++++++ .../Api/Mastodon/Statuses/RebloggedBy.php | 61 ++++++++++++ src/Module/BaseApi.php | 2 +- static/routes.config.php | 84 ++++++++-------- 11 files changed, 611 insertions(+), 45 deletions(-) create mode 100644 src/Module/Api/Mastodon/Blocks.php create mode 100644 src/Module/Api/Mastodon/Bookmarks.php create mode 100644 src/Module/Api/Mastodon/Favourited.php create mode 100644 src/Module/Api/Mastodon/Mutes.php create mode 100644 src/Module/Api/Mastodon/Statuses/Context.php create mode 100644 src/Module/Api/Mastodon/Statuses/FavouritedBy.php create mode 100644 src/Module/Api/Mastodon/Statuses/RebloggedBy.php diff --git a/doc/API-Mastodon.md b/doc/API-Mastodon.md index 574c5eb7f..811bb5bc5 100644 --- a/doc/API-Mastodon.md +++ b/doc/API-Mastodon.md @@ -17,12 +17,17 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en - [`GET /api/v1//accounts/:id`](https://docs.joinmastodon.org/methods/accounts/#retrieve-information) - [`GET /api/v1//accounts/:id/statuses`](https://docs.joinmastodon.org/methods/accounts/#retrieve-information) +- [`GET /api/v1//accounts/:id/followers`](https://docs.joinmastodon.org/methods/accounts/) +- [`GET /api/v1//accounts/:id/following`](https://docs.joinmastodon.org/methods/accounts/) +- [`GET /api/v1/blocks`](https://docs.joinmastodon.org/methods/accounts/blocks/) +- [`GET /api/v1/bookmarks`](https://docs.joinmastodon.org/methods/accounts/bookmarks/) - [`GET /api/v1//accounts/verify_credentials`](https://docs.joinmastodon.org/methods/accounts) - [`GET /api/v1/custom_emojis`](https://docs.joinmastodon.org/methods/instance/custom_emojis/) - Doesn't return unicode emojis since they aren't using an image URL - [`GET /api/v1/directory`](https://docs.joinmastodon.org/methods/instance/directory/) +- [`GET /api/v1/favourites`](https://docs.joinmastodon.org/methods/accounts/favourites/) - [`GET /api/v1/follow_requests`](https://docs.joinmastodon.org/methods/accounts/follow_requests#pending-follows) - Returned IDs are specific to follow requests - [`POST /api/v1/follow_requests/:id/authorize`](https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow) @@ -37,7 +42,11 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en - [`GET /api/v1/instance`](https://docs.joinmastodon.org/methods/instance#fetch-instance) - [`GET /api/v1/instance/peers`](https://docs.joinmastodon.org/methods/instance#list-of-connected-domains) +- [`GET /api/v1/mutes`](https://docs.joinmastodon.org/methods/accounts/mutes/) - [`GET /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/) - [`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/) diff --git a/src/Model/Post.php b/src/Model/Post.php index 9ce301ade..aae847664 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -267,13 +267,14 @@ class Post * @param array $selected Array of selected fields, empty for all * @param array $condition Array of fields for condition * @param array $params Array of several parameters + * @param bool $user_mode true = post-user-view, false = post-view * * @return boolean|object * @throws \Exception */ - public static function select(array $selected = [], array $condition = [], $params = []) + public static function select(array $selected = [], array $condition = [], $params = [], bool $user_mode = true) { - return self::selectView('post-user-view', $selected, $condition, $params); + return self::selectView($user_mode ? 'post-user-view' : 'post-view', $selected, $condition, $params); } /** diff --git a/src/Module/Api/Mastodon/Blocks.php b/src/Module/Api/Mastodon/Blocks.php new file mode 100644 index 000000000..7f968f64b --- /dev/null +++ b/src/Module/Api/Mastodon/Blocks.php @@ -0,0 +1,85 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Module\BaseApi; + +/** + * @see https://docs.joinmastodon.org/methods/accounts/blocks/ + */ +class Blocks extends BaseApi +{ + /** + * @param array $parameters + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + self::login(); + $uid = self::getCurrentUserID(); + + if (empty($parameters['id'])) { + DI::mstdnError()->RecordNotFound(); + } + + $id = $parameters['id']; + if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { + DI::mstdnError()->RecordNotFound(); + } + + // Return results older than this id + $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id']; + // Return results newer than this id + $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; + // Maximum number of results. Defaults to 40. + $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit']; + + $params = ['order' => ['cid' => true], 'limit' => $limit]; + + $condition = ['cid' => $id, 'blocked' => true, 'uid' => $uid]; + + if (!empty($max_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]); + } + + if (!empty($since_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]); + } + + if (!empty($min_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]); + + $params['order'] = ['cid']; + } + + $followers = DBA::select('user-contact', ['cid'], $condition, $parameters); + while ($follower = DBA::fetch($followers)) { + $accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid); + } + DBA::close($followers); + + System::jsonExit($accounts); + } +} diff --git a/src/Module/Api/Mastodon/Bookmarks.php b/src/Module/Api/Mastodon/Bookmarks.php new file mode 100644 index 000000000..8b03c40eb --- /dev/null +++ b/src/Module/Api/Mastodon/Bookmarks.php @@ -0,0 +1,86 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Model\Post; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException; + +/** + * @see https://docs.joinmastodon.org/methods/accounts/bookmarks/ + */ +class Bookmarks extends BaseApi +{ + /** + * @param array $parameters + * @throws HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + self::login(); + $uid = self::getCurrentUserID(); + + // Maximum number of results to return. Defaults to 20. + $limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit']; + // Return results older than id + $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id']; + // Return results newer than id + $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; + // Return results immediately newer than id + $min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id']; + + $params = ['order' => ['uri-id' => true], 'limit' => $limit]; + + $condition = ['pinned' => true, 'uid' => $uid]; + + if (!empty($max_id)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]); + } + + if (!empty($since_id)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]); + } + + if (!empty($min_id)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]); + + $params['order'] = ['uri-id']; + } + + $items = Post::selectThreadForUser($uid, ['uri-id'], $condition, $params); + + $statuses = []; + while ($item = Post::fetch($items)) { + $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid); + } + DBA::close($items); + + if (!empty($min_id)) { + array_reverse($statuses); + } + + System::jsonExit($statuses); + } +} diff --git a/src/Module/Api/Mastodon/Favourited.php b/src/Module/Api/Mastodon/Favourited.php new file mode 100644 index 000000000..f46fb7b07 --- /dev/null +++ b/src/Module/Api/Mastodon/Favourited.php @@ -0,0 +1,81 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Model\Post; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException; +use Friendica\Protocol\Activity; + +/** + * @see https://docs.joinmastodon.org/methods/accounts/favourites/ + */ +class Favourited extends BaseApi +{ + /** + * @param array $parameters + * @throws HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + self::login(); + $uid = self::getCurrentUserID(); + + // Maximum number of results to return. Defaults to 20. + $limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit']; + // Return results immediately newer than id + $min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id']; + // Return results older than id + $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id']; + + $params = ['order' => ['thr-parent-id' => true], 'limit' => $limit]; + + $condition = ['gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'uid' => $uid]; + + if (!empty($max_id)) { + $condition = DBA::mergeConditions($condition, ["`thr-parent-id` < ?", $max_id]); + } + + if (!empty($min_id)) { + $condition = DBA::mergeConditions($condition, ["`thr-parent-id` > ?", $min_id]); + + $params['order'] = ['thr-parent-id']; + } + + $items = Post::selectForUser($uid, ['thr-parent-id'], $condition, $params); + + $statuses = []; + while ($item = Post::fetch($items)) { + $statuses[] = DI::mstdnStatus()->createFromUriId($item['thr-parent-id'], $uid); + } + DBA::close($items); + + if (!empty($min_id)) { + array_reverse($statuses); + } + + System::jsonExit($statuses); + } +} diff --git a/src/Module/Api/Mastodon/Mutes.php b/src/Module/Api/Mastodon/Mutes.php new file mode 100644 index 000000000..b5ec30de4 --- /dev/null +++ b/src/Module/Api/Mastodon/Mutes.php @@ -0,0 +1,85 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Module\BaseApi; + +/** + * @see https://docs.joinmastodon.org/methods/accounts/mutes/ + */ +class Mutes extends BaseApi +{ + /** + * @param array $parameters + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + self::login(); + $uid = self::getCurrentUserID(); + + if (empty($parameters['id'])) { + DI::mstdnError()->RecordNotFound(); + } + + $id = $parameters['id']; + if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { + DI::mstdnError()->RecordNotFound(); + } + + // Return results older than this id + $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id']; + // Return results newer than this id + $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; + // Maximum number of results. Defaults to 40. + $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit']; + + $params = ['order' => ['cid' => true], 'limit' => $limit]; + + $condition = ['cid' => $id, 'ignored' => true, 'uid' => $uid]; + + if (!empty($max_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]); + } + + if (!empty($since_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]); + } + + if (!empty($min_id)) { + $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]); + + $params['order'] = ['cid']; + } + + $followers = DBA::select('user-contact', ['cid'], $condition, $parameters); + while ($follower = DBA::fetch($followers)) { + $accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid); + } + DBA::close($followers); + + System::jsonExit($accounts); + } +} diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php new file mode 100644 index 000000000..d64b4d24c --- /dev/null +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -0,0 +1,97 @@ +. + * + */ + +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 Context extends BaseApi +{ + /** + * @param array $parameters + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + $uid = self::getCurrentUserID(); + + if (empty($parameters['id'])) { + DI::mstdnError()->RecordNotFound(); + } + + $id = $parameters['id']; + $parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]); + if (!DBA::isResult($parent)) { + DI::mstdnError()->RecordNotFound(); + } + + $parents = []; + $children = []; + $posts = Post::select(['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']], [], false); + while ($post = Post::fetch($posts)) { + if ($post['uri-id'] == $post['thr-parent-id']) { + continue; + } + $parents[$post['uri-id']] = $post['thr-parent-id']; + $children[$post['thr-parent-id']][] = $post['uri-id']; + } + DBA::close($posts); + + $statuses = ['ancestors' => [], 'descendants' => []]; + + foreach (self::getParents($id, $parents) as $ancestor) { + $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid); + } + + foreach (self::getChildren($id, $children) as $descendant) { + $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid); + } + + System::jsonExit($statuses); + } + + private static function getParents(int $id, array $parents, array $list = []) + { + if (!empty($parents[$id])) { + $list[] = $parents[$id]; + $list = self::getParents($parents[$id], $parents, $list); + } + return $list; + } + + private static function getChildren(int $id, array $children, array $list = []) + { + if (!empty($children[$id])) { + foreach ($children[$id] as $child) { + $list[] = $child; + $list = self::getChildren($child, $children, $list); + } + } + return $list; + } +} diff --git a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php new file mode 100644 index 000000000..0787c98cc --- /dev/null +++ b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php @@ -0,0 +1,61 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon\Statuses; + +use Friendica\Core\System; +use Friendica\DI; +use Friendica\Model\Post; +use Friendica\Module\BaseApi; +use Friendica\Protocol\Activity; + +/** + * @see https://docs.joinmastodon.org/methods/statuses/ + */ +class FavouritedBy extends BaseApi +{ + /** + * @param array $parameters + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + $uid = self::getCurrentUserID(); + + if (empty($parameters['id'])) { + DI::mstdnError()->RecordNotFound(); + } + + $id = $parameters['id']; + if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { + DI::mstdnError()->RecordNotFound(); + } + + $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE], [], false); + $accounts = []; + + while ($activity = Post::fetch($activities)) { + $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); + } + + System::jsonExit($accounts); + } +} diff --git a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php new file mode 100644 index 000000000..089e713f5 --- /dev/null +++ b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php @@ -0,0 +1,61 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon\Statuses; + +use Friendica\Core\System; +use Friendica\DI; +use Friendica\Model\Post; +use Friendica\Module\BaseApi; +use Friendica\Protocol\Activity; + +/** + * @see https://docs.joinmastodon.org/methods/statuses/ + */ +class RebloggedBy extends BaseApi +{ + /** + * @param array $parameters + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function rawContent(array $parameters = []) + { + $uid = self::getCurrentUserID(); + + if (empty($parameters['id'])) { + DI::mstdnError()->RecordNotFound(); + } + + $id = $parameters['id']; + if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { + DI::mstdnError()->RecordNotFound(); + } + + $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE], [], false); + $accounts = []; + + while ($activity = Post::fetch($activities)) { + $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); + } + + System::jsonExit($accounts); + } +} diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index c3f11b0eb..248e65510 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -110,7 +110,7 @@ class BaseApi extends BaseModule public static function unsupported(string $method = 'all') { $path = DI::args()->getQueryString(); - Logger::info('Unimplemented API call', ['path' => $path, 'method' => $method]); + Logger::info('Unimplemented API call', ['method' => $method, 'path' => $path, 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); $error = DI::l10n()->t('API endpoint %s %s is not implemented', strtoupper($method), $path); $error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.');; $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); diff --git a/static/routes.config.php b/static/routes.config.php index d66169559..efbc6d523 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -61,9 +61,9 @@ return [ '/accounts/{id:\d+}' => [Module\Api\Mastodon\Accounts::class, [R::GET ]], '/accounts/{id:\d+}/statuses' => [Module\Api\Mastodon\Accounts\Statuses::class, [R::GET ]], '/accounts/{id:\d+}/followers' => [Module\Api\Mastodon\Accounts\Followers::class, [R::GET ]], - '/accounts/{id:\d+}/following' => [Module\Api\Mastodon\Accounts\Followers::class, [R::GET ]], - '/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/accounts/{id:\d+}/identity_proofs' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/accounts/{id:\d+}/following' => [Module\Api\Mastodon\Accounts\Following::class, [R::GET ]], + '/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo + '/accounts/{id:\d+}/identity_proofs' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/accounts/{id:\d+}/follow' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/unfollow' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/block' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], @@ -73,63 +73,63 @@ return [ '/accounts/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/note' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/accounts/relationships' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/accounts/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/accounts/relationships' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo + '/accounts/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/accounts/verify_credentials' => [Module\Api\Mastodon\Accounts\VerifyCredentials::class, [R::GET ]], '/accounts/update_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::PATCH ]], - '/admin/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/admin/accounts/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/admin/accounts/{id:\d+}/{action}' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/admin/reports' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/admin/reports/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/admin/reports/{id:\d+}/{action}' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/announcements' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/announcements/{id:\d+}/dismiss' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/announcements/{id:\d+}/reactions/{name}' => [Module\Api\Mastodon\Unimplemented::class, [R::PUT, R::DELETE]], + '/admin/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/admin/accounts/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/admin/accounts/{id:\d+}/{action}' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented + '/admin/reports' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/admin/reports/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/admin/reports/{id:\d+}/{action}' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented + '/announcements' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/announcements/{id:\d+}/dismiss' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented + '/announcements/{id:\d+}/reactions/{name}' => [Module\Api\Mastodon\Unimplemented::class, [R::PUT, R::DELETE]], // not implemented '/apps' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/apps/verify_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/bookmarks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/conversations' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/blocks' => [Module\Api\Mastodon\Blocks::class, [R::GET ]], + '/bookmarks' => [Module\Api\Mastodon\Bookmarks::class, [R::GET ]], + '/conversations' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/conversations/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], '/conversations/{id:\d+}/read' => [Module\Api\Mastodon\Unimplemented::class, [R::POST ]], '/custom_emojis' => [Module\Api\Mastodon\CustomEmojis::class, [R::GET ]], - '/domain_blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], + '/domain_blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], // not implemented '/directory' => [Module\Api\Mastodon\Directory::class, [R::GET ]], - '/endorsements' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/favourites' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/featured_tags' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], + '/endorsements' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/favourites' => [Module\Api\Mastodon\Favourited::class, [R::GET ]], + '/featured_tags' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], // not implemented '/featured_tags/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], - '/featured_tags/suggestions' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/filters' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/filters/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::PUT, R::DELETE]], + '/featured_tags/suggestions' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/filters' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/filters/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::PUT, R::DELETE]], // not implemented '/follow_requests' => [Module\Api\Mastodon\FollowRequests::class, [R::GET ]], '/follow_requests/{id:\d+}/{action}' => [Module\Api\Mastodon\FollowRequests::class, [ R::POST]], '/instance' => [Module\Api\Mastodon\Instance::class, [R::GET ]], - '/instance/activity' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/instance/activity' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/instance/peers' => [Module\Api\Mastodon\Instance\Peers::class, [R::GET ]], - '/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], - '/lists/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]], - '/lists/{id:\d+}/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], - '/markers' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], + '/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], // @todo + '/lists/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]], // @todo + '/lists/{id:\d+}/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], // @todo + '/markers' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], // not implemented '/media' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/media/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT]], - '/mutes' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/notifications' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/notifications/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/media/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT]], // @todo + '/mutes' => [Module\Api\Mastodon\Mutes::class, [R::GET ]], + '/notifications' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo + '/notifications/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/notifications/clear' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/notifications/{id:\d+}/dismiss' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/polls/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/polls/{id:\d+}/votes' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/preferences' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/polls/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/polls/{id:\d+}/votes' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented + '/preferences' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/reports' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/scheduled_statuses' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/scheduled_statuses/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]], + '/scheduled_statuses' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented + '/scheduled_statuses/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]], // not implemented '/statuses' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/statuses/{id:\d+}' => [Module\Api\Mastodon\Statuses::class, [R::GET, R::DELETE]], - '/statuses/{id:\d+}/context' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/statuses/{id:\d+}/reblogged_by' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], - '/statuses/{id:\d+}/favourited_by' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/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]], '/statuses/{id:\d+}/unfavourite' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/statuses/{id:\d+}/reblog' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], @@ -149,7 +149,7 @@ return [ '/trends' => [Module\Api\Mastodon\Trends::class, [R::GET ]], ], '/v2' => [ - '/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], + '/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo ], '/friendica' => [ '/profile/show' => [Module\Api\Friendica\Profile\Show::class , [R::GET ]], From cce0d0c21b278605d5e4cafec1884bbfd5919c81 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 19:25:20 +0000 Subject: [PATCH 2/6] Formatting --- src/Module/Api/Mastodon/Statuses/FavouritedBy.php | 1 + src/Module/Api/Mastodon/Statuses/RebloggedBy.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php index 0787c98cc..7c784c802 100644 --- a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php +++ b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php @@ -50,6 +50,7 @@ class FavouritedBy extends BaseApi } $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE], [], false); + $accounts = []; while ($activity = Post::fetch($activities)) { diff --git a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php index 089e713f5..3701afb0d 100644 --- a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php +++ b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php @@ -50,6 +50,7 @@ class RebloggedBy extends BaseApi } $activities = Post::select(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE], [], false); + $accounts = []; while ($activity = Post::fetch($activities)) { From 4b4298b0f8ed6497b2648ecf62758e535e4159f9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 19:26:57 +0000 Subject: [PATCH 3/6] Some more formatting --- src/Module/Api/Mastodon/Statuses/Context.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index d64b4d24c..2b06f9db3 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -79,6 +79,7 @@ class Context extends BaseApi { if (!empty($parents[$id])) { $list[] = $parents[$id]; + $list = self::getParents($parents[$id], $parents, $list); } return $list; @@ -89,6 +90,7 @@ class Context extends BaseApi if (!empty($children[$id])) { foreach ($children[$id] as $child) { $list[] = $child; + $list = self::getChildren($child, $children, $list); } } From a0e455a4938c7dd72e32df2b1cf8839e01b016a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 19:28:20 +0000 Subject: [PATCH 4/6] Again formatting --- src/Module/Api/Mastodon/Statuses/Context.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 2b06f9db3..351b65d36 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -58,6 +58,7 @@ class Context extends BaseApi continue; } $parents[$post['uri-id']] = $post['thr-parent-id']; + $children[$post['thr-parent-id']][] = $post['uri-id']; } DBA::close($posts); From 1e3182a896cf991620e4d2a01f845fc59efe78ab Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 19:30:09 +0000 Subject: [PATCH 5/6] And more formatting --- src/Module/Api/Mastodon/Statuses/Context.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 351b65d36..bf49d265c 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -45,13 +45,15 @@ class Context extends BaseApi } $id = $parameters['id']; + $parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]); if (!DBA::isResult($parent)) { DI::mstdnError()->RecordNotFound(); } - $parents = []; + $parents = []; $children = []; + $posts = Post::select(['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']], [], false); while ($post = Post::fetch($posts)) { if ($post['uri-id'] == $post['thr-parent-id']) { From 7d6ff10bf4e8de8ee45acc3beee818336e33fa2a Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 May 2021 20:22:08 +0000 Subject: [PATCH 6/6] Some added comments on routes --- static/routes.config.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/static/routes.config.php b/static/routes.config.php index efbc6d523..ddc755ec1 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -57,7 +57,7 @@ return [ '/api' => [ '/v1' => [ - '/accounts' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], + '/accounts' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented '/accounts/{id:\d+}' => [Module\Api\Mastodon\Accounts::class, [R::GET ]], '/accounts/{id:\d+}/statuses' => [Module\Api\Mastodon\Accounts\Statuses::class, [R::GET ]], '/accounts/{id:\d+}/followers' => [Module\Api\Mastodon\Accounts\Followers::class, [R::GET ]], @@ -70,8 +70,8 @@ return [ '/accounts/{id:\d+}/unblock' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/mute' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/{id:\d+}/unmute' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/accounts/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], - '/accounts/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], + '/accounts/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented + '/accounts/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented '/accounts/{id:\d+}/note' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/accounts/relationships' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo '/accounts/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo @@ -99,7 +99,7 @@ return [ '/endorsements' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/favourites' => [Module\Api\Mastodon\Favourited::class, [R::GET ]], '/featured_tags' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST]], // not implemented - '/featured_tags/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], + '/featured_tags/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], // not implemented '/featured_tags/suggestions' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/filters' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/filters/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::PUT, R::DELETE]], // not implemented @@ -122,7 +122,7 @@ return [ '/polls/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/polls/{id:\d+}/votes' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented '/preferences' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo - '/reports' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], + '/reports' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not implemented '/scheduled_statuses' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented '/scheduled_statuses/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]], // not implemented '/statuses' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], @@ -141,7 +141,7 @@ return [ '/statuses/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/statuses/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], '/suggestions' => [Module\Api\Mastodon\Suggestions::class, [R::GET ]], - '/suggestions/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], + '/suggestions/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], // not implemented '/timelines/home' => [Module\Api\Mastodon\Timelines\Home::class, [R::GET ]], '/timelines/list/{id:\d+}' => [Module\Api\Mastodon\Timelines\ListTimeline::class, [R::GET ]], '/timelines/public' => [Module\Api\Mastodon\Timelines\PublicTimeline::class, [R::GET ]],