Support legacy riot.im url.

This commit is contained in:
Onuray Sahin 2020-09-04 14:20:03 +03:00
parent a151f42495
commit f186a00515

View file

@ -30,7 +30,6 @@ import im.vector.app.features.login.LoginConfig
import im.vector.app.features.permalink.PermalinkHandler import im.vector.app.features.permalink.PermalinkHandler
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -61,26 +60,41 @@ class LinkHandlerActivity : VectorBaseActivity() {
} }
if (uri.path == PATH_CONFIG) { if (uri.path == PATH_CONFIG) {
handleConfigUrl(uri)
} else if (SUPPORTED_HOSTS.contains(uri.host)) {
handleSupportedHostUrl(uri)
}
}
private fun handleConfigUrl(uri: Uri) {
if (sessionHolder.hasActiveSession()) { if (sessionHolder.hasActiveSession()) {
displayAlreadyLoginPopup(uri) displayAlreadyLoginPopup(uri)
} else { } else {
// user is not yet logged in, this is the nominal case // user is not yet logged in, this is the nominal case
startLoginActivity(uri) startLoginActivity(uri)
} }
} else { }
private fun handleSupportedHostUrl(uri: Uri) {
if (!sessionHolder.hasActiveSession()) { if (!sessionHolder.hasActiveSession()) {
startLoginActivity(uri) startLoginActivity(uri)
finish() finish()
} else { } else {
convertUrlToPermalink(uri.toString())?.let { permalink -> convertUriToPermalink(uri)?.let { permalink ->
startPermalinkHandler(permalink) startPermalinkHandler(permalink)
} ?: run { } ?: run {
// Other link are not yet handled, but should not comes here (manifest configuration error?) // Host is correct but we do not recognize path
Timber.w("Unable to handle this uir: $uri") Timber.w("Unable to handle this uri: $uri")
finish() finish()
} }
} }
} }
private fun convertUriToPermalink(uri: Uri): String? {
val path = SUPPORTED_PATHS.find { it in uri.toString() } ?: return null
return uri
.toString()
.replace(uri.host + path, "$MATRIX_TO_HOST/#")
} }
private fun startPermalinkHandler(permalink: String) { private fun startPermalinkHandler(permalink: String) {
@ -96,20 +110,6 @@ class LinkHandlerActivity : VectorBaseActivity() {
.disposeOnDestroy() .disposeOnDestroy()
} }
/**
* Converts domain urls to matrix.to urls
* @param url full url like https://app.element.io/#/room/#dummy_room:matrix.org
* @return matrix.to url like https://matrix.to/#/#dummy_room:matrix.org
*/
private fun convertUrlToPermalink(url: String): String? {
return when {
url.startsWith(ROOM_BASE_URL) -> url.replace(ROOM_BASE_URL, PermalinkService.MATRIX_TO_URL_BASE)
url.startsWith(USER_BASE_URL) -> url.replace(USER_BASE_URL, PermalinkService.MATRIX_TO_URL_BASE)
url.startsWith(GROUP_BASE_URL) -> url.replace(GROUP_BASE_URL, PermalinkService.MATRIX_TO_URL_BASE)
else -> null
}
}
/** /**
* Start the login screen with identity server and home server pre-filled * Start the login screen with identity server and home server pre-filled
*/ */
@ -156,8 +156,9 @@ class LinkHandlerActivity : VectorBaseActivity() {
companion object { companion object {
private const val PATH_CONFIG = "/config/config" private const val PATH_CONFIG = "/config/config"
private const val ROOM_BASE_URL = "https://app.element.io/#/room/"
private const val USER_BASE_URL = "https://app.element.io/#/user/" private val SUPPORTED_HOSTS = arrayOf("app.element.io", "riot.im")
private const val GROUP_BASE_URL = "https://app.element.io/#/group/" private val SUPPORTED_PATHS = arrayOf("/#/room", "/#/user", "/#/group")
private const val MATRIX_TO_HOST = "matrix.to"
} }
} }