Update FederationController, add proper following/follower counts

This commit is contained in:
Daniel Supernault 2023-12-05 00:48:14 -07:00
parent 6ffc964371
commit 3204fb9669
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -30,6 +30,7 @@ use App\Util\ActivityPub\{
};
use Zttp\Zttp;
use App\Services\InstanceService;
use App\Services\AccountService;
class FederationController extends Controller
{
@ -239,12 +240,15 @@ class FederationController extends Controller
{
abort_if(!config_cache('federation.activitypub.enabled'), 404);
$id = AccountService::usernameToId($username);
abort_if(!$id, 404);
$account = AccountService::get($id);
abort_if(!$account || !isset($account['following_count']), 404);
$obj = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $request->getUri(),
'type' => 'OrderedCollectionPage',
'totalItems' => 0,
'orderedItems' => []
'type' => 'OrderedCollection',
'totalItems' => $account['following_count'] ?? 0,
];
return response()->json($obj);
}
@ -252,15 +256,16 @@ class FederationController extends Controller
public function userFollowers(Request $request, $username)
{
abort_if(!config_cache('federation.activitypub.enabled'), 404);
$id = AccountService::usernameToId($username);
abort_if(!$id, 404);
$account = AccountService::get($id);
abort_if(!$account || !isset($account['followers_count']), 404);
$obj = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $request->getUri(),
'type' => 'OrderedCollectionPage',
'totalItems' => 0,
'orderedItems' => []
'type' => 'OrderedCollection',
'totalItems' => $account['followers_count'] ?? 0,
];
return response()->json($obj);
}
}