Merge pull request #10376 from annando/api-swap-followers

API: The endpoints "followers" and "following" are swapped
This commit is contained in:
Tobias Diekershoff 2021-06-07 10:27:55 +02:00 committed by GitHub
commit a95825dd6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View file

@ -54,30 +54,30 @@ class Followers extends BaseApi
$request = self::getRequest([ $request = self::getRequest([
'max_id' => 0, // Return results older than this id 'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id 'since_id' => 0, // Return results newer than this id
'limit' => 20, // Maximum number of results to return. Defaults to 20. 'limit' => 40, // Maximum number of results to return. Defaults to 40.
]); ]);
$params = ['order' => ['cid' => true], 'limit' => $request['limit']]; $params = ['order' => ['relation-cid' => true], 'limit' => $request['limit']];
$condition = ['relation-cid' => $id, 'follows' => true]; $condition = ['cid' => $id, 'follows' => true];
if (!empty($request['max_id'])) { if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`cid` < ?", $request['max_id']]); $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $request['max_id']]);
} }
if (!empty($request['since_id'])) { if (!empty($request['since_id'])) {
$condition = DBA::mergeConditions($condition, ["`cid` > ?", $request['since_id']]); $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['since_id']]);
} }
if (!empty($min_id)) { if (!empty($min_id)) {
$condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]); $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
$params['order'] = ['cid']; $params['order'] = ['cid'];
} }
$followers = DBA::select('contact-relation', ['cid'], $condition, $parameters); $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $parameters);
while ($follower = DBA::fetch($followers)) { while ($follower = DBA::fetch($followers)) {
$accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid); $accounts[] = DI::mstdnAccount()->createFromContactId($follower['relation-cid'], $uid);
} }
DBA::close($followers); DBA::close($followers);

View file

@ -57,27 +57,27 @@ class Following extends BaseApi
'limit' => 40, // Maximum number of results to return. Defaults to 40. 'limit' => 40, // Maximum number of results to return. Defaults to 40.
]); ]);
$params = ['order' => ['relation-cid' => true], 'limit' => $request['limit']]; $params = ['order' => ['cid' => true], 'limit' => $request['limit']];
$condition = ['cid' => $id, 'follows' => true]; $condition = ['relation-cid' => $id, 'follows' => true];
if (!empty($request['max_id'])) { if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $request['max_id']]); $condition = DBA::mergeConditions($condition, ["`cid` < ?", $request['max_id']]);
} }
if (!empty($request['since_id'])) { if (!empty($request['since_id'])) {
$condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['since_id']]); $condition = DBA::mergeConditions($condition, ["`cid` > ?", $request['since_id']]);
} }
if (!empty($min_id)) { if (!empty($min_id)) {
$condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]); $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
$params['order'] = ['cid']; $params['order'] = ['cid'];
} }
$followers = DBA::select('contact-relation', ['relation-cid'], $condition, $parameters); $followers = DBA::select('contact-relation', ['cid'], $condition, $parameters);
while ($follower = DBA::fetch($followers)) { while ($follower = DBA::fetch($followers)) {
$accounts[] = DI::mstdnAccount()->createFromContactId($follower['relation-cid'], $uid); $accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid);
} }
DBA::close($followers); DBA::close($followers);

View file

@ -47,6 +47,13 @@ class Tag extends BaseApi
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
/**
* @todo Respect missing parameters
* @see https://github.com/tootsuite/mastodon/blob/main/app/controllers/api/v1/timelines/tag_controller.rb
*
* There seem to be the parameters "any", "all", and "none".
*/
$request = self::getRequest([ $request = self::getRequest([
'local' => false, // If true, return only local statuses. Defaults to false. 'local' => false, // If true, return only local statuses. Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false. 'remote' => false, // Show only remote statuses? Defaults to false.