From f0743e4e128dfcb5d6305f4ed09e969573ba6b15 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 29 Mar 2023 18:39:21 +0000 Subject: [PATCH] Allow the search for contacts on blocked servers via web --- src/Core/Search.php | 4 ++-- src/Model/Contact.php | 18 +++++++++++------- src/Module/Api/Mastodon/Accounts/Search.php | 2 +- src/Module/Api/Mastodon/Search.php | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Core/Search.php b/src/Core/Search.php index b641f2897..7f05a3a94 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -171,7 +171,7 @@ class Search { Logger::info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]); - $contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : ''); + $contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : '', true); $resultList = new ResultList($start, $itemPage, count($contacts)); @@ -226,7 +226,7 @@ class Search // check if searching in the local global contact table is enabled if (DI::config()->get('system', 'poco_local_search')) { - $return = Contact::searchByName($search, $mode); + $return = Contact::searchByName($search, $mode, true); } else { $p = $page > 1 ? 'p=' . $page : ''; $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d93c5f836..cf1b528da 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -3504,16 +3504,17 @@ class Contact /** * Search contact table by nick or name * - * @param string $search Name or nick - * @param string $mode Search mode (e.g. "community") - * @param int $uid User ID - * @param int $limit Maximum amount of returned values - * @param int $offset Limit offset + * @param string $search Name or nick + * @param string $mode Search mode (e.g. "community") + * @param bool $show_blocked Show users from blocked servers. Default is false + * @param int $uid User ID + * @param int $limit Maximum amount of returned values + * @param int $offset Limit offset * * @return array with search results * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function searchByName(string $search, string $mode = '', int $uid = 0, int $limit = 0, int $offset = 0): array + public static function searchByName(string $search, string $mode = '', bool $show_blocked = false, int $uid = 0, int $limit = 0, int $offset = 0): array { if (empty($search)) { return []; @@ -3532,13 +3533,16 @@ class Contact $condition = [ 'network' => $networks, 'server-failed' => false, - 'server-blocked' => false, 'failed' => false, 'deleted' => false, 'unsearchable' => false, 'uid' => $uid ]; + if (!$show_blocked) { + $condition['server-blocked'] = true; + } + if ($uid == 0) { $condition['blocked'] = false; } else { diff --git a/src/Module/Api/Mastodon/Accounts/Search.php b/src/Module/Api/Mastodon/Accounts/Search.php index 5a03cba19..527616164 100644 --- a/src/Module/Api/Mastodon/Accounts/Search.php +++ b/src/Module/Api/Mastodon/Accounts/Search.php @@ -60,7 +60,7 @@ class Search extends BaseApi } if (empty($accounts)) { - $contacts = Contact::searchByName($request['q'], '', $request['following'] ? $uid : 0, $request['limit'], $request['offset']); + $contacts = Contact::searchByName($request['q'], '', false, $request['following'] ? $uid : 0, $request['limit'], $request['offset']); foreach ($contacts as $contact) { $accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid); } diff --git a/src/Module/Api/Mastodon/Search.php b/src/Module/Api/Mastodon/Search.php index 69e262768..956e3d73b 100644 --- a/src/Module/Api/Mastodon/Search.php +++ b/src/Module/Api/Mastodon/Search.php @@ -115,7 +115,7 @@ class Search extends BaseApi } $accounts = []; - foreach (Contact::searchByName($q, '', $following ? $uid : 0, $limit, $offset) as $contact) { + foreach (Contact::searchByName($q, '', $following ? $uid : 0, false, $limit, $offset) as $contact) { $accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid); }