From 3842ec6bb09e32a9a882c2aaa59fa1d7b25166d5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 8 Jul 2020 09:54:57 +0200 Subject: [PATCH] Invite by msisdn. Error 500 from matrix.org though (#548) --- .../matrix/android/api/extensions/Strings.kt | 24 +++++++++++++++++++ .../riotx/core/extensions/BasicExtensions.kt | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/extensions/Strings.kt diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/extensions/Strings.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/extensions/Strings.kt new file mode 100644 index 0000000000..202c15b5b0 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/extensions/Strings.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.extensions + +fun CharSequence.ensurePrefix(prefix: CharSequence): CharSequence { + return when { + startsWith(prefix) -> this + else -> "$prefix$this" + } +} diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/BasicExtensions.kt b/vector/src/main/java/im/vector/riotx/core/extensions/BasicExtensions.kt index 6afd4fb279..99a5cb5a1a 100644 --- a/vector/src/main/java/im/vector/riotx/core/extensions/BasicExtensions.kt +++ b/vector/src/main/java/im/vector/riotx/core/extensions/BasicExtensions.kt @@ -21,6 +21,7 @@ import android.util.Patterns import androidx.fragment.app.Fragment import com.google.i18n.phonenumbers.NumberParseException import com.google.i18n.phonenumbers.PhoneNumberUtil +import im.vector.matrix.android.api.extensions.ensurePrefix fun Boolean.toOnOff() = if (this) "ON" else "OFF" @@ -38,11 +39,10 @@ fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches() /** * Check if a CharSequence is a phone number - * FIXME It does not work? */ fun CharSequence.isMsisdn(): Boolean { return try { - PhoneNumberUtil.getInstance().parse(this, null) + PhoneNumberUtil.getInstance().parse(ensurePrefix("+"), null) true } catch (e: NumberParseException) { false