API: Fix relationships

This commit is contained in:
Michael 2021-05-15 15:02:15 +00:00
parent 78dab01696
commit f001f52e39
13 changed files with 121 additions and 85 deletions

View file

@ -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());
}
}

View file

@ -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());
}
}

View 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());
}
}

View file

@ -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);

View file

@ -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 = [];

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -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());
}
}