From 51eb2cda95a7f7b37fd5bc390b4d9575a4113783 Mon Sep 17 00:00:00 2001
From: Benoit Marty <benoitm@matrix.org>
Date: Fri, 24 Apr 2020 15:22:09 +0200
Subject: [PATCH] Move some constants to the Matrix SDK

---
 .../matrix/android/api/auth/Constants.kt      | 29 +++++++++++++++++++
 .../riotx/features/login/LoginWebFragment.kt  |  6 ++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt

diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt
new file mode 100644
index 0000000000..27569bd90e
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt
@@ -0,0 +1,29 @@
+/*
+ * 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.auth
+
+/**
+ * Path to use when the client does not supported any or all login flows
+ * Ref: https://matrix.org/docs/spec/client_server/latest#login-fallback
+ * */
+const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/"
+
+/**
+ * Path to use when the client does not supported any or all registration flows
+ * Not documented
+ */
+const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/"
diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt
index 08d92760b2..84bac99e11 100644
--- a/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt
+++ b/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt
@@ -31,6 +31,8 @@ import android.webkit.WebView
 import android.webkit.WebViewClient
 import androidx.appcompat.app.AlertDialog
 import com.airbnb.mvrx.activityViewModel
+import im.vector.matrix.android.api.auth.LOGIN_FALLBACK_PATH
+import im.vector.matrix.android.api.auth.REGISTER_FALLBACK_PATH
 import im.vector.matrix.android.api.auth.data.Credentials
 import im.vector.matrix.android.internal.di.MoshiProvider
 import im.vector.riotx.R
@@ -123,14 +125,14 @@ class LoginWebFragment @Inject constructor(
         val url = buildString {
             append(state.homeServerUrl?.trim { it == '/' })
             if (state.signMode == SignMode.SignIn) {
-                append("/_matrix/static/client/login/")
+                append(LOGIN_FALLBACK_PATH)
                 state.deviceId?.takeIf { it.isNotBlank() }?.let {
                     // But https://github.com/matrix-org/synapse/issues/5755
                     append("?device_id=$it")
                 }
             } else {
                 // MODE_REGISTER
-                append("/_matrix/static/client/register/")
+                append(REGISTER_FALLBACK_PATH)
             }
         }