Ignore "@instance..." part of username when computing status length (#3392)
* Move compose.* tests to own namespace
* Ignore "@instance..." part of username when computing status length
In a status with a mention ("@foo@example.org") only the "@foo" part should
be included in the calculated status length. It wasn't, so the app was
prevening people from posting statuses that should have been allowed.
Fix this.
- Lift the length calculation code in to a separate static function (easier
and faster to test)
- Add a `MentionSpan` type, to reuse existing code for detecting mentions
- Fix a bug in `FakeSpannable.getSpans()` (it was returning the outer type,
not the wrapped inner span)
- Add additional fast tests
The tests made sense under the `components.compose.ComposeActivity` package,
so I also created that and moved the existing ComposeActivity tests there.
Fixes https://github.com/tuskyapp/Tusky/issues/3339
* Static import assertEquals
This commit is contained in:
parent
f309c7750f
commit
6dfdaec425
8 changed files with 158 additions and 23 deletions
|
|
@ -156,7 +156,7 @@ private fun getCustomSpanForMention(mentions: List<Mention>, span: URLSpan, list
|
|||
}
|
||||
|
||||
private fun getCustomSpanForMentionUrl(url: String, mentionId: String, listener: LinkListener): ClickableSpan {
|
||||
return object : NoUnderlineURLSpan(url) {
|
||||
return object : MentionSpan(url) {
|
||||
override fun onClick(view: View) = listener.onViewAccount(mentionId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,14 @@ import android.text.TextPaint
|
|||
import android.text.style.URLSpan
|
||||
import android.view.View
|
||||
|
||||
open class NoUnderlineURLSpan(
|
||||
url: String
|
||||
) : URLSpan(url) {
|
||||
open class NoUnderlineURLSpan constructor(val url: String) : URLSpan(url) {
|
||||
|
||||
// This should not be necessary. But if you don't do this the [StatusLengthTest] tests
|
||||
// fail. Without this, accessing the `url` property, or calling `getUrl()` (which should
|
||||
// automatically call through to [UrlSpan.getURL]) returns null.
|
||||
override fun getURL(): String {
|
||||
return url
|
||||
}
|
||||
|
||||
override fun updateDrawState(ds: TextPaint) {
|
||||
super.updateDrawState(ds)
|
||||
|
|
@ -32,3 +37,8 @@ open class NoUnderlineURLSpan(
|
|||
view.context.openLink(url)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mentions of other users ("@user@example.org")
|
||||
*/
|
||||
open class MentionSpan(url: String) : NoUnderlineURLSpan(url)
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ private fun getSpan(matchType: FoundMatchType, string: String, colour: Int, star
|
|||
return when (matchType) {
|
||||
FoundMatchType.HTTP_URL -> NoUnderlineURLSpan(string.substring(start, end))
|
||||
FoundMatchType.HTTPS_URL -> NoUnderlineURLSpan(string.substring(start, end))
|
||||
FoundMatchType.MENTION -> MentionSpan(string.substring(start, end))
|
||||
else -> ForegroundColorSpan(colour)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue