fix: Improve URL / tag / mention extraction when composing #564
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previous code used custom regular expressions to extract URLs, hashtags, and mentions from text while the user was writing a post. These were inconsistent with the ones that Mastodon uses so the derived character count could be wrong.
As well as being visually incorrect this could prevent the user from posting a status that was within the length limit, or allow them to attempt to post a status that was over the length limit (which would then fail).
Fix this by dropping the homegrown regular expressions and using the same text parsing library that Mastodon users; twitter-text. This has been converted to Kotlin and the functionality related to Twitter specific features has been removed.
The hashtag handling has been adjusted, as Mastodon is more permissive about the positions where hashtags can appear than Twitter is, in particular, a hashtag does not need to be preceded with whitespace if the tag appears after some scripts, such as Hirigana.