1
0
Fork 0

Allow the search for contacts on blocked servers via web

This commit is contained in:
Michael 2023-03-29 18:39:21 +00:00
parent e6ce165bb5
commit f0743e4e12
4 changed files with 15 additions and 11 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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);
}

View file

@ -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);
}