Open rqu1 opened 6 years ago
Hi! Thanks for reporting!
I actually think Mastodon shortens urls too soon. You cant even see if a github link is an issue or a pull request. On the desktop its possible to preview the whole link by hovering, we don't have that on mobile, But yeah we should do something about really long urls, I think truncating them at 50-60 would be ok?
I had a look at the code in LinkHelper.kt
, and I think this should be fairly easy to implement. This is my first time looking at the code, but I think you would just need another function, called from setClickableText
that iterated over the URLSpans, and replaces the link text for long URLs with a shortened version.
I can have a go at implementing this, but I have a few questions:
Actually the HTML Mastodon sends us already has the urls shortened, but the HTML parser we use does not handle it correctly.
<p>Volkswagen: all brands have halted paid activities on Twitter <a href=\"http://reut.rs/3EY8h2n\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">http://</span><span class=\"\">reut.rs/3EY8h2n</span><span class=\"invisible\"></span></a></p>
Maybe hooking into the HTML (with a custom TagHandler
) is a better idea than implementing our own url shortening?
To answer the question: I like how Mastodon web shortens urls, but it might not be ideal for touchscreens (can't hover to preview), so yes long press to preview sounds like a good idea.
I did experiment with a TagHandler in parseAsMastodonHtml
however because HtmlCompat.fromHTML
treats a span as a supported tag, we can't modify it that way.
You mentioned above that Mastodon perhaps shortens paths too much - if the Tusky code does shortening itself, we have more control over that. I have some code and tests that are working for the shortening. When I get some time I'll have a go at the dialog.
I realised that by shortening links inside of setClickableText
, the overall status length changes compared to StatusViewData.content
. This causes the calculation for StatusViewData.isCollapsible
to be incorrect. As a result, the collapse button is sometimes shown when it shouldn't be, and in the wrong place.
My WIP code is in commit ac484f03 but I need to have a think about how to refactor things to handle this correctly.
https://mstdn.ca/@fishgolfski/109518030131969248 is a user request for this feature.
The web client visually truncates URLs to 30 characters, which makes scrolling past very long links not take forever. Proposed new behavior would be to copy the web clients behavior and truncate link text after a few characters instead of displaying the full URL.
Tusky Version: 1.8.0
Android Version: 8.0.0
Android Device: Samsung Galaxy s9
[x] I searched or browsed the repo’s other issues to ensure this is not a duplicate.