mirror of
https://github.com/friendica/friendica
synced 2025-04-22 01:50:11 +00:00
API: Fix relationships
This commit is contained in:
parent
78dab01696
commit
f001f52e39
13 changed files with 121 additions and 85 deletions
|
@ -42,6 +42,6 @@ class Block extends BaseApi
|
|||
|
||||
Contact\User::setBlocked($parameters['id'], $uid, true);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ class Mute extends BaseApi
|
|||
|
||||
Contact\User::setIgnored($parameters['id'], $uid, true);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
53
src/Module/Api/Mastodon/Accounts/Note.php
Normal file
53
src/Module/Api/Mastodon/Accounts/Note.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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 Note extends BaseApi
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContacID($parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
DBA::update('contact', ['info' => $_REQUEST['comment'] ?? ''], ['id' => $cdata['user']]);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
@ -39,15 +40,14 @@ class Relationships extends BaseApi
|
|||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
if (empty($_REQUEST['id']) || !is_array($_REQUEST['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
$relationsships = [];
|
||||
|
||||
foreach ($parameters['id'] as $id) {
|
||||
$relationsships[] = DI::mstdnRelationship()->createFromPublicContactId($id, $uid);
|
||||
foreach ($_REQUEST['id'] as $id) {
|
||||
$relationsships[] = DI::mstdnRelationship()->createFromContactId($id, $uid);
|
||||
}
|
||||
|
||||
System::jsonExit($relationsships);
|
|
@ -62,6 +62,9 @@ class Statuses extends BaseApi
|
|||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
$pinned = (bool)!isset($_REQUEST['pinned']) ? false : ($_REQUEST['pinned'] == 'true');
|
||||
$exclude_replies = (bool)!isset($_REQUEST['exclude_replies']) ? false : ($_REQUEST['exclude_replies'] == 'true');
|
||||
|
||||
$params = ['order' => ['uri-id' => true], 'limit' => $limit];
|
||||
|
||||
$uid = self::getCurrentUserID();
|
||||
|
@ -94,6 +97,14 @@ class Statuses extends BaseApi
|
|||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
if ($pinned) {
|
||||
$condition = DBA::mergeConditions($condition, ['pinned' => true]);
|
||||
}
|
||||
|
||||
if ($exclude_replies) {
|
||||
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
|
||||
}
|
||||
|
||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
|
|
|
@ -42,6 +42,6 @@ class Unblock extends BaseApi
|
|||
|
||||
Contact\User::setBlocked($parameters['id'], $uid, false);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ class Unfollow extends BaseApi
|
|||
|
||||
Contact::unfollow($parameters['id'], $uid);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ class Unmute extends BaseApi
|
|||
|
||||
Contact\User::setIgnored($parameters['id'], $uid, false);
|
||||
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromPublicContactId($parameters['id'], $uid)->toArray());
|
||||
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,15 +31,6 @@ use Friendica\Network\HTTPException;
|
|||
*/
|
||||
class FollowRequests extends BaseApi
|
||||
{
|
||||
public static function init(array $parameters = [])
|
||||
{
|
||||
parent::init($parameters);
|
||||
|
||||
if (!self::login()) {
|
||||
throw new HTTPException\UnauthorizedException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\BadRequestException
|
||||
|
@ -54,9 +45,10 @@ class FollowRequests extends BaseApi
|
|||
*/
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
parent::post($parameters);
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$introduction = DI::intro()->selectFirst(['id' => $parameters['id'], 'uid' => self::$current_user_id]);
|
||||
$introduction = DI::intro()->selectFirst(['id' => $parameters['id'], 'uid' => $uid]);
|
||||
|
||||
$contactId = $introduction->{'contact-id'};
|
||||
|
||||
|
@ -64,17 +56,17 @@ class FollowRequests extends BaseApi
|
|||
case 'authorize':
|
||||
$introduction->confirm();
|
||||
|
||||
$relationship = DI::mstdnRelationship()->createFromContactId($contactId);
|
||||
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
||||
break;
|
||||
case 'ignore':
|
||||
$introduction->ignore();
|
||||
|
||||
$relationship = DI::mstdnRelationship()->createDefaultFromContactId($contactId);
|
||||
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
||||
break;
|
||||
case 'reject':
|
||||
$introduction->discard();
|
||||
|
||||
$relationship = DI::mstdnRelationship()->createDefaultFromContactId($contactId);
|
||||
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
||||
break;
|
||||
default:
|
||||
throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"');
|
||||
|
@ -91,6 +83,9 @@ class FollowRequests extends BaseApi
|
|||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$min_id = $_GET['min_id'] ?? null;
|
||||
$max_id = $_GET['max_id'] ?? null;
|
||||
$limit = intval($_GET['limit'] ?? 40);
|
||||
|
@ -98,7 +93,7 @@ class FollowRequests extends BaseApi
|
|||
$baseUrl = DI::baseUrl();
|
||||
|
||||
$introductions = DI::intro()->selectByBoundaries(
|
||||
['`uid` = ? AND NOT `ignore`', self::$current_user_id],
|
||||
['`uid` = ? AND NOT `ignore`', $uid],
|
||||
['order' => ['id' => 'DESC']],
|
||||
$min_id,
|
||||
$max_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue