Fix review
This commit is contained in:
parent
e37fb313c0
commit
fa3abecf8f
@ -32,7 +32,11 @@ data class MatrixConfiguration(
|
||||
"https://scalar-staging.riot.im/scalar/api"
|
||||
),
|
||||
/**
|
||||
* Optional base url to create client permalinks instead of Matrix ones (matrix.to links).
|
||||
* Optional base url to create client permalinks (eg. https://www.example.com/#/) instead of Matrix ones (matrix.to links).
|
||||
* Do not forget to add the "#" which is required by the permalink parser.
|
||||
*
|
||||
* Note: this field is only used for permalinks creation, you will also have to edit the string-array `permalink_supported_hosts` in the config file
|
||||
* and add it to your manifest to handle these links in the application.
|
||||
*/
|
||||
val clientPermalinkBaseUrl: String? = null,
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ import android.net.Uri
|
||||
/**
|
||||
* Mapping of an input URI to a matrix.to compliant URI.
|
||||
*/
|
||||
object MatrixToMapper {
|
||||
object MatrixToConverter {
|
||||
|
||||
/**
|
||||
* Try to convert a URL from an element web instance or from a client permalink to a matrix.to url.
|
||||
@ -31,7 +31,7 @@ object MatrixToMapper {
|
||||
* - https://app.element.io/#/room/#element-android:matrix.org -> https://matrix.to/#/#element-android:matrix.org
|
||||
* - https://www.example.org/#/room/#element-android:matrix.org -> https://matrix.to/#/#element-android:matrix.org
|
||||
*/
|
||||
fun map(uri: Uri): Uri? {
|
||||
fun convert(uri: Uri): Uri? {
|
||||
val uriString = uri.toString()
|
||||
|
||||
return when {
|
@ -26,7 +26,7 @@ import java.net.URLDecoder
|
||||
* This class turns a uri to a [PermalinkData]
|
||||
* element-based domains (e.g. https://app.element.io/#/user/@chagai95:matrix.org) permalinks
|
||||
* or matrix.to permalinks (e.g. https://matrix.to/#/@chagai95:matrix.org)
|
||||
* or client permalinks (e.g. https://www.example.com/#/user/@chagai95:matrix.org)
|
||||
* or client permalinks (e.g. <clientPermalinkBaseUrl>user/@chagai95:matrix.org)
|
||||
*/
|
||||
object PermalinkParser {
|
||||
|
||||
@ -46,12 +46,12 @@ object PermalinkParser {
|
||||
// the client or element-based domain permalinks (e.g. https://app.element.io/#/user/@chagai95:matrix.org) don't have the
|
||||
// mxid in the first param (like matrix.to does - https://matrix.to/#/@chagai95:matrix.org) but rather in the second after /user/ so /user/mxid
|
||||
// so convert URI to matrix.to to simplify parsing process
|
||||
val matrixToUri = MatrixToMapper.map(uri) ?: return PermalinkData.FallbackLink(uri)
|
||||
val matrixToUri = MatrixToConverter.convert(uri) ?: return PermalinkData.FallbackLink(uri)
|
||||
|
||||
// We can't use uri.fragment as it is decoding to early and it will break the parsing
|
||||
// of parameters that represents url (like signurl)
|
||||
val fragment = matrixToUri.toString().substringAfter("#") // uri.fragment
|
||||
if (fragment.isNullOrEmpty()) {
|
||||
if (fragment.isEmpty()) {
|
||||
return PermalinkData.FallbackLink(uri)
|
||||
}
|
||||
val safeFragment = fragment.substringBefore('?')
|
||||
@ -122,12 +122,13 @@ object PermalinkParser {
|
||||
}
|
||||
}
|
||||
|
||||
private fun safeExtractParams(fragment: String) = fragment.substringAfter("?").split('&').mapNotNull {
|
||||
val splitNameValue = it.split("=")
|
||||
if (splitNameValue.size == 2) {
|
||||
Pair(splitNameValue[0], URLDecoder.decode(splitNameValue[1], "UTF-8"))
|
||||
} else null
|
||||
}
|
||||
private fun safeExtractParams(fragment: String) =
|
||||
fragment.substringAfter("?").split('&').mapNotNull {
|
||||
val splitNameValue = it.split("=")
|
||||
if (splitNameValue.size == 2) {
|
||||
Pair(splitNameValue[0], URLDecoder.decode(splitNameValue[1], "UTF-8"))
|
||||
} else null
|
||||
}
|
||||
|
||||
private fun String.getViaParameters(): List<String> {
|
||||
return UrlQuerySanitizer(this)
|
||||
@ -135,9 +136,7 @@ object PermalinkParser {
|
||||
.filter {
|
||||
it.mParameter == "via"
|
||||
}.map {
|
||||
it.mValue.let {
|
||||
URLDecoder.decode(it, "UTF-8")
|
||||
}
|
||||
URLDecoder.decode(it.mValue, "UTF-8")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.session.events.model.Event
|
||||
|
||||
/**
|
||||
* Useful methods to create permalink (like matrix.to links or client permalinks).
|
||||
* See [org.matrix.android.sdk.api.MatrixConfiguration.clientPermalinkBaseUrl] to setup a custom permalink base url.
|
||||
*/
|
||||
interface PermalinkService {
|
||||
|
||||
|
@ -105,8 +105,8 @@
|
||||
<activity android:name=".features.home.HomeActivity" />
|
||||
<activity
|
||||
android:name=".features.login.LoginActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:enabled="@bool/useLoginV1"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
||||
<intent-filter>
|
||||
@ -122,8 +122,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".features.login2.LoginActivity2"
|
||||
android:launchMode="singleTask"
|
||||
android:enabled="@bool/useLoginV2"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
||||
<intent-filter>
|
||||
@ -180,8 +180,11 @@
|
||||
<activity android:name=".features.createdirect.CreateDirectRoomActivity" />
|
||||
<activity android:name=".features.invite.InviteUsersToRoomActivity" />
|
||||
<activity android:name=".features.webview.VectorWebViewActivity" />
|
||||
|
||||
<!-- Activity to intercept links coming from a web instance -->
|
||||
<activity
|
||||
android:name=".features.link.LinkHandlerActivity"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
@ -198,8 +201,10 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Activity alias for matrix.to or element permalinks -->
|
||||
<activity-alias
|
||||
android:name=".features.permalink.PermalinkHandlerActivity"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:targetActivity=".features.link.LinkHandlerActivity">
|
||||
|
Loading…
x
Reference in New Issue
Block a user