]> git.mxchange.org Git - friendica.git/commitdiff
Convert Directory Search results into contact-looking records
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 1 Jan 2023 04:13:50 +0000 (23:13 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 1 Jan 2023 23:47:45 +0000 (18:47 -0500)
- Address https://github.com/friendica/friendica/issues/12488#issuecomment-1368216631

src/Core/Search.php

index d1892d726e3890d586bccaa2ad3637786df103ae..3c0ace3db5468d62486f7cfc2d1236a75b9b87c1 100644 (file)
@@ -233,7 +233,24 @@ class Search
                        if ($curlResult->isSuccess()) {
                                $searchResult = json_decode($curlResult->getBody(), true);
                                if (!empty($searchResult['profiles'])) {
-                                       $return = $searchResult['profiles'];
+                                       // Converting Directory Search results into contact-looking records
+                                       $return = array_map(function ($result) {
+                                               static $contactType = [
+                                                       'People'       => Contact::TYPE_PERSON,
+                                                       'Forum'        => Contact::TYPE_COMMUNITY,
+                                                       'Organization' => Contact::TYPE_ORGANISATION,
+                                                       'News'         => Contact::TYPE_NEWS,
+                                               ];
+
+                                               return [
+                                                       'name'         => $result['name'],
+                                                       'addr'         => $result['addr'],
+                                                       'url'          => $result['profile_url'],
+                                                       'network'      => Protocol::DFRN,
+                                                       'micro'        => $result['photo'],
+                                                       'contact-type' => $contactType[$result['account_type']],
+                                               ];
+                                       }, $searchResult['profiles']);
                                }
                        }
                }