Closed sk22 closed 1 year ago
@Tak is the idea behind this function that the BottomSheetActivity
receives instructions to open a URL, and if the URL does not look like a Mastodon one (seems like it's doing some regex with what you'd see after api/v1
or api/v2
) it opens in browser but otherwise it does some other stuff?
If so, then how about we extract MastodonApi urls to their own const strings and then refer to those in the MastodonApi definition, and then you can do
//mastodonapi.kt
private const val FOLLOW_TAG_URL = "/......./{hash_id}"
mastodonApiUrlList = listOf(FOLLOW_TAG_URL, ...)
@POST(FOLLOW_TAG_URL)
suspend fun followTag(): Obs....
// looksLikeMastodonApi function
return mastodonApiUrlList
.map { it.replace(Regex("\\{(.+?)\\}"), "\\\\w+").toRegex() }
.any(uri.path::matches)
This will keep every {tagId}
in the Mastodon API URLs but will convert them into regex-appropriate word boundaries for the URL, and now there's no duplication of hard-coded URLs anywhere.
This will resolve the issue, probably make the function more complete.
Edit Probably need to append "$" to each URL in the list too for regex purposes, like
.map { "${it.replace(...)}$".toRegex() }
It's not about whether a url is a mastodon api point, but whether it's likely to be a fediverse object Tusky knows how to handle, or whether we should open it in the browser.
Oh OK so no reusing of URLs from the MastodonApi
then!
Hi! I'm using Tusky's
looksLikeMastodonUrl
helper function in Megalodon and I stumbled upon (an Akkoma user shared it) a URL that looks like this, which was not detected:https://example.social/users/[username]/statuses/[numeric_id]
Adding this RegEx seems to fix the issue:
"^/users/[^/]+/statuses/[a-zA-Z0-9]+$
"Tusky Version: https://github.com/tuskyapp/Tusky/blob/6aed1c6806f0b02114a8182538859756ca2ccbff/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt
Mastodon instance (if applicable): glitch-soc v4.0.2+cat+1.1.1
[x] I searched or browsed the repo’s other issues to ensure this is not a duplicate.