Merge pull request #10248 from annando/api-accounts
API: Account actions
This commit is contained in:
commit
84efabbfb6
|
@ -13,17 +13,18 @@ Authentication is the same as described in [Using the APIs](help/api#Authenticat
|
|||
|
||||
Supported mobile apps:
|
||||
|
||||
- [Tusky](https://tusky.app)
|
||||
- [Husky](https://husky.fwgs.ru)
|
||||
- [twitlatte](https://github.com/moko256/twitlatte)
|
||||
- [AndStatus](http://andstatus.org)
|
||||
- [Twidere](https://github.com/TwidereProject/)
|
||||
- [Husky](https://husky.fwgs.ru)
|
||||
- [Subway Tooter](https://github.com/tateisu/SubwayTooter)
|
||||
- [Tusky](https://tusky.app)
|
||||
- [Twidere](https://github.com/TwidereProject/)
|
||||
- [twitlatte](https://github.com/moko256/twitlatte)
|
||||
- [Yuito](https://github.com/accelforce/Yuito)
|
||||
|
||||
Unsupported mobile apps:
|
||||
|
||||
- [Mammut](https://github.com/jamiesanson/Mammut) There are problems with the token request, see issue https://github.com/jamiesanson/Mammut/issues/19
|
||||
- [Fedilab](https://framagit.org/tom79/fedilab) Automatically uses the legacy API, see issue: https://framagit.org/tom79/fedilab/-/issues/520
|
||||
- [Mammut](https://github.com/jamiesanson/Mammut) There are problems with the token request, see issue https://github.com/jamiesanson/Mammut/issues/19
|
||||
|
||||
## Entities
|
||||
|
||||
|
@ -32,12 +33,23 @@ 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/)
|
||||
- [`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/)
|
||||
- [`POST /api/v1/accounts/:id/follow`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/unfollow`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/block`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/unblock`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/mute`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/unmute`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`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)
|
||||
- [`POST /api/v1/apps`](https://docs.joinmastodon.org/methods/apps/)
|
||||
- [`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/custom_emojis`](https://docs.joinmastodon.org/methods/instance/custom_emojis/)
|
||||
|
@ -61,8 +73,13 @@ 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/)
|
||||
- [`POST /api/v1/lists`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`GET /api/v1/lists/:id`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`PUT /api/v1/lists/:id`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`DELETE /api/v1/lists/:id`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`GET /api/v1/lists/:id/accounts`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`POST /api/v1/lists/:id/accounts`](https://docs.joinmastodon.org/methods/timelines/lists/)
|
||||
- [`DELETE /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/)
|
||||
|
@ -79,6 +96,76 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
|
|||
- [`GET /api/v1/timelines/tag/:hashtag`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
- [`GET /api/v1/trends`](https://docs.joinmastodon.org/methods/instance/trends/)
|
||||
|
||||
## Non-implemented endpoints
|
||||
|
||||
## Currently unimplemented endpoints
|
||||
|
||||
These emdpoints are planned to be implemented
|
||||
|
||||
- [`POST /api/v1/accounts/:id/note`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`GET /api/v1/accounts/relationships`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`PATCH /api/v1/accounts/update_credentials`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`GET /api/v1/apps/verify_credentials`](https://docs.joinmastodon.org/methods/apps/)
|
||||
- [`GET /api/v1/conversations`](https://docs.joinmastodon.org/methods/timelines/conversations/)
|
||||
- [`DELETE /api/v1/conversations/:id`](https://docs.joinmastodon.org/methods/timelines/conversations/)
|
||||
- [`POST /api/v1/conversations/:id/read`](https://docs.joinmastodon.org/methods/timelines/conversations/)
|
||||
- [`GET /api/v1/instance/activity`](https://docs.joinmastodon.org/methods/instance#weekly-activity)
|
||||
- [`POST /api/v1/media`](https://docs.joinmastodon.org/methods/statuses/media/)
|
||||
- [`PUT /api/v1/media/:id`](https://docs.joinmastodon.org/methods/statuses/media/)
|
||||
- [`POST /api/v1/notifications/clear`](https://docs.joinmastodon.org/methods/notifications/)
|
||||
- [`POST /api/v1/notifications/:id/dismiss`](https://docs.joinmastodon.org/methods/notifications/)
|
||||
- [`POST /api/v1/statuses`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`DELETE /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/favourite`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/unfavourite`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/reblog`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/unreblog`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/bookmark`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/unbookmark`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/mute`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/unmute`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/pin`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`POST /api/v1/statuses/:id/unpin`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`GET /api/v1/timelines/direct`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
|
||||
## Non supportable endpoints
|
||||
|
||||
These endpoints won't be implemented, since they refer to functionality that doesn't exist in Friendica
|
||||
|
||||
- [`GET /api/v1/instance/activity`](https://docs.joinmastodon.org/methods/instance#weekly-activity)
|
||||
- [`POST /api/v1/accounts`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`GET /api/v1/accounts/:id/identity_proofs`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/pin`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`POST /api/v1/accounts/:id/unpin`](https://docs.joinmastodon.org/methods/accounts/)
|
||||
- [`GET /api/v1/admin/accounts`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`GET /api/v1/admin/accounts/:id`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`POST /api/v1/admin/accounts/:id/{action}`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`GET /api/v1/admin/reports`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`GET /api/v1/admin/reports/:id`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`POST /api/v1/admin/reports/:id/{action}`](https://docs.joinmastodon.org/methods/admin/)
|
||||
- [`GET /api/v1/announcements`](https://docs.joinmastodon.org/methods/announcements/)
|
||||
- [`POST /api/v1/announcements/:id/dismiss`](https://docs.joinmastodon.org/methods/announcements/)
|
||||
- [`PUT /api/v1/announcements/:id/reactions/{name}`](https://docs.joinmastodon.org/methods/announcements/)
|
||||
- [`DELETE /api/v1/announcements/:id/reactions/{name}`](https://docs.joinmastodon.org/methods/announcements/)
|
||||
- [`GET /api/v1/domain_blocks`](https://docs.joinmastodon.org/methods/accounts/domain_blocks/)
|
||||
- [`POST /api/v1/domain_blocks`](https://docs.joinmastodon.org/methods/accounts/domain_blocks/)
|
||||
- [`DELETE /api/v1/domain_blocks`](https://docs.joinmastodon.org/methods/accounts/domain_blocks/)
|
||||
- [`GET /api/v1/endorsements`](https://docs.joinmastodon.org/methods/accounts/endorsements/)
|
||||
- [`GET /api/v1/featured_tags`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
|
||||
- [`POST /api/v1/featured_tags`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
|
||||
- [`DELETE /api/v1/featured_tags/:id`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
|
||||
- [`GET /api/v1/featured_tags/suggestions`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
|
||||
- [`GET /api/v1/filters`](https://docs.joinmastodon.org/methods/accounts/filters/)
|
||||
- [`GET /api/v1/filters/:id`](https://docs.joinmastodon.org/methods/accounts/filters/)
|
||||
- [`POST /api/v1/filters/:id`](https://docs.joinmastodon.org/methods/accounts/filters/)
|
||||
- [`PUT /api/v1/filters/:id`](https://docs.joinmastodon.org/methods/accounts/filters/)
|
||||
- [`DELETE /api/v1/filters/:id`](https://docs.joinmastodon.org/methods/accounts/filters/)
|
||||
- [`GET /api/v1/markers`](https://docs.joinmastodon.org/methods/timelines/markers/)
|
||||
- [`POST /api/v1/markers`](https://docs.joinmastodon.org/methods/timelines/markers/)
|
||||
- [`GET /api/v1/polls/:id`](https://docs.joinmastodon.org/methods/statuses/polls/)
|
||||
- [`POST /api/v1/polls/:id/votes`](https://docs.joinmastodon.org/methods/statuses/polls/)
|
||||
- [`POST /api/v1/reports`](https://docs.joinmastodon.org/methods/accounts/reports/)
|
||||
- [`GET /api/v1/scheduled_statuses`](https://docs.joinmastodon.org/methods/statuses/scheduled_statuses/)
|
||||
- [`GET /api/v1/scheduled_statuses/:id`](https://docs.joinmastodon.org/methods/statuses/scheduled_statuses/)
|
||||
- [`PUT /api/v1/scheduled_statuses/:id`](https://docs.joinmastodon.org/methods/statuses/scheduled_statuses/)
|
||||
- [`DELETE /api/v1/scheduled_statuses/:id`](https://docs.joinmastodon.org/methods/statuses/scheduled_statuses/)
|
||||
- [`DELETE /api/v1/suggestions/:id`](https://docs.joinmastodon.org/methods/accounts/suggestions/)
|
||||
|
|
|
@ -37,13 +37,33 @@ class Relationship extends BaseFactory
|
|||
return $this->createFromContact(Contact::getById($userContactId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $publicContactId Contact row id with uid = 0
|
||||
* @param int $uid User ID
|
||||
* @return RelationshipEntity
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromPublicContactId(int $publicContactId, int $uid)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContacID($publicContactId, $uid);
|
||||
if (!empty($cdata)) {
|
||||
$cid = $cdata['user'];
|
||||
} else {
|
||||
$cid = $publicContactId;
|
||||
}
|
||||
|
||||
return $this->createFromContact(Contact::getById($cid));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userContact Full contact row record with uid != 0
|
||||
* @return RelationshipEntity
|
||||
*/
|
||||
public function createFromContact(array $userContact)
|
||||
{
|
||||
return new RelationshipEntity($userContact['id'], $userContact);
|
||||
return new RelationshipEntity($userContact['id'], $userContact,
|
||||
Contact\User::isBlocked($userContact['id'], $userContact['uid']),
|
||||
Contact\User::isIgnored($userContact['id'], $userContact['uid']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2409,6 +2409,50 @@ class Contact
|
|||
return $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow a contact
|
||||
*
|
||||
* @param int $cid Public contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return bool "true" if following had been successful
|
||||
*/
|
||||
public static function follow(int $cid, int $uid)
|
||||
{
|
||||
$user = User::getById($uid);
|
||||
if (empty($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contact = self::getById($cid, ['url']);
|
||||
|
||||
$result = self::createFromProbe($user, $contact['url'], false);
|
||||
|
||||
return $result['cid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Unfollow a contact
|
||||
*
|
||||
* @param int $cid Public contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return bool "true" if unfollowing had been successful
|
||||
*/
|
||||
public static function unfollow(int $cid, int $uid)
|
||||
{
|
||||
$cdata = self::getPublicAndUserContacID($cid, $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contact = self::getById($cdata['user']);
|
||||
|
||||
self::removeSharer([], $contact);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $importer Owner (local user) data
|
||||
* @param array $contact Existing owner-specific contact data we want to expand the relationship with. Optional.
|
||||
|
@ -2554,7 +2598,7 @@ class Contact
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function removeFollower($importer, $contact, array $datarray = [], $item = "")
|
||||
public static function removeFollower($importer, $contact)
|
||||
{
|
||||
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) {
|
||||
DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]);
|
||||
|
@ -2563,7 +2607,7 @@ class Contact
|
|||
}
|
||||
}
|
||||
|
||||
public static function removeSharer($importer, $contact, array $datarray = [], $item = "")
|
||||
public static function removeSharer($importer, $contact)
|
||||
{
|
||||
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::FOLLOWER)) {
|
||||
DBA::update('contact', ['rel' => self::FOLLOWER], ['id' => $contact['id']]);
|
||||
|
|
47
src/Module/Api/Mastodon/Accounts/Block.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Block.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Block extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($parameters['id'], $uid, true);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
47
src/Module/Api/Mastodon/Accounts/Follow.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Follow.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Follow extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
$cid = Contact::follow($parameters['id'], self::getCurrentUserID());
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($cid)->toArray());
|
||||
}
|
||||
}
|
47
src/Module/Api/Mastodon/Accounts/Mute.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Mute.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Mute extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($parameters['id'], $uid, true);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
47
src/Module/Api/Mastodon/Accounts/Unblock.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Unblock.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Unblock extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($parameters['id'], $uid, false);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
47
src/Module/Api/Mastodon/Accounts/Unfollow.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Unfollow.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Unfollow extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
Contact::unfollow($parameters['id'], $uid);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
47
src/Module/Api/Mastodon/Accounts/Unmute.php
Normal file
47
src/Module/Api/Mastodon/Accounts/Unmute.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Unmute extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($parameters['id'], $uid, false);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@ class Favourited extends BaseApi
|
|||
|
||||
$params = ['order' => ['thr-parent-id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'uid' => $uid];
|
||||
$condition = ['gravity' => GRAVITY_ACTIVITY, 'origin' => true, 'verb' => Activity::LIKE, 'uid' => $uid];
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`thr-parent-id` < ?", $max_id]);
|
||||
|
|
|
@ -37,42 +37,61 @@ class Relationship extends BaseDataTransferObject
|
|||
/** @var bool */
|
||||
protected $following = false;
|
||||
/** @var bool */
|
||||
protected $followed_by = false;
|
||||
protected $requested = false;
|
||||
/**
|
||||
* Unsupported
|
||||
* @var bool
|
||||
*/
|
||||
protected $endorsed = false;
|
||||
/** @var bool */
|
||||
protected $blocking = false;
|
||||
protected $followed_by = false;
|
||||
/** @var bool */
|
||||
protected $muting = false;
|
||||
/** @var bool */
|
||||
protected $muting_notifications = false;
|
||||
/**
|
||||
* Unsupported
|
||||
* @var bool
|
||||
*/
|
||||
protected $showing_reblogs = true;
|
||||
/** @var bool */
|
||||
protected $requested = false;
|
||||
protected $notifying = false;
|
||||
/** @var bool */
|
||||
protected $blocking = false;
|
||||
/** @var bool */
|
||||
protected $domain_blocking = false;
|
||||
/**
|
||||
* Unsupported
|
||||
* @var bool
|
||||
*/
|
||||
protected $showing_reblogs = true;
|
||||
protected $blocked_by = false;
|
||||
/**
|
||||
* Unsupported
|
||||
* @var bool
|
||||
* @var string
|
||||
*/
|
||||
protected $endorsed = false;
|
||||
protected $note = '';
|
||||
|
||||
/**
|
||||
* @param int $userContactId Contact row Id with uid != 0
|
||||
* @param array $userContact Full Contact table record with uid != 0
|
||||
* @param bool $blocked "true" if user is blocked
|
||||
* @param bool $muted "true" if user is muted
|
||||
*/
|
||||
public function __construct(int $userContactId, array $userContact = [])
|
||||
public function __construct(int $userContactId, array $userContact = [], bool $blocked = false, bool $muted = false)
|
||||
{
|
||||
$this->id = $userContactId;
|
||||
$this->following = in_array($userContact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
|
||||
$this->followed_by = in_array($userContact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||
$this->blocking = (bool)$userContact['blocked'] ?? false;
|
||||
$this->muting = (bool)$userContact['readonly'] ?? false;
|
||||
$this->muting_notifications = (bool)$userContact['readonly'] ?? false;
|
||||
$this->requested = (bool)$userContact['pending'] ?? false;
|
||||
$this->endorsed = false;
|
||||
$this->followed_by = in_array($userContact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||
$this->muting = (bool)($userContact['readonly'] ?? false) || $muted;
|
||||
$this->muting_notifications = $this->muting;
|
||||
$this->showing_reblogs = true;
|
||||
$this->notifying = (bool)$userContact['notify_new_posts'] ?? false;
|
||||
$this->blocking = (bool)($userContact['blocked'] ?? false) || $blocked;
|
||||
$this->domain_blocking = Network::isUrlBlocked($userContact['url'] ?? '');
|
||||
$this->blocked_by = false;
|
||||
$this->note = '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -64,12 +64,12 @@ return [
|
|||
'/accounts/{id:\d+}/following' => [Module\Api\Mastodon\Accounts\Following::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Accounts\Lists::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/identity_proofs' => [Module\Api\Mastodon\Accounts\IdentityProofs::class, [R::GET ]], // Dummy, not supported
|
||||
'/accounts/{id:\d+}/follow' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/unfollow' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/block' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/unblock' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/mute' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/unmute' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/accounts/{id:\d+}/follow' => [Module\Api\Mastodon\Accounts\Follow::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/unfollow' => [Module\Api\Mastodon\Accounts\Unfollow::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/block' => [Module\Api\Mastodon\Accounts\Block::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/unblock' => [Module\Api\Mastodon\Accounts\Unblock::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/mute' => [Module\Api\Mastodon\Accounts\Mute::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/unmute' => [Module\Api\Mastodon\Accounts\Unmute::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not supported
|
||||
'/accounts/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not supported
|
||||
'/accounts/{id:\d+}/note' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
|
@ -90,9 +90,9 @@ return [
|
|||
'/apps/verify_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/blocks' => [Module\Api\Mastodon\Blocks::class, [R::GET ]],
|
||||
'/bookmarks' => [Module\Api\Mastodon\Bookmarks::class, [R::GET ]],
|
||||
'/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
|
||||
'/conversations' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/conversations/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], // @todo
|
||||
'/conversations/{id:\d+}/read' => [Module\Api\Mastodon\Unimplemented::class, [R::POST ]], // @todo
|
||||
'/custom_emojis' => [Module\Api\Mastodon\CustomEmojis::class, [R::GET ]],
|
||||
'/domain_blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::POST, R::DELETE]], // not supported
|
||||
'/directory' => [Module\Api\Mastodon\Directory::class, [R::GET ]],
|
||||
|
@ -142,6 +142,7 @@ return [
|
|||
'/statuses/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // @todo
|
||||
'/suggestions' => [Module\Api\Mastodon\Suggestions::class, [R::GET ]],
|
||||
'/suggestions/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]], // not implemented
|
||||
'/timelines/direct' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/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 ]],
|
||||
|
|
Loading…
Reference in a new issue