Merge pull request #12956 from annando/server-blocked
Don't search for contacts on blocked or failed systems
This commit is contained in:
commit
bc7bf77096
10
database.sql
10
database.sql
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 2023.03-rc (Giant Rhubarb)
|
-- Friendica 2023.03-rc (Giant Rhubarb)
|
||||||
-- DB_UPDATE_VERSION 1517
|
-- DB_UPDATE_VERSION 1518
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -2849,7 +2849,9 @@ CREATE VIEW `account-view` AS SELECT
|
||||||
`apcontact`.`statuses_count` AS `ap-statuses_count`,
|
`apcontact`.`statuses_count` AS `ap-statuses_count`,
|
||||||
`gserver`.`site_name` AS `site_name`,
|
`gserver`.`site_name` AS `site_name`,
|
||||||
`gserver`.`platform` AS `platform`,
|
`gserver`.`platform` AS `platform`,
|
||||||
`gserver`.`version` AS `version`
|
`gserver`.`version` AS `version`,
|
||||||
|
`gserver`.`blocked` AS `server-blocked`,
|
||||||
|
`gserver`.`failed` AS `server-failed`
|
||||||
FROM `contact`
|
FROM `contact`
|
||||||
LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
|
LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
|
||||||
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
|
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
|
||||||
|
@ -2953,7 +2955,9 @@ CREATE VIEW `account-user-view` AS SELECT
|
||||||
`apcontact`.`statuses_count` AS `ap-statuses_count`,
|
`apcontact`.`statuses_count` AS `ap-statuses_count`,
|
||||||
`gserver`.`site_name` AS `site_name`,
|
`gserver`.`site_name` AS `site_name`,
|
||||||
`gserver`.`platform` AS `platform`,
|
`gserver`.`platform` AS `platform`,
|
||||||
`gserver`.`version` AS `version`
|
`gserver`.`version` AS `version`,
|
||||||
|
`gserver`.`blocked` AS `server-blocked`,
|
||||||
|
`gserver`.`failed` AS `server-failed`
|
||||||
FROM `contact` AS `ucontact`
|
FROM `contact` AS `ucontact`
|
||||||
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
|
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
|
||||||
LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
|
LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Search
|
||||||
$user_data['url'] ?? '',
|
$user_data['url'] ?? '',
|
||||||
$user_data['photo'] ?? '',
|
$user_data['photo'] ?? '',
|
||||||
$user_data['network'] ?? '',
|
$user_data['network'] ?? '',
|
||||||
$contactDetails['id'] ?? 0,
|
$contactDetails['cid'] ?? 0,
|
||||||
$user_data['id'] ?? 0,
|
$user_data['id'] ?? 0,
|
||||||
$user_data['tags'] ?? ''
|
$user_data['tags'] ?? ''
|
||||||
);
|
);
|
||||||
|
@ -146,7 +146,7 @@ class Search
|
||||||
$profile['photo'] ?? '',
|
$profile['photo'] ?? '',
|
||||||
Protocol::DFRN,
|
Protocol::DFRN,
|
||||||
$contactDetails['cid'] ?? 0,
|
$contactDetails['cid'] ?? 0,
|
||||||
0,
|
$contactDetails['zid'] ?? 0,
|
||||||
$profile['tags'] ?? ''
|
$profile['tags'] ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
@ -179,12 +179,12 @@ class Search
|
||||||
$result = new ContactResult(
|
$result = new ContactResult(
|
||||||
$contact['name'],
|
$contact['name'],
|
||||||
$contact['addr'],
|
$contact['addr'],
|
||||||
$contact['addr'],
|
$contact['addr'] ?: $contact['url'],
|
||||||
$contact['url'],
|
$contact['url'],
|
||||||
$contact['photo'],
|
$contact['photo'],
|
||||||
$contact['network'],
|
$contact['network'],
|
||||||
$contact['cid'] ?? 0,
|
0,
|
||||||
$contact['zid'] ?? 0,
|
$contact['pid'],
|
||||||
$contact['keywords']
|
$contact['keywords']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
|
@ -3506,6 +3506,7 @@ class Contact
|
||||||
*
|
*
|
||||||
* @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 bool $show_blocked Show users from blocked servers. Default is false
|
||||||
* @param int $uid User ID
|
* @param int $uid User ID
|
||||||
* @param int $limit Maximum amount of returned values
|
* @param int $limit Maximum amount of returned values
|
||||||
* @param int $offset Limit offset
|
* @param int $offset Limit offset
|
||||||
|
@ -3513,7 +3514,7 @@ class Contact
|
||||||
* @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 [];
|
||||||
|
@ -3529,7 +3530,18 @@ class Contact
|
||||||
$networks[] = Protocol::OSTATUS;
|
$networks[] = Protocol::OSTATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = ['network' => $networks, 'failed' => false, 'deleted' => false, 'uid' => $uid];
|
$condition = [
|
||||||
|
'network' => $networks,
|
||||||
|
'server-failed' => false,
|
||||||
|
'failed' => false,
|
||||||
|
'deleted' => false,
|
||||||
|
'unsearchable' => false,
|
||||||
|
'uid' => $uid
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$show_blocked) {
|
||||||
|
$condition['server-blocked'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($uid == 0) {
|
if ($uid == 0) {
|
||||||
$condition['blocked'] = false;
|
$condition['blocked'] = false;
|
||||||
|
@ -3553,10 +3565,9 @@ class Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = DBA::mergeConditions($condition,
|
$condition = DBA::mergeConditions($condition,
|
||||||
["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` WHERE `publish` OR `net-publish`))
|
["(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
|
||||||
AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
|
|
||||||
|
|
||||||
return self::selectToArray([], $condition, $params);
|
return DBA::selectToArray('account-user-view', [], $condition, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
|
||||||
if (!defined('DB_UPDATE_VERSION')) {
|
if (!defined('DB_UPDATE_VERSION')) {
|
||||||
define('DB_UPDATE_VERSION', 1517);
|
define('DB_UPDATE_VERSION', 1518);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -1009,6 +1009,8 @@
|
||||||
"site_name" => ["gserver", "site_name"],
|
"site_name" => ["gserver", "site_name"],
|
||||||
"platform" => ["gserver", "platform"],
|
"platform" => ["gserver", "platform"],
|
||||||
"version" => ["gserver", "version"],
|
"version" => ["gserver", "version"],
|
||||||
|
"server-blocked" => ["gserver", "blocked"],
|
||||||
|
"server-failed" => ["gserver", "failed"],
|
||||||
],
|
],
|
||||||
"query" => "FROM `contact`
|
"query" => "FROM `contact`
|
||||||
LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
|
LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
|
||||||
|
@ -1111,6 +1113,8 @@
|
||||||
"site_name" => ["gserver", "site_name"],
|
"site_name" => ["gserver", "site_name"],
|
||||||
"platform" => ["gserver", "platform"],
|
"platform" => ["gserver", "platform"],
|
||||||
"version" => ["gserver", "version"],
|
"version" => ["gserver", "version"],
|
||||||
|
"server-blocked" => ["gserver", "blocked"],
|
||||||
|
"server-failed" => ["gserver", "failed"],
|
||||||
],
|
],
|
||||||
"query" => "FROM `contact` AS `ucontact`
|
"query" => "FROM `contact` AS `ucontact`
|
||||||
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
|
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
|
||||||
|
|
11
update.php
11
update.php
|
@ -1315,3 +1315,14 @@ function update_1516()
|
||||||
|
|
||||||
return Update::SUCCESS;
|
return Update::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_1518()
|
||||||
|
{
|
||||||
|
$users = DBA::select('user', ['uid']);
|
||||||
|
while ($user = DBA::fetch($users)) {
|
||||||
|
Contact::updateSelfFromUserID($user['uid']);
|
||||||
|
}
|
||||||
|
DBA::close($users);
|
||||||
|
|
||||||
|
return Update::SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user