Merge pull request #26386 from nextcloud/bugfix/noid/also-check-default-phone-region-when-no-country-code

Also check the default phone region when the number has no country code
This commit is contained in:
Joas Schilling 2021-03-31 10:28:51 +02:00 committed by GitHub
commit 89cf1cb33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -234,6 +234,7 @@ class UsersController extends AUserData {
/** @var IUser $user */ /** @var IUser $user */
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
$knownTo = $user->getUID(); $knownTo = $user->getUID();
$defaultPhoneRegion = $this->config->getSystemValueString('default_phone_region');
$normalizedNumberToKey = []; $normalizedNumberToKey = [];
foreach ($search as $key => $phoneNumbers) { foreach ($search as $key => $phoneNumbers) {
@ -246,6 +247,20 @@ class UsersController extends AUserData {
} }
} catch (NumberParseException $e) { } 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) {
}
}
} }
} }