Fix: Contacts can now be searched with a leading @ again.
This commit is contained in:
parent
725f99c813
commit
f45dbf8b01
2 changed files with 38 additions and 40 deletions
|
@ -55,40 +55,36 @@ class Search
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getContactsFromProbe(string $user): ResultList
|
||||
public static function getContactsFromProbe(string $user): ?ResultList
|
||||
{
|
||||
$emptyResultList = new ResultList(1, 0, 1);
|
||||
|
||||
if ((filter_var($user, FILTER_VALIDATE_EMAIL) && Network::isEmailDomainValid($user)) ||
|
||||
(substr(Strings::normaliseLink($user), 0, 7) == 'http://')) {
|
||||
|
||||
$user_data = Contact::getByURL($user);
|
||||
if (empty($user_data)) {
|
||||
return $emptyResultList;
|
||||
}
|
||||
|
||||
if (!in_array($user_data['network'], Protocol::FEDERATED)) {
|
||||
return $emptyResultList;
|
||||
}
|
||||
|
||||
$contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId());
|
||||
|
||||
$result = new ContactResult(
|
||||
$user_data['name'] ?? '',
|
||||
$user_data['addr'] ?? '',
|
||||
($contactDetails['addr'] ?? '') ?: ($user_data['url'] ?? ''),
|
||||
new Uri($user_data['url'] ?? ''),
|
||||
$user_data['photo'] ?? '',
|
||||
$user_data['network'] ?? '',
|
||||
$contactDetails['cid'] ?? 0,
|
||||
$user_data['id'] ?? 0,
|
||||
$user_data['tags'] ?? ''
|
||||
);
|
||||
|
||||
return new ResultList(1, 1, 1, [$result]);
|
||||
} else {
|
||||
return $emptyResultList;
|
||||
if (empty(parse_url($user, PHP_URL_SCHEME)) && !(filter_var($user, FILTER_VALIDATE_EMAIL) || Network::isEmailDomainValid($user))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user_data = Contact::getByURL($user);
|
||||
if (empty($user_data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Protocol::supportsProbe($user_data['network'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$contactDetails = Contact::getByURLForUser($user_data['url'], DI::userSession()->getLocalUserId());
|
||||
|
||||
$result = new ContactResult(
|
||||
$user_data['name'],
|
||||
$user_data['addr'],
|
||||
$user_data['addr'] ?: $user_data['url'],
|
||||
new Uri($user_data['url']),
|
||||
$user_data['photo'],
|
||||
$user_data['network'],
|
||||
$contactDetails['cid'] ?? 0,
|
||||
$user_data['id'],
|
||||
$user_data['tags']
|
||||
);
|
||||
|
||||
return new ResultList(1, 1, 1, [$result]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,14 +91,16 @@ class BaseSearch extends BaseModule
|
|||
|
||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
|
||||
|
||||
if ($localSearch && empty($results)) {
|
||||
$pager->setItemsPerPage(80);
|
||||
$results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
|
||||
} elseif (Search::getGlobalDirectory() && empty($results)) {
|
||||
$results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
|
||||
$pager->setItemsPerPage($results->getItemsPage());
|
||||
} else {
|
||||
$results = new ResultList();
|
||||
if (empty($results)) {
|
||||
if ($localSearch) {
|
||||
$pager->setItemsPerPage(80);
|
||||
$results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
|
||||
} elseif (Search::getGlobalDirectory()) {
|
||||
$results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
|
||||
$pager->setItemsPerPage($results->getItemsPage());
|
||||
} else {
|
||||
$results = new ResultList();
|
||||
}
|
||||
}
|
||||
|
||||
return self::printResult($results, $pager, $header);
|
||||
|
|
Loading…
Reference in a new issue