Merge pull request #9994 from annando/issue-9986
Issue 9986: Improve contact search
This commit is contained in:
commit
57336f341d
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -171,45 +170,11 @@ class Search
|
|||
{
|
||||
Logger::info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]);
|
||||
|
||||
$config = DI::config();
|
||||
$contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : '');
|
||||
|
||||
$diaspora = $config->get('system', 'diaspora_enabled') ? Protocol::DIASPORA : Protocol::DFRN;
|
||||
$ostatus = !$config->get('system', 'ostatus_disabled') ? Protocol::OSTATUS : Protocol::DFRN;
|
||||
$resultList = new ResultList($start, $itemPage, count($contacts));
|
||||
|
||||
$wildcard = Strings::escapeHtml('%' . $search . '%');
|
||||
|
||||
$condition = [
|
||||
'NOT `unsearchable`
|
||||
AND `network` IN (?, ?, ?, ?)
|
||||
AND NOT `failed` AND `uid` = ?
|
||||
AND (`url` LIKE ? OR `name` LIKE ? OR `location` LIKE ?
|
||||
OR `addr` LIKE ? OR `about` LIKE ? OR `keywords` LIKE ?)
|
||||
AND `forum` = ?',
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $ostatus, $diaspora, 0,
|
||||
$wildcard, $wildcard, $wildcard,
|
||||
$wildcard, $wildcard, $wildcard,
|
||||
($type === self::TYPE_FORUM),
|
||||
];
|
||||
|
||||
$count = DBA::count('contact', $condition);
|
||||
|
||||
$resultList = new ResultList($start, $itemPage, $count);
|
||||
|
||||
if (empty($count)) {
|
||||
return $resultList;
|
||||
}
|
||||
|
||||
$data = DBA::select('contact', [], $condition, [
|
||||
'group_by' => ['nurl', 'updated'],
|
||||
'limit' => [$start, $itemPage],
|
||||
'order' => ['updated' => 'DESC']
|
||||
]);
|
||||
|
||||
if (!DBA::isResult($data)) {
|
||||
return $resultList;
|
||||
}
|
||||
|
||||
while ($contact = DBA::fetch($data)) {
|
||||
foreach ($contacts as $contact) {
|
||||
$result = new ContactResult(
|
||||
$contact["name"],
|
||||
$contact["addr"],
|
||||
|
@ -225,8 +190,6 @@ class Search
|
|||
$resultList->addResult($result);
|
||||
}
|
||||
|
||||
DBA::close($data);
|
||||
|
||||
// Add found profiles from the global directory to the local directory
|
||||
Worker::add(PRIORITY_LOW, 'SearchDirectory', $search);
|
||||
|
||||
|
|
|
@ -1477,17 +1477,22 @@ class Contact
|
|||
* @param string $field Fieldname of the photo in the contact array
|
||||
* @param string $size Size of the avatar picture
|
||||
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
private static function getAvatarPath(array $contact, string $field, string $size, string $avatar)
|
||||
private static function getAvatarPath(array $contact, string $field, string $size, string $avatar, $no_update = false)
|
||||
{
|
||||
if (!empty($contact)) {
|
||||
$contact = self::checkAvatarCacheByArray($contact);
|
||||
$contact = self::checkAvatarCacheByArray($contact, $no_update);
|
||||
if (!empty($contact[$field])) {
|
||||
$avatar = $contact[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if ($no_update && empty($avatar) && !empty($contact['avatar'])) {
|
||||
$avatar = $contact['avatar'];
|
||||
}
|
||||
|
||||
if (empty($avatar)) {
|
||||
$avatar = self::getDefaultAvatar([], $size);
|
||||
}
|
||||
|
@ -1504,11 +1509,12 @@ class Contact
|
|||
*
|
||||
* @param array $contact Contact array
|
||||
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getPhoto(array $contact, string $avatar = '')
|
||||
public static function getPhoto(array $contact, string $avatar = '', bool $no_update = false)
|
||||
{
|
||||
return self::getAvatarPath($contact, 'photo', Proxy::SIZE_SMALL, $avatar);
|
||||
return self::getAvatarPath($contact, 'photo', Proxy::SIZE_SMALL, $avatar, $no_update);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1516,11 +1522,12 @@ class Contact
|
|||
*
|
||||
* @param array $contact Contact array
|
||||
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getThumb(array $contact, string $avatar = '')
|
||||
public static function getThumb(array $contact, string $avatar = '', bool $no_update = false)
|
||||
{
|
||||
return self::getAvatarPath($contact, 'thumb', Proxy::SIZE_THUMB, $avatar);
|
||||
return self::getAvatarPath($contact, 'thumb', Proxy::SIZE_THUMB, $avatar, $no_update);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1528,20 +1535,22 @@ class Contact
|
|||
*
|
||||
* @param array $contact Contact array
|
||||
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getMicro(array $contact, string $avatar = '')
|
||||
public static function getMicro(array $contact, string $avatar = '', bool $no_update = false)
|
||||
{
|
||||
return self::getAvatarPath($contact, 'micro', Proxy::SIZE_MICRO, $avatar);
|
||||
return self::getAvatarPath($contact, 'micro', Proxy::SIZE_MICRO, $avatar, $no_update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the given contact array for avatar cache fields
|
||||
*
|
||||
* @param array $contact
|
||||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return array contact array with avatar cache fields
|
||||
*/
|
||||
private static function checkAvatarCacheByArray(array $contact)
|
||||
private static function checkAvatarCacheByArray(array $contact, bool $no_update = false)
|
||||
{
|
||||
$update = false;
|
||||
$contact_fields = [];
|
||||
|
@ -1555,7 +1564,7 @@ class Contact
|
|||
}
|
||||
}
|
||||
|
||||
if (!$update) {
|
||||
if (!$update || $no_update) {
|
||||
return $contact;
|
||||
}
|
||||
|
||||
|
|
|
@ -1103,7 +1103,7 @@ class Contact extends BaseModule
|
|||
'url' => $url,
|
||||
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
|
||||
'photo_menu' => Model\Contact::photoMenu($contact),
|
||||
'thumb' => Model\Contact::getThumb($contact),
|
||||
'thumb' => Model\Contact::getThumb($contact, '', true),
|
||||
'alt_text' => $alt_text,
|
||||
'name' => $contact['name'],
|
||||
'nick' => $contact['nick'],
|
||||
|
|
|
@ -30,7 +30,6 @@ use Friendica\Core\Search;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -79,7 +78,7 @@ class Acl extends BaseModule
|
|||
$contacts = [];
|
||||
foreach ($result as $contact) {
|
||||
$contacts[] = [
|
||||
'photo' => Contact::getMicro($contact),
|
||||
'photo' => Contact::getMicro($contact, '', true),
|
||||
'name' => htmlspecialchars($contact['name']),
|
||||
'nick' => $contact['addr'] ?: $contact['url'],
|
||||
'network' => $contact['network'],
|
||||
|
|
Loading…
Reference in a new issue