]> git.mxchange.org Git - friendica.git/commitdiff
Allow the search for contacts on blocked servers via web
authorMichael <heluecht@pirati.ca>
Wed, 29 Mar 2023 18:39:21 +0000 (18:39 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 29 Mar 2023 18:39:21 +0000 (18:39 +0000)
src/Core/Search.php
src/Model/Contact.php
src/Module/Api/Mastodon/Accounts/Search.php
src/Module/Api/Mastodon/Search.php

index b641f2897f14511fe6f965c920d6c2378203e8e9..7f05a3a947c05e7348feb734d8b30845c97b8360 100644 (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);
index d93c5f836706c0ef15aa5f3eccf1f65ca2e11b29..cf1b528da8e0084c5f68cb0c0c24d3952c76f570 100644 (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 {
index 5a03cba196a1c9a4c0e113369685d78ecf93745a..5276161640c823d5c5011cafa12258375a185ea8 100644 (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);
                        }
index 69e2627682773c040812da00b98360d12c3a1727..956e3d73b82a22562a2149cca1218c79689ed03f 100644 (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);
                }