Merge pull request #10223 from annando/api-search-lists
API: added account related endpoints
This commit is contained in:
commit
2817547edd
17
database.sql
17
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2021.06-dev (Siberian Iris)
|
||||
-- DB_UPDATE_VERSION 1414
|
||||
-- DB_UPDATE_VERSION 1415
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -364,6 +364,21 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
|
|||
FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
|
||||
|
||||
--
|
||||
-- TABLE application
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `application` (
|
||||
`id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
|
||||
`client_id` varchar(64) NOT NULL COMMENT '',
|
||||
`client_secret` varchar(64) NOT NULL COMMENT '',
|
||||
`name` varchar(255) NOT NULL COMMENT '',
|
||||
`redirect_uri` varchar(255) NOT NULL COMMENT '',
|
||||
`website` varchar(255) COMMENT '',
|
||||
`scopes` varchar(255) COMMENT '',
|
||||
PRIMARY KEY(`id`),
|
||||
UNIQUE INDEX `client_id` (`client_id`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application';
|
||||
|
||||
--
|
||||
-- TABLE attach
|
||||
--
|
||||
|
|
|
@ -15,13 +15,15 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
|
|||
|
||||
## Implemented endpoints
|
||||
|
||||
- [`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/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/accounts/:id/lists`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`GET /api/v1/accounts/search`](https://docs.joinmastodon.org/methods/accounts)
|
||||
- [`GET /api/v1/accounts/verify_credentials`](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
|
||||
|
||||
|
@ -42,7 +44,14 @@ 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/lists`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`GET /api/v1/lists/:id`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`GET /api/v1/lists/:id/accounts`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`GET /api/v1/media/:id`](https://docs.joinmastodon.org/methods/statuses/media/)
|
||||
- [`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/)
|
||||
- [`GET /api/v1/preferences`](https://docs.joinmastodon.org/methods/accounts/preferences/)
|
||||
- [`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/)
|
||||
|
|
24
src/DI.php
24
src/DI.php
|
@ -239,6 +239,14 @@ abstract class DI
|
|||
return self::$dice->create(Factory\Api\Mastodon\Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Application
|
||||
*/
|
||||
public static function mstdnApplication()
|
||||
{
|
||||
return self::$dice->create(Factory\Api\Mastodon\Application::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Attachment
|
||||
*/
|
||||
|
@ -295,6 +303,14 @@ abstract class DI
|
|||
return self::$dice->create(Factory\Api\Mastodon\Status::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\ListEntity
|
||||
*/
|
||||
public static function mstdnList()
|
||||
{
|
||||
return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Mention
|
||||
*/
|
||||
|
@ -303,6 +319,14 @@ abstract class DI
|
|||
return self::$dice->create(Factory\Api\Mastodon\Mention::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Notification
|
||||
*/
|
||||
public static function mstdnNotification()
|
||||
{
|
||||
return self::$dice->create(Factory\Api\Mastodon\Notification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Tag
|
||||
*/
|
||||
|
|
49
src/Factory/Api/Mastodon/Application.php
Normal file
49
src/Factory/Api/Mastodon/Application.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?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\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
class Application extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* @param int $id Application ID
|
||||
*/
|
||||
public function createFromApplicationId(int $id)
|
||||
{
|
||||
$application = DBA::selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]);
|
||||
if (!DBA::isResult($application)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Application(
|
||||
$application['name'],
|
||||
$application['client_id'],
|
||||
$application['client_secret'],
|
||||
$application['id'],
|
||||
$application['redirect_uri'],
|
||||
$application['website']);
|
||||
|
||||
return $object->toArray();
|
||||
}
|
||||
}
|
|
@ -23,9 +23,12 @@ namespace Friendica\Factory\Api\Mastodon;
|
|||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Repository\ProfileField;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Proxy;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
@ -93,4 +96,36 @@ class Attachment extends BaseFactory
|
|||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id id of the photo
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromPhoto(int $id)
|
||||
{
|
||||
$photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]);
|
||||
if (empty($photo)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attachment = ['id' => $photo['id'], 'description' => $photo['title']];
|
||||
|
||||
$phototypes = Images::supportedTypes();
|
||||
$ext = $phototypes[$photo['type']];
|
||||
|
||||
$url = DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-0.' . $ext;
|
||||
|
||||
$preview = Photo::selectFirst(['scale'], ["`resource-id` = ? AND `uid` = ? AND `scale` > ?", $photo['resource-id'], $photo['uid'], 0], ['order' => ['scale']]);
|
||||
if (empty($scale)) {
|
||||
$preview_url = DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $preview['scale'] . '.' . $ext;
|
||||
} else {
|
||||
$preview_url = '';
|
||||
}
|
||||
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, 'image', $url, $preview_url, '');
|
||||
return $object->toArray();
|
||||
}
|
||||
}
|
||||
|
|
34
src/Factory/Api/Mastodon/ListEntity.php
Normal file
34
src/Factory/Api/Mastodon/ListEntity.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?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\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
class ListEntity extends BaseFactory
|
||||
{
|
||||
public function createFromGroupId(int $id)
|
||||
{
|
||||
$group = DBA::selectFirst('group', ['name'], ['id' => $id, 'deleted' => false]);
|
||||
return new \Friendica\Object\Api\Mastodon\ListEntity($id, $group['name'] ?? '', 'list');
|
||||
}
|
||||
}
|
89
src/Factory/Api/Mastodon/Notification.php
Normal file
89
src/Factory/Api/Mastodon/Notification.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?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\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Notification as ModelNotification;
|
||||
|
||||
class Notification extends BaseFactory
|
||||
{
|
||||
public function createFromNotifyId(int $id)
|
||||
{
|
||||
$notification = DBA::selectFirst('notify', [], ['id' => $id]);
|
||||
if (!DBA::isResult($notification)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cid = Contact::getIdForURL($notification['url'], 0, false);
|
||||
if (empty($cid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
follow = Someone followed you
|
||||
follow_request = Someone requested to follow you
|
||||
mention = Someone mentioned you in their status
|
||||
reblog = Someone boosted one of your statuses
|
||||
favourite = Someone favourited one of your statuses
|
||||
poll = A poll you have voted in or created has ended
|
||||
status = Someone you enabled notifications for has posted a status
|
||||
*/
|
||||
|
||||
switch ($notification['type']) {
|
||||
case ModelNotification\Type::INTRO:
|
||||
$type = 'follow_request';
|
||||
break;
|
||||
|
||||
case ModelNotification\Type::WALL:
|
||||
case ModelNotification\Type::COMMENT:
|
||||
case ModelNotification\Type::MAIL:
|
||||
case ModelNotification\Type::TAG_SELF:
|
||||
case ModelNotification\Type::POKE:
|
||||
$type = 'mention';
|
||||
break;
|
||||
|
||||
case ModelNotification\Type::SHARE:
|
||||
$type = 'status';
|
||||
break;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
$account = DI::mstdnAccount()->createFromContactId($cid);
|
||||
|
||||
if (!empty($notification['uri-id'])) {
|
||||
try {
|
||||
$status = DI::mstdnStatus()->createFromUriId($notification['uri-id'], $notification['uid']);
|
||||
} catch (\Throwable $th) {
|
||||
$status = null;
|
||||
}
|
||||
} else {
|
||||
$status = null;
|
||||
}
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Notification($id, $type, $notification['date'], $account, $status);
|
||||
}
|
||||
}
|
|
@ -2763,11 +2763,12 @@ class Contact
|
|||
*
|
||||
* @param string $search Name or nick
|
||||
* @param string $mode Search mode (e.g. "community")
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return array with search results
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function searchByName($search, $mode = '')
|
||||
public static function searchByName(string $search, string $mode = '', int $uid = 0)
|
||||
{
|
||||
if (empty($search)) {
|
||||
return [];
|
||||
|
@ -2800,7 +2801,7 @@ class Contact
|
|||
NOT `failed` AND `uid` = ? AND
|
||||
(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
|
||||
ORDER BY `nurl` DESC LIMIT 1000",
|
||||
Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, 0, $search, $search, $search
|
||||
Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $uid, $search, $search, $search
|
||||
);
|
||||
|
||||
$contacts = DBA::toArray($results);
|
||||
|
|
|
@ -81,6 +81,10 @@ class Followers extends BaseApi
|
|||
}
|
||||
DBA::close($followers);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($accounts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,10 @@ class Following extends BaseApi
|
|||
}
|
||||
DBA::close($followers);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($accounts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
||||
|
|
66
src/Module/Api/Mastodon/Accounts/Lists.php
Normal file
66
src/Module/Api/Mastodon/Accounts/Lists.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Lists 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();
|
||||
}
|
||||
|
||||
$lists = [];
|
||||
|
||||
$cdata = Contact::getPublicAndUserContacID($id, $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$groups = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]);
|
||||
while ($group = DBA::fetch($groups)) {
|
||||
$lists[] = DI::mstdnList()->createFromGroupId($group['gid']);
|
||||
}
|
||||
DBA::close($groups);
|
||||
}
|
||||
|
||||
System::jsonExit($lists);
|
||||
}
|
||||
}
|
101
src/Module/Api/Mastodon/Accounts/Search.php
Normal file
101
src/Module/Api/Mastodon/Accounts/Search.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?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\Accounts;
|
||||
|
||||
use Friendica\Core\Search as CoreSearch;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Object\Search\ContactResult;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Search extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
// What to search for
|
||||
$q = (int)!isset($_REQUEST['q']) ? 0 : $_REQUEST['q'];
|
||||
// Maximum number of results. Defaults to 40.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
|
||||
// Attempt WebFinger lookup. Defaults to false. Use this when q is an exact address.
|
||||
$resolve = (int)!isset($_REQUEST['resolve']) ? 0 : $_REQUEST['resolve'];
|
||||
// Only who the user is following. Defaults to false.
|
||||
$following = (int)!isset($_REQUEST['following']) ? 0 : $_REQUEST['following'];
|
||||
|
||||
$accounts = [];
|
||||
|
||||
if (!$following) {
|
||||
if ((strrpos($q, '@') > 0) && $resolve) {
|
||||
$results = CoreSearch::getContactsFromProbe($q);
|
||||
}
|
||||
|
||||
if (empty($results)) {
|
||||
if (DI::config()->get('system', 'poco_local_search')) {
|
||||
$results = CoreSearch::getContactsFromLocalDirectory($q, CoreSearch::TYPE_ALL, 0, $limit);
|
||||
} elseif (!empty(DI::config()->get('system', 'directory'))) {
|
||||
$results = CoreSearch::getContactsFromGlobalDirectory($q, CoreSearch::TYPE_ALL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($results)) {
|
||||
$counter = 0;
|
||||
foreach ($results->getResults() as $result) {
|
||||
if (++$counter > $limit) {
|
||||
continue;
|
||||
}
|
||||
if ($result instanceof ContactResult) {
|
||||
$id = Contact::getIdForURL($result->getUrl(), 0, false);
|
||||
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$contacts = Contact::searchByName($q, '', $uid);
|
||||
|
||||
$counter = 0;
|
||||
foreach ($contacts as $contact) {
|
||||
if (!in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
|
||||
continue;
|
||||
}
|
||||
if (++$counter > $limit) {
|
||||
continue;
|
||||
}
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
||||
}
|
||||
DBA::close($contacts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
68
src/Module/Api/Mastodon/Apps.php
Normal file
68
src/Module/Api/Mastodon/Apps.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Apps class to register new OAuth clients
|
||||
*/
|
||||
class Apps extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
$name = !isset($_REQUEST['client_name']) ? '' : $_REQUEST['client_name'];
|
||||
$redirect = !isset($_REQUEST['redirect_uris']) ? '' : $_REQUEST['redirect_uris'];
|
||||
$scopes = !isset($_REQUEST['scopes']) ? '' : $_REQUEST['scopes'];
|
||||
$website = !isset($_REQUEST['website']) ? '' : $_REQUEST['website'];
|
||||
|
||||
if (empty($name) || empty($redirect)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$client_id = base64_encode(openssl_random_pseudo_bytes(32));
|
||||
$client_secret = bin2hex(random_bytes(32));
|
||||
|
||||
$fields = ['client_id' => $client_id, 'client_secret' => $client_secret, 'name' => $name, 'redirect_uri' => $redirect];
|
||||
|
||||
if (!empty($scopes)) {
|
||||
$fields['scopes'] = $scopes;
|
||||
}
|
||||
|
||||
if (!empty($website)) {
|
||||
$fields['website'] = $website;
|
||||
}
|
||||
|
||||
if (!DBA::insert('application', $fields)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId()));
|
||||
}
|
||||
}
|
|
@ -80,6 +80,10 @@ class Blocks extends BaseApi
|
|||
}
|
||||
DBA::close($followers);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($accounts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
||||
|
|
76
src/Module/Api/Mastodon/Lists.php
Normal file
76
src/Module/Api/Mastodon/Lists.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?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/timelines/lists/
|
||||
*/
|
||||
class Lists extends BaseApi
|
||||
{
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::unsupported('post');
|
||||
}
|
||||
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
self::unsupported('put');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
$lists = [];
|
||||
|
||||
$groups = DBA::select('group', ['id'], ['uid' => $uid, 'deleted' => false]);
|
||||
while ($group = DBA::fetch($groups)) {
|
||||
$lists[] = DI::mstdnList()->createFromGroupId($group['id']);
|
||||
}
|
||||
DBA::close($groups);
|
||||
} else {
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('group',['uid' => $uid, 'deleted' => false])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
$lists = DI::mstdnList()->createFromGroupId($id);
|
||||
}
|
||||
|
||||
System::jsonExit($lists);
|
||||
}
|
||||
}
|
102
src/Module/Api/Mastodon/Lists/Accounts.php
Normal file
102
src/Module/Api/Mastodon/Lists/Accounts.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\Lists;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/lists/
|
||||
*
|
||||
* Currently the output will be unordered since we use public contact ids in the api and not user contact ids.
|
||||
*/
|
||||
class Accounts extends BaseApi
|
||||
{
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::unsupported('post');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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('group', ['id' => $id, 'uid' => $uid])) {
|
||||
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 to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
|
||||
|
||||
|
||||
$params = ['order' => ['contact-id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['gid' => $id];
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['contact-id'];
|
||||
}
|
||||
|
||||
$members = DBA::select('group_member', ['contact-id'], $condition, $params);
|
||||
while ($member = DBA::fetch($members)) {
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
|
||||
}
|
||||
DBA::close($members);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($accounts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
59
src/Module/Api/Mastodon/Media.php
Normal file
59
src/Module/Api/Mastodon/Media.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?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\DI;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/statuses/media/
|
||||
*/
|
||||
class Media extends BaseApi
|
||||
{
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
self::unsupported('put');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 (!Photo::exists(['id' => $id, 'uid' => $uid])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
System::jsonExit(DI::mstdnAttachment()->createFromPhoto($id));
|
||||
}
|
||||
}
|
|
@ -80,6 +80,10 @@ class Mutes extends BaseApi
|
|||
}
|
||||
DBA::close($followers);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($accounts);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
||||
|
|
122
src/Module/Api/Mastodon/Notifications.php
Normal file
122
src/Module/Api/Mastodon/Notifications.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?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\Contact;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/mutes/
|
||||
*/
|
||||
class Notifications 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'])) {
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('notify', ['id' => $id, 'uid' => $uid])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
System::jsonExit(DI::mstdnNotification()->createFromNotifyId($id));
|
||||
}
|
||||
|
||||
// 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'];
|
||||
|
||||
// Return results immediately newer than this ID
|
||||
$min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id'];
|
||||
|
||||
// Maximum number of results to return (default 20)
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
// Array of types to exclude (follow, favourite, reblog, mention, poll, follow_request)
|
||||
$exclude_types = !isset($_REQUEST['exclude_types']) ? [] : $_REQUEST['exclude_types'];
|
||||
|
||||
// Return only notifications received from this account
|
||||
$account_id = (int)!isset($_REQUEST['account_id']) ? 0 : $_REQUEST['account_id'];
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['uid' => $uid, 'seen' => false, 'type' => []];
|
||||
|
||||
if (!empty($account_id)) {
|
||||
$contact = Contact::getById($account_id, ['url']);
|
||||
if (!empty($contact['url'])) {
|
||||
$condition['url'] = $contact['url'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array('follow_request', $exclude_types)) {
|
||||
$condition['type'] = array_merge($condition['type'], [Notification\Type::INTRO]);
|
||||
}
|
||||
|
||||
if (!in_array('mention', $exclude_types)) {
|
||||
$condition['type'] = array_merge($condition['type'],
|
||||
[Notification\Type::WALL, Notification\Type::COMMENT, Notification\Type::MAIL, Notification\Type::TAG_SELF, Notification\Type::POKE]);
|
||||
}
|
||||
|
||||
if (!in_array('status', $exclude_types)) {
|
||||
$condition['type'] = array_merge($condition['type'], [Notification\Type::SHARE]);
|
||||
}
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['id'];
|
||||
}
|
||||
|
||||
$notifications = [];
|
||||
|
||||
$notify = DBA::select('notify', ['id'], $condition, $params);
|
||||
while ($notification = DBA::fetch($notify)) {
|
||||
$notifications[] = DI::mstdnNotification()->createFromNotifyId($notification['id']);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($notifications);
|
||||
}
|
||||
|
||||
System::jsonExit($notifications);
|
||||
}
|
||||
}
|
61
src/Module/Api/Mastodon/Preferences.php
Normal file
61
src/Module/Api/Mastodon/Preferences.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?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\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/preferences/
|
||||
*/
|
||||
class Preferences extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$user = User::getById($uid, ['language', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
|
||||
if (!empty($user['allow_cid']) || !empty($user['allow_gid']) || !empty($user['deny_cid']) || !empty($user['deny_gid'])) {
|
||||
$visibility = 'private';
|
||||
} elseif (DI::pConfig()->get($uid, 'system', 'unlisted')) {
|
||||
$visibility = 'unlisted';
|
||||
} else {
|
||||
$visibility = 'public';
|
||||
}
|
||||
|
||||
$sensitive = false;
|
||||
$language = $user['language'];
|
||||
$media = DI::pConfig()->get($uid, 'nsfw', 'disable') ? 'show_all' : 'default';
|
||||
$spoilers = DI::pConfig()->get($uid, 'system', 'disable_cw');
|
||||
|
||||
$preferences = new \Friendica\Object\Api\Mastodon\Preferences($visibility, $sensitive, $language, $media, $spoilers);
|
||||
|
||||
System::jsonExit($preferences);
|
||||
}
|
||||
}
|
|
@ -30,8 +30,18 @@ use Friendica\BaseDataTransferObject;
|
|||
*/
|
||||
class Application extends BaseDataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
protected $client_id;
|
||||
/** @var string */
|
||||
protected $client_secret;
|
||||
/** @var int */
|
||||
protected $id;
|
||||
/** @var string */
|
||||
protected $name;
|
||||
/** @var string */
|
||||
protected $redirect_uri;
|
||||
/** @var string */
|
||||
protected $website;
|
||||
|
||||
/**
|
||||
* Creates an application entry
|
||||
|
@ -39,8 +49,36 @@ class Application extends BaseDataTransferObject
|
|||
* @param array $item
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(string $name)
|
||||
public function __construct(string $name, string $client_id = null, string $client_secret = null, int $id = null, string $redirect_uri = null, string $website = null)
|
||||
{
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->website = $website;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current entity as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$application = parent::toArray();
|
||||
|
||||
if (empty($application['id'])) {
|
||||
unset($application['client_id']);
|
||||
unset($application['client_secret']);
|
||||
unset($application['id']);
|
||||
unset($application['redirect_uri']);
|
||||
}
|
||||
|
||||
if (empty($application['website'])) {
|
||||
unset($application['website']);
|
||||
}
|
||||
|
||||
return $application;
|
||||
}
|
||||
}
|
||||
|
|
51
src/Object/Api/Mastodon/ListEntity.php
Normal file
51
src/Object/Api/Mastodon/ListEntity.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?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\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseDataTransferObject;
|
||||
|
||||
/**
|
||||
* Class ListEntity
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/list/
|
||||
*/
|
||||
class ListEntity extends BaseDataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
protected $id;
|
||||
/** @var string */
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Creates an list record
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $title
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(int $id, string $title, string $policy)
|
||||
{
|
||||
$this->id = (string)$id;
|
||||
$this->title = $title;
|
||||
$this->replies_policy = $policy;
|
||||
}
|
||||
}
|
78
src/Object/Api/Mastodon/Notification.php
Normal file
78
src/Object/Api/Mastodon/Notification.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?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\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseDataTransferObject;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
/**
|
||||
* Class Notification
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/notification/
|
||||
*/
|
||||
class Notification extends BaseDataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
protected $id;
|
||||
/** @var string (Enumerable oneOf) */
|
||||
protected $type;
|
||||
/** @var string (Datetime) */
|
||||
protected $created_at;
|
||||
/** @var Account */
|
||||
protected $account;
|
||||
/** @var Status|null */
|
||||
protected $status = null;
|
||||
|
||||
/**
|
||||
* Creates a notification record
|
||||
*
|
||||
* @param array $item
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(int $id, string $type, string $created_at, Account $account = null, Status $status = null)
|
||||
{
|
||||
$this->id = (string)$id;
|
||||
$this->type = $type;
|
||||
$this->created_at = DateTimeFormat::utc($created_at, DateTimeFormat::ATOM);
|
||||
$this->account = $account->toArray();
|
||||
|
||||
if (!empty($status)) {
|
||||
$this->status = $status->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current entity as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$notification = parent::toArray();
|
||||
|
||||
if (!$notification['status']) {
|
||||
unset($notification['status']);
|
||||
}
|
||||
|
||||
return $notification;
|
||||
}
|
||||
}
|
62
src/Object/Api/Mastodon/Preferences.php
Normal file
62
src/Object/Api/Mastodon/Preferences.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\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseDataTransferObject;
|
||||
|
||||
/**
|
||||
* Class Preferences
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/preferences/
|
||||
*/
|
||||
class Preferences extends BaseDataTransferObject
|
||||
{
|
||||
// /** @var string (Enumerable, oneOf) */
|
||||
// protected $posting_default_visibility;
|
||||
// /** @var bool */
|
||||
// protected $posting_default_sensitive;
|
||||
// /** @var string (ISO 639-1 language two-letter code), or null*/
|
||||
// protected $posting_default_language;
|
||||
// /** @var string (Enumerable, oneOf) */
|
||||
// protected $reading_expand_media;
|
||||
// /** @var bool */
|
||||
// protected $reading_expand_spoilers;
|
||||
|
||||
/**
|
||||
* Creates a preferences record.
|
||||
*
|
||||
* @param BaseURL $baseUrl
|
||||
* @param array $publicContact Full contact table record with uid = 0
|
||||
* @param array $apcontact Optional full apcontact table record
|
||||
* @param array $userContact Optional full contact table record with uid != 0
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(string $visibility, bool $sensitive, string $language, string $media, bool $spoilers)
|
||||
{
|
||||
$this->{'posting:default:visibility'} = $visibility;
|
||||
$this->{'posting:default:sensitive'} = $sensitive;
|
||||
$this->{'posting:default:language'} = $language;
|
||||
$this->{'reading:expand:media'} = $media;
|
||||
$this->{'reading:expand:spoilers'} = $spoilers;
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1414);
|
||||
define('DB_UPDATE_VERSION', 1415);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -426,6 +426,22 @@ return [
|
|||
"gsid" => ["gsid"]
|
||||
]
|
||||
],
|
||||
"application" => [
|
||||
"comment" => "OAuth application",
|
||||
"fields" => [
|
||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "generated index"],
|
||||
"client_id" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""],
|
||||
"client_secret" => ["type" => "varchar(64)", "not null" => "1", "comment" => ""],
|
||||
"name" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
|
||||
"redirect_uri" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
|
||||
"website" => ["type" => "varchar(255)", "comment" => ""],
|
||||
"scopes" => ["type" => "varchar(255)", "comment" => ""],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"],
|
||||
"client_id" => ["UNIQUE", "client_id"]
|
||||
]
|
||||
],
|
||||
"attach" => [
|
||||
"comment" => "file attachments",
|
||||
"fields" => [
|
||||
|
|
|
@ -62,7 +62,7 @@ return [
|
|||
'/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\Following::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Accounts\Lists::class, [R::GET ]],
|
||||
'/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]],
|
||||
|
@ -74,7 +74,7 @@ return [
|
|||
'/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
|
||||
'/accounts/search' => [Module\Api\Mastodon\Accounts\Search::class, [R::GET ]],
|
||||
'/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 ]], // not implemented
|
||||
|
@ -86,13 +86,13 @@ return [
|
|||
'/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' => [Module\Api\Mastodon\Apps::class, [ R::POST]],
|
||||
'/apps/verify_credentials' => [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 ]],
|
||||
'/conversations' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented
|
||||
'/conversations/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], // not implemented
|
||||
'/conversations/{id:\d+}/read' => [Module\Api\Mastodon\Unimplemented::class, [R::POST ]], // not implemented
|
||||
'/custom_emojis' => [Module\Api\Mastodon\CustomEmojis::class, [R::GET ]],
|
||||
'/domain_blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], // not implemented
|
||||
'/directory' => [Module\Api\Mastodon\Directory::class, [R::GET ]],
|
||||
|
@ -108,20 +108,20 @@ return [
|
|||
'/instance' => [Module\Api\Mastodon\Instance::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]], // @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
|
||||
'/lists' => [Module\Api\Mastodon\Lists::class, [R::GET, R::POST]],
|
||||
'/lists/{id:\d+}' => [Module\Api\Mastodon\Lists::class, [R::GET, R::PUT, R::DELETE]],
|
||||
'/lists/{id:\d+}/accounts' => [Module\Api\Mastodon\Lists\Accounts::class, [R::GET, R::POST, R::DELETE]],
|
||||
'/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]], // @todo
|
||||
'/media/{id:\d+}' => [Module\Api\Mastodon\Media::class, [R::GET, R::PUT]],
|
||||
'/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' => [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]],
|
||||
'/notifications/{id:\d+}/dismiss' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/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
|
||||
'/preferences' => [Module\Api\Mastodon\Preferences::class, [R::GET ]],
|
||||
'/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
|
||||
|
|
Loading…
Reference in a new issue