Support legacy riot.im url.

This commit is contained in:
Onuray Sahin 2020-09-04 14:20:03 +03:00
parent a151f42495
commit f186a00515
1 changed files with 35 additions and 34 deletions

View File

@ -30,7 +30,6 @@ import im.vector.app.features.login.LoginConfig
import im.vector.app.features.permalink.PermalinkHandler
import io.reactivex.android.schedulers.AndroidSchedulers
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -61,26 +60,41 @@ class LinkHandlerActivity : VectorBaseActivity() {
}
if (uri.path == PATH_CONFIG) {
handleConfigUrl(uri)
} else if (SUPPORTED_HOSTS.contains(uri.host)) {
handleSupportedHostUrl(uri)
}
}
private fun handleConfigUrl(uri: Uri) {
if (sessionHolder.hasActiveSession()) {
displayAlreadyLoginPopup(uri)
} else {
// user is not yet logged in, this is the nominal case
startLoginActivity(uri)
}
} else {
}
private fun handleSupportedHostUrl(uri: Uri) {
if (!sessionHolder.hasActiveSession()) {
startLoginActivity(uri)
finish()
} else {
convertUrlToPermalink(uri.toString())?.let { permalink ->
convertUriToPermalink(uri)?.let { permalink ->
startPermalinkHandler(permalink)
} ?: run {
// Other link are not yet handled, but should not comes here (manifest configuration error?)
Timber.w("Unable to handle this uir: $uri")
// Host is correct but we do not recognize path
Timber.w("Unable to handle this uri: $uri")
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) {
@ -96,20 +110,6 @@ class LinkHandlerActivity : VectorBaseActivity() {
.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
*/
@ -156,8 +156,9 @@ class LinkHandlerActivity : VectorBaseActivity() {
companion object {
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 const val GROUP_BASE_URL = "https://app.element.io/#/group/"
private val SUPPORTED_HOSTS = arrayOf("app.element.io", "riot.im")
private val SUPPORTED_PATHS = arrayOf("/#/room", "/#/user", "/#/group")
private const val MATRIX_TO_HOST = "matrix.to"
}
}