]> git.mxchange.org Git - friendica.git/commitdiff
Fix: Contacts can now be searched with a leading @ again.
authorMichael <heluecht@pirati.ca>
Fri, 12 May 2023 07:00:02 +0000 (07:00 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 12 May 2023 07:00:02 +0000 (07:00 +0000)
src/Core/Search.php
src/Module/BaseSearch.php

index 45b64eb5179b52a51d0fe20291b230eddfa390e6..605e3fa22918c4beafa37599397c9ae27e58d229 100644 (file)
@@ -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;
-                       }
+               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;
+               }
 
-                       $contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId());
+               if (!Protocol::supportsProbe($user_data['network'])) {
+                       return null;
+               }
 
-                       $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'] ?? ''
-                       );
+               $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]);
-               } else {
-                       return $emptyResultList;
-               }
+               return new ResultList(1, 1, 1, [$result]);
        }
 
        /**
index 675deb8fb26abf935d43f3d51ad4ce12277bab62..3593e8a632d15cdfd8eae3170f7797ef8c2ee620 100644 (file)
@@ -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);