From dc71b89d3ee5fe49c7ef3f654d016f2dfbde5201 Mon Sep 17 00:00:00 2001 From: Bofh Date: Thu, 1 Dec 2022 01:17:41 +0100 Subject: [PATCH] Add following/followers/statuses to search result --- api/v1/database/mastodon/accounts/search/index.php | 9 +++++++++ classes/PgDatabase.php | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/api/v1/database/mastodon/accounts/search/index.php b/api/v1/database/mastodon/accounts/search/index.php index 1b963e3..05af701 100644 --- a/api/v1/database/mastodon/accounts/search/index.php +++ b/api/v1/database/mastodon/accounts/search/index.php @@ -136,7 +136,16 @@ foreach ($filtered_accounts as $id) { $newacc['avatar'] .= '/cache'; $newacc['avatar'] .= '/accounts/avatars/'.implode('/',$parts).'/original/'.$account['avatar_file_name']; } + + $following = $pg->fetch_one('SELECT count(1) FROM follows WHERE account_id = \''.$id.'\''); + $newacc['following'] = intval($following['count']); + $followers = $pg->fetch_one('SELECT count(1) FROM follows WHERE target_account_id = \''.$id.'\''); + $newacc['followers'] = intval($followers['count']); + $statuses = $pg->fetch_one('SELECT count(1) FROM statuses WHERE account_id = \''.$id.'\''); + $newacc['statuses'] = intval($statuses['count']); + $result_accounts []= $newacc; } +$pg->close(); apiresult($result_accounts); diff --git a/classes/PgDatabase.php b/classes/PgDatabase.php index d670255..0dc2ac5 100644 --- a/classes/PgDatabase.php +++ b/classes/PgDatabase.php @@ -36,6 +36,11 @@ class PgDatabase { return $result; } + public function fetch_one($sql) { + $result = $this->query($sql); + return pg_fetch_assoc($result); + } + public function fetch_all($sql) { $data = []; $result = $this->query($sql);