X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FApi%2FMastodon%2FAccounts%2FFollowers.php;h=19f2a438838041540f6c833854255f87d754502b;hb=7486ebdc10715b7204b70ce262052d28cb61c69e;hp=4c1a6429c5dcaccc5c1a470413243d9f700b65fe;hpb=87084a3e854b72290fcc49e66fd0ccdf737672ee;p=friendica.git diff --git a/src/Module/Api/Mastodon/Accounts/Followers.php b/src/Module/Api/Mastodon/Accounts/Followers.php index 4c1a6429c5..19f2a43883 100644 --- a/src/Module/Api/Mastodon/Accounts/Followers.php +++ b/src/Module/Api/Mastodon/Accounts/Followers.php @@ -1,6 +1,6 @@ checkAllowedScope(self::SCOPE_READ); $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - DI::mstdnError()->UnprocessableEntity(); + $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } - $request = self::getRequest([ + $request = $this->getRequest([ 'max_id' => 0, // Return results older than this id 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results to return. Defaults to 40. - ]); + ], $request); - $params = ['order' => ['relation-cid' => true], 'limit' => $request['limit']]; + if ($id == Contact::getPublicIdByUserId($uid)) { + $params = ['order' => ['pid' => true], 'limit' => $request['limit']]; - $condition = ['cid' => $id, 'follows' => true]; + $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; - if (!empty($request['max_id'])) { - $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $request['max_id']]); - } + if (!empty($request['max_id'])) { + $condition = DBA::mergeConditions($condition, ["`pid` < ?", $request['max_id']]); + } - if (!empty($request['since_id'])) { - $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['since_id']]); - } + if (!empty($request['since_id'])) { + $condition = DBA::mergeConditions($condition, ["`pid` > ?", $request['since_id']]); + } - if (!empty($request['min_id'])) { - $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['min_id']]); + if (!empty($request['min_id'])) { + $condition = DBA::mergeConditions($condition, ["`pid` > ?", $request['min_id']]); - $params['order'] = ['cid']; - } + $params['order'] = ['pid']; + } + + $accounts = []; + + foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) { + self::setBoundaries($follower['pid']); + $accounts[] = DI::mstdnAccount()->createFromContactId($follower['pid'], $uid); + } + } else { + $params = ['order' => ['relation-cid' => true], 'limit' => $request['limit']]; + + $condition = ['cid' => $id, 'follows' => true]; + + if (!empty($request['max_id'])) { + $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $request['max_id']]); + } + + if (!empty($request['since_id'])) { + $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['since_id']]); + } + + if (!empty($request['min_id'])) { + $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $request['min_id']]); + + $params['order'] = ['relation-cid']; + } + + $accounts = []; - $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params); - while ($follower = DBA::fetch($followers)) { - self::setBoundaries($follower['relation-cid']); - $accounts[] = DI::mstdnAccount()->createFromContactId($follower['relation-cid'], $uid); + $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params); + while ($follower = DBA::fetch($followers)) { + self::setBoundaries($follower['relation-cid']); + $accounts[] = DI::mstdnAccount()->createFromContactId($follower['relation-cid'], $uid); + } + DBA::close($followers); } - DBA::close($followers); if (!empty($request['min_id'])) { - array_reverse($accounts); + $accounts = array_reverse($accounts); } self::setLinkHeader(); - System::jsonExit($accounts); + $this->jsonExit($accounts); } }