Skip to content

Commit

Permalink
Merge pull request #26391 from nextcloud/backport/26386/stable21
Browse files Browse the repository at this point in the history
[stable21] Also check the default phone region when the number has no country code
  • Loading branch information
MorrisJobke authored Apr 1, 2021
2 parents 737f755 + f38248d commit 052c9ab
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public function searchByPhoneNumbers(string $location, array $search): DataRespo
/** @var IUser $user */
$user = $this->userSession->getUser();
$knownTo = $user->getUID();
$defaultPhoneRegion = $this->config->getSystemValueString('default_phone_region');

$normalizedNumberToKey = [];
foreach ($search as $key => $phoneNumbers) {
Expand All @@ -245,6 +246,20 @@ public function searchByPhoneNumbers(string $location, array $search): DataRespo
}
} catch (NumberParseException $e) {
}

if ($defaultPhoneRegion !== '' && $defaultPhoneRegion !== $location && strpos($phone, '0') === 0) {
// If the number has a leading zero (no country code),
// we also check the default phone region of the instance,
// when it's different to the user's given region.
try {
$phoneNumber = $phoneUtil->parse($phone, $defaultPhoneRegion);
if ($phoneNumber instanceof PhoneNumber && $phoneUtil->isValidNumber($phoneNumber)) {
$normalizedNumber = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
$normalizedNumberToKey[$normalizedNumber] = (string) $key;
}
} catch (NumberParseException $e) {
}
}
}
}

Expand Down

0 comments on commit 052c9ab

Please sign in to comment.