]> source.dussan.org Git - nextcloud-server.git/commitdiff
Also check the default phone region when the number has no country code 26391/head
authorJoas Schilling <coding@schilljs.com>
Wed, 31 Mar 2021 06:45:32 +0000 (08:45 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 31 Mar 2021 08:30:56 +0000 (08:30 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/provisioning_api/lib/Controller/UsersController.php

index f933cd4cd7f99f226cdc09bac3f19791b3f7456c..f65744d94309065868ad3725387020aa874f0281 100644 (file)
@@ -233,6 +233,7 @@ class UsersController extends AUserData {
                /** @var IUser $user */
                $user = $this->userSession->getUser();
                $knownTo = $user->getUID();
+               $defaultPhoneRegion = $this->config->getSystemValueString('default_phone_region');
 
                $normalizedNumberToKey = [];
                foreach ($search as $key => $phoneNumbers) {
@@ -245,6 +246,20 @@ class UsersController extends AUserData {
                                        }
                                } 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) {
+                                       }
+                               }
                        }
                }