From ec46ad3926c04dff84778c33dad655df77286d39 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 17 May 2017 14:56:41 +0800 Subject: [PATCH] fixed #839 --- .../extension/model/api/mastodon/StatusExtensions.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt index b41e0e6bd..93f2991b0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt @@ -105,7 +105,8 @@ fun Status.applyTo(accountKey: UserKey, result: ParcelableStatus) { result.is_possibly_sensitive = status.isSensitive result.mentions = status.mentions?.mapToArray { it.toParcelable(accountKey) } - extras.display_text_range = calculateDisplayTextRange(result.spans, result.media) + extras.display_text_range = calculateDisplayTextRange(result.text_unescaped, result.spans, + result.media) // Try to complete mastodon `in_reply_to` info val inReplyToMention = result.mentions?.firstOrNull { @@ -122,9 +123,10 @@ fun Status.applyTo(accountKey: UserKey, result: ParcelableStatus) { result.extras = extras } -private fun calculateDisplayTextRange(spans: Array?, media: Array?): IntArray? { +private fun calculateDisplayTextRange(text: String, spans: Array?, media: Array?): IntArray? { if (spans == null || media == null) return null val lastMatch = spans.lastOrNull { span -> media.any { span.link == it.page_url } } ?: return null + if (lastMatch.end < text.length) return null return intArrayOf(0, lastMatch.start) }