feat: Support matrix: links (#4839)

This commit is contained in:
夜坂雅
2025-06-09 22:40:45 +08:00
committed by GitHub
parent 3b8a170621
commit 91b925c3ee
4 changed files with 31 additions and 4 deletions

View File

@@ -122,6 +122,17 @@
<data android:scheme="https" />
<data android:host="matrix.to" />
</intent-filter>
<!--
matrix: links
-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="matrix" />
</intent-filter>
<!--
links from matrix.to website
-->

View File

@@ -12,6 +12,7 @@ package io.element.android.libraries.matrix.api.permalink
* 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. <clientPermalinkBaseUrl>user/@chagai95:matrix.org)
* or matrix: permalinks (e.g. matrix:u/chagai95:matrix.org)
*/
interface PermalinkParser {
/**

View File

@@ -29,6 +29,7 @@ import javax.inject.Inject
* 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. <clientPermalinkBaseUrl>user/@chagai95:matrix.org)
* or matrix: permalinks (e.g. matrix:u/chagai95:matrix.org)
*/
@ContributesBinding(AppScope::class)
class DefaultPermalinkParser @Inject constructor(
@@ -40,10 +41,15 @@ class DefaultPermalinkParser @Inject constructor(
*/
override fun parse(uriString: String): PermalinkData {
val uri = uriString.toUri()
// 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 = matrixToConverter.convert(uri) ?: return PermalinkData.FallbackLink(uri)
val matrixToUri = if (uri.scheme == "matrix") {
// take matrix: URI as is to [parseMatrixEntityFrom]
uri
} else {
// 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
matrixToConverter.convert(uri) ?: return PermalinkData.FallbackLink(uri)
}
val result = runCatchingExceptions {
parseMatrixEntityFrom(matrixToUri.toString())

9
tools/adb/deeplink_matrix.sh Executable file
View File

@@ -0,0 +1,9 @@
#! /bin/bash
# Copyright 2025 New Vector Ltd.
#
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
# Please see LICENSE files in the repository root for full details.
adb shell am start -a android.intent.action.VIEW \
-d "matrix:r/element-android:matrix.org"