/**
* @param string $search
- * @return bool (true if a exact match was found, false otherwise)
+ * @return array
*/
protected function getRemote($search) {
- $this->result['remotes'] = [];
+ $result = ['results' => [], 'exact' => []];
// Search in contacts
//@todo Pagination missing
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
- $foundRemoteById = false;
+ $result['exactIdMatch'] = false;
foreach ($addressBookContacts as $contact) {
if (isset($contact['isLocalSystemBook'])) {
continue;
list(, $serverUrl) = $this->splitUserRemote($cloudId);
if (strtolower($contact['FN']) === strtolower($search) || strtolower($cloudId) === strtolower($search)) {
if (strtolower($cloudId) === strtolower($search)) {
- $foundRemoteById = true;
+ $result['exactIdMatch'] = true;
}
- $this->result['exact']['remotes'][] = [
+ $result['exact'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
],
];
} else {
- $this->result['remotes'][] = [
+ $result['results'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
}
if (!$this->shareeEnumeration) {
- $this->result['remotes'] = [];
+ $result['results'] = [];
}
- if (!$foundRemoteById && substr_count($search, '@') >= 1 && $this->offset === 0) {
- $this->result['exact']['remotes'][] = [
+ if (!$result['exactIdMatch'] && substr_count($search, '@') >= 1 && $this->offset === 0) {
+ $result['exact'][] = [
'label' => $search,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
$this->reachedEndFor[] = 'remotes';
- return $foundRemoteById;
+ return $result;
}
/**
}
// Get remote
- $foundExactCloudID = false;
+ $remoteResults = ['results' => [], 'exact' => []];
if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) {
- $foundExactCloudID = $this->getRemote($search);
+ $remoteResults = $this->getRemote($search);
}
- // if we have a exact match for the cloud ID we don't show the email option,
- // it is extremely unlikely that a identical email address and cloud id exists
- if (!$foundExactCloudID && in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
- $this->getEmail($search);
+ $mailResults = ['results' => [], 'exact' => []];
+ if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
+ $mailResults = $this->getEmail($search);
+ }
+
+ // if we have a exact match, either for the federated cloud id or for the
+ // email address we only return the exact match. It is highly unlikely
+ // that the exact same email address and federated cloud id exists
+ if ($mailResults['exactIdMatch'] && !$remoteResults['exactIdMatch']) {
+ $this->result['emails'] = $mailResults['results'];
+ $this->result['exact']['emails'] = $mailResults['exact'];
+ } else if (!$mailResults['exactIdMatch'] && $remoteResults['exactIdMatch']) {
+ $this->result['remotes'] = $remoteResults['results'];
+ $this->result['exact']['remotes'] = $remoteResults['exact'];
+ } else {
+ $this->result['remotes'] = $remoteResults['results'];
+ $this->result['exact']['remotes'] = $remoteResults['exact'];
+ $this->result['emails'] = $mailResults['results'];
+ $this->result['exact']['emails'] = $mailResults['exact'];
}
$response = new Http\DataResponse($this->result);
/**
* @param string $search
- * @return bool (true if a exact match was found, false otherwise)
+ * @return array
*/
protected function getEmail($search) {
-
- $this->result['emails'] = [];
+ $result = ['results' => [], 'exact' => []];
// Search in contacts
//@todo Pagination missing
$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
- $foundEmailByAddress = false;
+ $result['exactIdMatch'] = false;
foreach ($addressBookContacts as $contact) {
if (isset($contact['isLocalSystemBook'])) {
continue;
foreach ($emailAddresses as $emailAddress) {
if (strtolower($contact['FN']) === strtolower($search) || strtolower($emailAddress) === strtolower($search)) {
if (strtolower($emailAddress) === strtolower($search)) {
+ $result['exactIdMatch'] = true;
$foundEmailByAddress = true;
}
- $this->result['exact']['emails'][] = [
+ $result['exact'][] = [
'label' => $contact['FN'] . " ($emailAddress)",
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
],
];
} else {
- $this->result['emails'][] = [
+ $result['results'][] = [
'label' => $contact['FN'] . " ($emailAddress)",
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
}
if (!$this->shareeEnumeration) {
- $this->result['emails'] = [];
+ $result['results'] = [];
}
- if (!$foundEmailByAddress && filter_var($search, FILTER_VALIDATE_EMAIL)) {
- $this->result['exact']['emails'][] = [
+ if (!$result['exactIdMatch'] && filter_var($search, FILTER_VALIDATE_EMAIL)) {
+ $result['exact'][] = [
'label' => $search,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
$this->reachedEndFor[] = 'emails';
- return $foundEmailByAddress;
+ return $result;
}
/**