Skip to content

Commit 20270cd

Browse files
authored
feat: Support matrix: links (#4839)
1 parent f15013e commit 20270cd

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@
122122
<data android:scheme="https" />
123123
<data android:host="matrix.to" />
124124
</intent-filter>
125+
<!--
126+
matrix: links
127+
-->
128+
<intent-filter>
129+
<action android:name="android.intent.action.VIEW" />
130+
131+
<category android:name="android.intent.category.DEFAULT" />
132+
<category android:name="android.intent.category.BROWSABLE" />
133+
134+
<data android:scheme="matrix" />
135+
</intent-filter>
125136
<!--
126137
links from matrix.to website
127138
-->

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/permalink/PermalinkParser.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package io.element.android.libraries.matrix.api.permalink
1212
* element-based domains (e.g. https://app.element.io/#/user/@chagai95:matrix.org) permalinks
1313
* or matrix.to permalinks (e.g. https://matrix.to/#/@chagai95:matrix.org)
1414
* or client permalinks (e.g. <clientPermalinkBaseUrl>user/@chagai95:matrix.org)
15+
* or matrix: permalinks (e.g. matrix:u/chagai95:matrix.org)
1516
*/
1617
interface PermalinkParser {
1718
/**

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/permalink/DefaultPermalinkParser.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import javax.inject.Inject
2929
* element-based domains (e.g. https://app.element.io/#/user/@chagai95:matrix.org) permalinks
3030
* or matrix.to permalinks (e.g. https://matrix.to/#/@chagai95:matrix.org)
3131
* or client permalinks (e.g. <clientPermalinkBaseUrl>user/@chagai95:matrix.org)
32+
* or matrix: permalinks (e.g. matrix:u/chagai95:matrix.org)
3233
*/
3334
@ContributesBinding(AppScope::class)
3435
class DefaultPermalinkParser @Inject constructor(
@@ -40,10 +41,15 @@ class DefaultPermalinkParser @Inject constructor(
4041
*/
4142
override fun parse(uriString: String): PermalinkData {
4243
val uri = uriString.toUri()
43-
// the client or element-based domain permalinks (e.g. https://app.element.io/#/user/@chagai95:matrix.org) don't have the
44-
// 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
45-
// so convert URI to matrix.to to simplify parsing process
46-
val matrixToUri = matrixToConverter.convert(uri) ?: return PermalinkData.FallbackLink(uri)
44+
val matrixToUri = if (uri.scheme == "matrix") {
45+
// take matrix: URI as is to [parseMatrixEntityFrom]
46+
uri
47+
} else {
48+
// the client or element-based domain permalinks (e.g. https://app.element.io/#/user/@chagai95:matrix.org) don't have the
49+
// 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
50+
// so convert URI to matrix.to to simplify parsing process
51+
matrixToConverter.convert(uri) ?: return PermalinkData.FallbackLink(uri)
52+
}
4753

4854
val result = runCatchingExceptions {
4955
parseMatrixEntityFrom(matrixToUri.toString())

tools/adb/deeplink_matrix.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /bin/bash
2+
3+
# Copyright 2025 New Vector Ltd.
4+
#
5+
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6+
# Please see LICENSE files in the repository root for full details.
7+
8+
adb shell am start -a android.intent.action.VIEW \
9+
-d "matrix:r/element-android:matrix.org"

0 commit comments

Comments
 (0)