Merge pull request #13115 from annando/search

Fix: Contacts can now be searched with a leading @ again.
This commit is contained in:
Hypolite Petovan 2023-05-17 13:35:51 -04:00 committed by GitHub
commit 454f177831
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 98 deletions

View file

@ -55,40 +55,42 @@ class Search
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function getContactsFromProbe(string $user): ResultList public static function getContactsFromProbe(string $user, $only_forum = false): ResultList
{ {
$emptyResultList = new ResultList(1, 0, 1); $emptyResultList = new ResultList();
if ((filter_var($user, FILTER_VALIDATE_EMAIL) && Network::isEmailDomainValid($user)) || if (empty(parse_url($user, PHP_URL_SCHEME)) && !(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;
}
$contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId());
$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'] ?? ''
);
return new ResultList(1, 1, 1, [$result]);
} else {
return $emptyResultList; return $emptyResultList;
} }
$user_data = Contact::getByURL($user);
if (empty($user_data)) {
return $emptyResultList;
}
if ($only_forum && ($user_data['contact-type'] != Contact::TYPE_COMMUNITY)) {
return $emptyResultList;
}
if (!Protocol::supportsProbe($user_data['network'])) {
return $emptyResultList;
}
$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]);
} }
/** /**
@ -129,7 +131,7 @@ class Search
$resultList = new ResultList( $resultList = new ResultList(
($results['page'] ?? 0) ?: 1, ($results['page'] ?? 0) ?: 1,
$results['count'] ?? 0, $results['count'] ?? 0,
($results['itemsperpage'] ?? 0) ?: 30 ($results['itemsperpage'] ?? 0) ?: 30
); );
@ -174,7 +176,7 @@ class Search
$contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : '', true); $contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : '', true);
$resultList = new ResultList($start, $itemPage, count($contacts)); $resultList = new ResultList($start, count($contacts), $itemPage);
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
$result = new ContactResult( $result = new ContactResult(
@ -284,4 +286,4 @@ class Search
return 'search?q=' . urlencode($search); return 'search?q=' . urlencode($search);
} }
} }
} }

View file

@ -23,6 +23,7 @@ namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Search; use Friendica\Core\Search;
use Friendica\DI; use Friendica\DI;
@ -62,18 +63,13 @@ class BaseSearch extends BaseModule
} }
$header = ''; $header = '';
$results = new ResultList();
if (strpos($search, '@') === 0) { if (strpos($search, '@') === 0) {
$search = trim(substr($search, 1)); $search = trim(substr($search, 1));
$type = Search::TYPE_PEOPLE; $type = Search::TYPE_PEOPLE;
$header = DI::l10n()->t('People Search - %s', $search); $header = DI::l10n()->t('People Search - %s', $search);
} elseif (strpos($search, '!') === 0) {
if (strrpos($search, '@') > 0) {
$results = Search::getContactsFromProbe(Network::convertToIdn($search));
}
}
if (strpos($search, '!') === 0) {
$search = trim(substr($search, 1)); $search = trim(substr($search, 1));
$type = Search::TYPE_FORUM; $type = Search::TYPE_FORUM;
$header = DI::l10n()->t('Forum Search - %s', $search); $header = DI::l10n()->t('Forum Search - %s', $search);
@ -91,14 +87,18 @@ class BaseSearch extends BaseModule
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
if ($localSearch && empty($results)) { if (!$results->getTotal() && !$localSearch && Search::getGlobalDirectory()) {
$pager->setItemsPerPage(80);
$results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
} elseif (Search::getGlobalDirectory() && empty($results)) {
$results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
$pager->setItemsPerPage($results->getItemsPage()); $pager->setItemsPerPage($results->getItemsPage());
} else { }
$results = new ResultList();
if (!$results->getTotal()) {
$pager->setItemsPerPage(80);
$results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
}
if (!$results->getTotal()) {
$results = Search::getContactsFromProbe(Network::convertToIdn($search), $type == Search::TYPE_FORUM);
} }
return self::printResult($results, $pager, $header); return self::printResult($results, $pager, $header);
@ -151,4 +151,4 @@ class BaseSearch extends BaseModule
'$paginate' => $pager->renderFull($results->getTotal()), '$paginate' => $pager->renderFull($results->getTotal()),
]); ]);
} }
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2023.06-dev\n" "Project-Id-Version: 2023.06-dev\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-09 06:34+0000\n" "POT-Creation-Date: 2023-05-12 07:57+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -44,7 +44,7 @@ msgstr ""
msgid "Item not found." msgid "Item not found."
msgstr "" msgstr ""
#: mod/item.php:435 mod/message.php:68 mod/message.php:114 mod/notes.php:45 #: mod/item.php:435 mod/message.php:67 mod/message.php:113 mod/notes.php:45
#: mod/photos.php:152 mod/photos.php:669 src/Model/Event.php:522 #: mod/photos.php:152 mod/photos.php:669 src/Model/Event.php:522
#: src/Module/Attach.php:55 src/Module/BaseApi.php:99 #: src/Module/Attach.php:55 src/Module/BaseApi.php:99
#: src/Module/BaseNotifications.php:98 src/Module/BaseSettings.php:52 #: src/Module/BaseNotifications.php:98 src/Module/BaseSettings.php:52
@ -219,86 +219,86 @@ msgstr ""
msgid "Your password has been changed at %s" msgid "Your password has been changed at %s"
msgstr "" msgstr ""
#: mod/message.php:46 mod/message.php:129 src/Content/Nav.php:319 #: mod/message.php:46 mod/message.php:128 src/Content/Nav.php:319
msgid "New Message" msgid "New Message"
msgstr "" msgstr ""
#: mod/message.php:83 src/Module/Profile/UnkMail.php:100 #: mod/message.php:82 src/Module/Profile/UnkMail.php:100
msgid "No recipient selected." msgid "No recipient selected."
msgstr "" msgstr ""
#: mod/message.php:88 #: mod/message.php:87
msgid "Unable to locate contact information." msgid "Unable to locate contact information."
msgstr "" msgstr ""
#: mod/message.php:92 src/Module/Profile/UnkMail.php:106 #: mod/message.php:91 src/Module/Profile/UnkMail.php:106
msgid "Message could not be sent." msgid "Message could not be sent."
msgstr "" msgstr ""
#: mod/message.php:96 src/Module/Profile/UnkMail.php:109 #: mod/message.php:95 src/Module/Profile/UnkMail.php:109
msgid "Message collection failure." msgid "Message collection failure."
msgstr "" msgstr ""
#: mod/message.php:123 src/Module/Notifications/Introductions.php:135 #: mod/message.php:122 src/Module/Notifications/Introductions.php:135
#: src/Module/Notifications/Introductions.php:170 #: src/Module/Notifications/Introductions.php:170
#: src/Module/Notifications/Notification.php:85 #: src/Module/Notifications/Notification.php:85
msgid "Discard" msgid "Discard"
msgstr "" msgstr ""
#: mod/message.php:136 src/Content/Nav.php:316 view/theme/frio/theme.php:241 #: mod/message.php:135 src/Content/Nav.php:316 view/theme/frio/theme.php:241
msgid "Messages" msgid "Messages"
msgstr "" msgstr ""
#: mod/message.php:149 #: mod/message.php:148
msgid "Conversation not found." msgid "Conversation not found."
msgstr "" msgstr ""
#: mod/message.php:154 #: mod/message.php:153
msgid "Message was not deleted." msgid "Message was not deleted."
msgstr "" msgstr ""
#: mod/message.php:169 #: mod/message.php:168
msgid "Conversation was not removed." msgid "Conversation was not removed."
msgstr "" msgstr ""
#: mod/message.php:182 mod/message.php:287 src/Module/Profile/UnkMail.php:145 #: mod/message.php:181 mod/message.php:286 src/Module/Profile/UnkMail.php:145
msgid "Please enter a link URL:" msgid "Please enter a link URL:"
msgstr "" msgstr ""
#: mod/message.php:191 src/Module/Profile/UnkMail.php:151 #: mod/message.php:190 src/Module/Profile/UnkMail.php:151
msgid "Send Private Message" msgid "Send Private Message"
msgstr "" msgstr ""
#: mod/message.php:192 mod/message.php:347 #: mod/message.php:191 mod/message.php:346
msgid "To:" msgid "To:"
msgstr "" msgstr ""
#: mod/message.php:193 mod/message.php:348 #: mod/message.php:192 mod/message.php:347
msgid "Subject:" msgid "Subject:"
msgstr "" msgstr ""
#: mod/message.php:197 mod/message.php:351 src/Module/Invite.php:171 #: mod/message.php:196 mod/message.php:350 src/Module/Invite.php:171
msgid "Your message:" msgid "Your message:"
msgstr "" msgstr ""
#: mod/message.php:200 mod/message.php:355 src/Content/Conversation.php:360 #: mod/message.php:199 mod/message.php:354 src/Content/Conversation.php:360
#: src/Module/Post/Edit.php:131 #: src/Module/Post/Edit.php:131
msgid "Upload photo" msgid "Upload photo"
msgstr "" msgstr ""
#: mod/message.php:201 mod/message.php:356 src/Module/Post/Edit.php:135 #: mod/message.php:200 mod/message.php:355 src/Module/Post/Edit.php:135
#: src/Module/Profile/UnkMail.php:153 #: src/Module/Profile/UnkMail.php:153
msgid "Insert web link" msgid "Insert web link"
msgstr "" msgstr ""
#: mod/message.php:202 mod/message.php:358 mod/photos.php:1291 #: mod/message.php:201 mod/message.php:357 mod/photos.php:1291
#: src/Content/Conversation.php:390 src/Content/Conversation.php:734 #: src/Content/Conversation.php:390 src/Content/Conversation.php:734
#: src/Module/Item/Compose.php:205 src/Module/Post/Edit.php:145 #: src/Module/Item/Compose.php:205 src/Module/Post/Edit.php:145
#: src/Module/Profile/UnkMail.php:154 src/Object/Post.php:550 #: src/Module/Profile/UnkMail.php:154 src/Object/Post.php:550
msgid "Please wait" msgid "Please wait"
msgstr "" msgstr ""
#: mod/message.php:203 mod/message.php:357 mod/photos.php:702 #: mod/message.php:202 mod/message.php:356 mod/photos.php:702
#: mod/photos.php:819 mod/photos.php:1097 mod/photos.php:1138 #: mod/photos.php:819 mod/photos.php:1097 mod/photos.php:1138
#: mod/photos.php:1194 mod/photos.php:1268 #: mod/photos.php:1194 mod/photos.php:1268
#: src/Module/Calendar/Event/Form.php:250 src/Module/Contact/Advanced.php:132 #: src/Module/Calendar/Event/Form.php:250 src/Module/Contact/Advanced.php:132
@ -317,52 +317,52 @@ msgstr ""
msgid "Submit" msgid "Submit"
msgstr "" msgstr ""
#: mod/message.php:224 #: mod/message.php:223
msgid "No messages." msgid "No messages."
msgstr "" msgstr ""
#: mod/message.php:280 #: mod/message.php:279
msgid "Message not available." msgid "Message not available."
msgstr "" msgstr ""
#: mod/message.php:324 #: mod/message.php:323
msgid "Delete message" msgid "Delete message"
msgstr "" msgstr ""
#: mod/message.php:326 mod/message.php:457 #: mod/message.php:325 mod/message.php:456
msgid "D, d M Y - g:i A" msgid "D, d M Y - g:i A"
msgstr "" msgstr ""
#: mod/message.php:341 mod/message.php:454 #: mod/message.php:340 mod/message.php:453
msgid "Delete conversation" msgid "Delete conversation"
msgstr "" msgstr ""
#: mod/message.php:343 #: mod/message.php:342
msgid "" msgid ""
"No secure communications available. You <strong>may</strong> be able to " "No secure communications available. You <strong>may</strong> be able to "
"respond from the sender's profile page." "respond from the sender's profile page."
msgstr "" msgstr ""
#: mod/message.php:346 #: mod/message.php:345
msgid "Send Reply" msgid "Send Reply"
msgstr "" msgstr ""
#: mod/message.php:428 #: mod/message.php:427
#, php-format #, php-format
msgid "Unknown sender - %s" msgid "Unknown sender - %s"
msgstr "" msgstr ""
#: mod/message.php:430 #: mod/message.php:429
#, php-format #, php-format
msgid "You and %s" msgid "You and %s"
msgstr "" msgstr ""
#: mod/message.php:432 #: mod/message.php:431
#, php-format #, php-format
msgid "%s and You" msgid "%s and You"
msgstr "" msgstr ""
#: mod/message.php:460 #: mod/message.php:459
#, php-format #, php-format
msgid "%d message" msgid "%d message"
msgid_plural "%d messages" msgid_plural "%d messages"
@ -1683,7 +1683,7 @@ msgstr ""
#: src/Content/Item.php:439 src/Content/Widget.php:80 #: src/Content/Item.php:439 src/Content/Widget.php:80
#: src/Model/Contact.php:1199 src/Model/Contact.php:1210 #: src/Model/Contact.php:1199 src/Model/Contact.php:1210
#: src/Module/Contact/Follow.php:167 view/theme/vier/theme.php:196 #: src/Module/Contact/Follow.php:167 view/theme/vier/theme.php:195
msgid "Connect/Follow" msgid "Connect/Follow"
msgstr "" msgstr ""
@ -1804,7 +1804,7 @@ msgstr ""
#: src/Module/Settings/TwoFactor/AppSpecific.php:129 #: src/Module/Settings/TwoFactor/AppSpecific.php:129
#: src/Module/Settings/TwoFactor/Index.php:118 #: src/Module/Settings/TwoFactor/Index.php:118
#: src/Module/Settings/TwoFactor/Recovery.php:107 #: src/Module/Settings/TwoFactor/Recovery.php:107
#: src/Module/Settings/TwoFactor/Verify.php:146 view/theme/vier/theme.php:241 #: src/Module/Settings/TwoFactor/Verify.php:146 view/theme/vier/theme.php:240
msgid "Help" msgid "Help"
msgstr "" msgstr ""
@ -2081,46 +2081,46 @@ msgid_plural "%d invitations available"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Content/Widget.php:78 view/theme/vier/theme.php:194 #: src/Content/Widget.php:78 view/theme/vier/theme.php:193
msgid "Find People" msgid "Find People"
msgstr "" msgstr ""
#: src/Content/Widget.php:79 view/theme/vier/theme.php:195 #: src/Content/Widget.php:79 view/theme/vier/theme.php:194
msgid "Enter name or interest" msgid "Enter name or interest"
msgstr "" msgstr ""
#: src/Content/Widget.php:81 view/theme/vier/theme.php:197 #: src/Content/Widget.php:81 view/theme/vier/theme.php:196
msgid "Examples: Robert Morgenstein, Fishing" msgid "Examples: Robert Morgenstein, Fishing"
msgstr "" msgstr ""
#: src/Content/Widget.php:82 src/Module/Contact.php:432 #: src/Content/Widget.php:82 src/Module/Contact.php:432
#: src/Module/Directory.php:96 view/theme/vier/theme.php:198 #: src/Module/Directory.php:96 view/theme/vier/theme.php:197
msgid "Find" msgid "Find"
msgstr "" msgstr ""
#: src/Content/Widget.php:83 src/Module/Contact/Suggestions.php:73 #: src/Content/Widget.php:83 src/Module/Contact/Suggestions.php:73
#: view/theme/vier/theme.php:199 #: view/theme/vier/theme.php:198
msgid "Friend Suggestions" msgid "Friend Suggestions"
msgstr "" msgstr ""
#: src/Content/Widget.php:84 view/theme/vier/theme.php:200 #: src/Content/Widget.php:84 view/theme/vier/theme.php:199
msgid "Similar Interests" msgid "Similar Interests"
msgstr "" msgstr ""
#: src/Content/Widget.php:85 view/theme/vier/theme.php:201 #: src/Content/Widget.php:85 view/theme/vier/theme.php:200
msgid "Random Profile" msgid "Random Profile"
msgstr "" msgstr ""
#: src/Content/Widget.php:86 view/theme/vier/theme.php:202 #: src/Content/Widget.php:86 view/theme/vier/theme.php:201
msgid "Invite Friends" msgid "Invite Friends"
msgstr "" msgstr ""
#: src/Content/Widget.php:87 src/Module/Directory.php:88 #: src/Content/Widget.php:87 src/Module/Directory.php:88
#: view/theme/vier/theme.php:203 #: view/theme/vier/theme.php:202
msgid "Global Directory" msgid "Global Directory"
msgstr "" msgstr ""
#: src/Content/Widget.php:89 view/theme/vier/theme.php:205 #: src/Content/Widget.php:89 view/theme/vier/theme.php:204
msgid "Local Directory" msgid "Local Directory"
msgstr "" msgstr ""
@ -3272,7 +3272,7 @@ msgstr ""
msgid "[no subject]" msgid "[no subject]"
msgstr "" msgstr ""
#: src/Model/Photo.php:1188 src/Module/Media/Photo/Upload.php:171 #: src/Model/Photo.php:1184 src/Module/Media/Photo/Upload.php:171
msgid "Wall Photos" msgid "Wall Photos"
msgstr "" msgstr ""
@ -5546,11 +5546,11 @@ msgstr ""
msgid "Forum Search - %s" msgid "Forum Search - %s"
msgstr "" msgstr ""
#: src/Module/BaseSearch.php:121 src/Module/Contact/MatchInterests.php:139 #: src/Module/BaseSearch.php:123 src/Module/Contact/MatchInterests.php:139
msgid "No matches" msgid "No matches"
msgstr "" msgstr ""
#: src/Module/BaseSearch.php:147 #: src/Module/BaseSearch.php:149
#, php-format #, php-format
msgid "" msgid ""
"%d result was filtered out because your node blocks the domain it is " "%d result was filtered out because your node blocks the domain it is "
@ -11876,7 +11876,7 @@ msgstr ""
msgid "Community Pages" msgid "Community Pages"
msgstr "" msgstr ""
#: view/theme/vier/config.php:139 view/theme/vier/theme.php:149 #: view/theme/vier/config.php:139 view/theme/vier/theme.php:148
msgid "Community Profiles" msgid "Community Profiles"
msgstr "" msgstr ""
@ -11884,7 +11884,7 @@ msgstr ""
msgid "Help or @NewHere ?" msgid "Help or @NewHere ?"
msgstr "" msgstr ""
#: view/theme/vier/config.php:141 view/theme/vier/theme.php:320 #: view/theme/vier/config.php:141 view/theme/vier/theme.php:319
msgid "Connect Services" msgid "Connect Services"
msgstr "" msgstr ""
@ -11892,10 +11892,10 @@ msgstr ""
msgid "Find Friends" msgid "Find Friends"
msgstr "" msgstr ""
#: view/theme/vier/config.php:143 view/theme/vier/theme.php:176 #: view/theme/vier/config.php:143 view/theme/vier/theme.php:175
msgid "Last users" msgid "Last users"
msgstr "" msgstr ""
#: view/theme/vier/theme.php:235 #: view/theme/vier/theme.php:234
msgid "Quick Start" msgid "Quick Start"
msgstr "" msgstr ""