Allow the search for contacts on blocked servers via web
This commit is contained in:
parent
e6ce165bb5
commit
f0743e4e12
4 changed files with 15 additions and 11 deletions
|
@ -171,7 +171,7 @@ class Search
|
||||||
{
|
{
|
||||||
Logger::info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]);
|
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));
|
$resultList = new ResultList($start, $itemPage, count($contacts));
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ class Search
|
||||||
|
|
||||||
// check if searching in the local global contact table is enabled
|
// check if searching in the local global contact table is enabled
|
||||||
if (DI::config()->get('system', 'poco_local_search')) {
|
if (DI::config()->get('system', 'poco_local_search')) {
|
||||||
$return = Contact::searchByName($search, $mode);
|
$return = Contact::searchByName($search, $mode, true);
|
||||||
} else {
|
} else {
|
||||||
$p = $page > 1 ? 'p=' . $page : '';
|
$p = $page > 1 ? 'p=' . $page : '';
|
||||||
$curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON);
|
$curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON);
|
||||||
|
|
|
@ -3504,16 +3504,17 @@ class Contact
|
||||||
/**
|
/**
|
||||||
* Search contact table by nick or name
|
* Search contact table by nick or name
|
||||||
*
|
*
|
||||||
* @param string $search Name or nick
|
* @param string $search Name or nick
|
||||||
* @param string $mode Search mode (e.g. "community")
|
* @param string $mode Search mode (e.g. "community")
|
||||||
* @param int $uid User ID
|
* @param bool $show_blocked Show users from blocked servers. Default is false
|
||||||
* @param int $limit Maximum amount of returned values
|
* @param int $uid User ID
|
||||||
* @param int $offset Limit offset
|
* @param int $limit Maximum amount of returned values
|
||||||
|
* @param int $offset Limit offset
|
||||||
*
|
*
|
||||||
* @return array with search results
|
* @return array with search results
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @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)) {
|
if (empty($search)) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -3532,13 +3533,16 @@ class Contact
|
||||||
$condition = [
|
$condition = [
|
||||||
'network' => $networks,
|
'network' => $networks,
|
||||||
'server-failed' => false,
|
'server-failed' => false,
|
||||||
'server-blocked' => false,
|
|
||||||
'failed' => false,
|
'failed' => false,
|
||||||
'deleted' => false,
|
'deleted' => false,
|
||||||
'unsearchable' => false,
|
'unsearchable' => false,
|
||||||
'uid' => $uid
|
'uid' => $uid
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!$show_blocked) {
|
||||||
|
$condition['server-blocked'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($uid == 0) {
|
if ($uid == 0) {
|
||||||
$condition['blocked'] = false;
|
$condition['blocked'] = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Search extends BaseApi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($accounts)) {
|
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) {
|
foreach ($contacts as $contact) {
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ class Search extends BaseApi
|
||||||
}
|
}
|
||||||
|
|
||||||
$accounts = [];
|
$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);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue