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"
|
"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,
|
val clientPermalinkBaseUrl: String? = null,
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,7 @@ import android.net.Uri
|
||||||
/**
|
/**
|
||||||
* Mapping of an input URI to a matrix.to compliant 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.
|
* 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://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
|
* - 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()
|
val uriString = uri.toString()
|
||||||
|
|
||||||
return when {
|
return when {
|
|
@ -26,7 +26,7 @@ import java.net.URLDecoder
|
||||||
* This class turns a uri to a [PermalinkData]
|
* This class turns a uri to a [PermalinkData]
|
||||||
* element-based domains (e.g. https://app.element.io/#/user/@chagai95:matrix.org) permalinks
|
* 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 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 {
|
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
|
// 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
|
// 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
|
// 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
|
// 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)
|
// of parameters that represents url (like signurl)
|
||||||
val fragment = matrixToUri.toString().substringAfter("#") // uri.fragment
|
val fragment = matrixToUri.toString().substringAfter("#") // uri.fragment
|
||||||
if (fragment.isNullOrEmpty()) {
|
if (fragment.isEmpty()) {
|
||||||
return PermalinkData.FallbackLink(uri)
|
return PermalinkData.FallbackLink(uri)
|
||||||
}
|
}
|
||||||
val safeFragment = fragment.substringBefore('?')
|
val safeFragment = fragment.substringBefore('?')
|
||||||
|
@ -122,7 +122,8 @@ object PermalinkParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun safeExtractParams(fragment: String) = fragment.substringAfter("?").split('&').mapNotNull {
|
private fun safeExtractParams(fragment: String) =
|
||||||
|
fragment.substringAfter("?").split('&').mapNotNull {
|
||||||
val splitNameValue = it.split("=")
|
val splitNameValue = it.split("=")
|
||||||
if (splitNameValue.size == 2) {
|
if (splitNameValue.size == 2) {
|
||||||
Pair(splitNameValue[0], URLDecoder.decode(splitNameValue[1], "UTF-8"))
|
Pair(splitNameValue[0], URLDecoder.decode(splitNameValue[1], "UTF-8"))
|
||||||
|
@ -135,9 +136,7 @@ object PermalinkParser {
|
||||||
.filter {
|
.filter {
|
||||||
it.mParameter == "via"
|
it.mParameter == "via"
|
||||||
}.map {
|
}.map {
|
||||||
it.mValue.let {
|
URLDecoder.decode(it.mValue, "UTF-8")
|
||||||
URLDecoder.decode(it, "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).
|
* 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 {
|
interface PermalinkService {
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,8 @@
|
||||||
<activity android:name=".features.home.HomeActivity" />
|
<activity android:name=".features.home.HomeActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".features.login.LoginActivity"
|
android:name=".features.login.LoginActivity"
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:enabled="@bool/useLoginV1"
|
android:enabled="@bool/useLoginV1"
|
||||||
|
android:launchMode="singleTask"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -122,8 +122,8 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".features.login2.LoginActivity2"
|
android:name=".features.login2.LoginActivity2"
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:enabled="@bool/useLoginV2"
|
android:enabled="@bool/useLoginV2"
|
||||||
|
android:launchMode="singleTask"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -180,8 +180,11 @@
|
||||||
<activity android:name=".features.createdirect.CreateDirectRoomActivity" />
|
<activity android:name=".features.createdirect.CreateDirectRoomActivity" />
|
||||||
<activity android:name=".features.invite.InviteUsersToRoomActivity" />
|
<activity android:name=".features.invite.InviteUsersToRoomActivity" />
|
||||||
<activity android:name=".features.webview.VectorWebViewActivity" />
|
<activity android:name=".features.webview.VectorWebViewActivity" />
|
||||||
|
|
||||||
|
<!-- Activity to intercept links coming from a web instance -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".features.link.LinkHandlerActivity"
|
android:name=".features.link.LinkHandlerActivity"
|
||||||
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
@ -198,8 +201,10 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- Activity alias for matrix.to or element permalinks -->
|
||||||
<activity-alias
|
<activity-alias
|
||||||
android:name=".features.permalink.PermalinkHandlerActivity"
|
android:name=".features.permalink.PermalinkHandlerActivity"
|
||||||
|
android:enabled="true"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:targetActivity=".features.link.LinkHandlerActivity">
|
android:targetActivity=".features.link.LinkHandlerActivity">
|
||||||
|
|
Loading…
Reference in New Issue