Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the base domain permalinks don't have the mxid in the first param but… #3735

Merged
merged 4 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3735.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ import android.net.UrlQuerySanitizer
import org.matrix.android.sdk.api.MatrixPatterns

/**
* This class turns an 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 or matrix.to permalinks (e.g. https://matrix.to/#/@chagai95:matrix.org)
*
*/
object PermalinkParser {

/**
* Turns an uri string to a [PermalinkData]
* Turns a uri string to a [PermalinkData]
*/
fun parse(uriString: String): PermalinkData {
val uri = Uri.parse(uriString)
return parse(uri)
}

/**
* Turns an uri to a [PermalinkData]
* Turns a uri to a [PermalinkData]
*/
fun parse(uri: Uri): PermalinkData {
if (!uri.toString().startsWith(PermalinkService.MATRIX_TO_URL_BASE)) {
Copy link
Member

@bmarty bmarty Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't get to your change, uri has to start by https://matrix.to/#/

Copy link
Contributor Author

@chagai95 chagai95 Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the MATRIX_TO_URL_BASE variable on my fork to be the element-based domain permalink, that's why for me it worked, I think this is easier to find this issue than to find a hard coded array, I could add this to a comment but it will of course be better to make a variable out of this, I don't think I can get to doing that easily but if anyone else wants to pick this PR and do it before I do, please do... I understand if you don't want to merge like this, I just wanted others to not spend a day looking for this issue 🙈 on our fork it's working now... @bmarty

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we build matrix.to links, so it's OK I think...

Copy link
Contributor Author

@chagai95 chagai95 Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For you it's fine but other forks use element-based domain permalinks 😬 @bmarty

Copy link
Member

@bmarty bmarty Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the explaination. We definitely need to improve this code, and add unit test.

Also I guess you will have the same problem for room or group URL, for instance:

https://develop.element.io/#/room/#element-android:matrix.org

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep thanks, we don't have room links but thx for the heads up 😉

Expand All @@ -53,7 +55,12 @@ object PermalinkParser {
.filter { it.isNotEmpty() }
.take(2)

val identifier = params.getOrNull(0)
// the 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
var identifier = params.getOrNull(0);
if (identifier.equals("user")) {
identifier = params.getOrNull(1)
}

val extraParameter = params.getOrNull(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a domain room url then it will have to become params.getOrNull(2)

return when {
identifier.isNullOrEmpty() -> PermalinkData.FallbackLink(uri)
Expand Down