Merge pull request #10222 from annando/more-api
API: Some more endpoints
This commit is contained in:
commit
6511493fdf
11 changed files with 624 additions and 51 deletions
|
@ -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/)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
85
src/Module/Api/Mastodon/Blocks.php
Normal file
85
src/Module/Api/Mastodon/Blocks.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
86
src/Module/Api/Mastodon/Bookmarks.php
Normal file
86
src/Module/Api/Mastodon/Bookmarks.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
81
src/Module/Api/Mastodon/Favourited.php
Normal file
81
src/Module/Api/Mastodon/Favourited.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
85
src/Module/Api/Mastodon/Mutes.php
Normal file
85
src/Module/Api/Mastodon/Mutes.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
102
src/Module/Api/Mastodon/Statuses/Context.php
Normal file
102
src/Module/Api/Mastodon/Statuses/Context.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?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 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;
|
||||
}
|
||||
}
|
62
src/Module/Api/Mastodon/Statuses/FavouritedBy.php
Normal file
62
src/Module/Api/Mastodon/Statuses/FavouritedBy.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?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\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);
|
||||
}
|
||||
}
|
62
src/Module/Api/Mastodon/Statuses/RebloggedBy.php
Normal file
62
src/Module/Api/Mastodon/Statuses/RebloggedBy.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?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\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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -57,79 +57,79 @@ 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 ]],
|
||||
'/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]],
|
||||
'/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 ]],
|
||||
'/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]],
|
||||
'/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]],
|
||||
'/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 ]], // 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
|
||||
'/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 ]],
|
||||
'/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]],
|
||||
'/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]], // 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]],
|
||||
'/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]],
|
||||
|
@ -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 ]],
|
||||
|
@ -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 ]],
|
||||
|
|
Loading…
Reference in a new issue