Skip to content

Commit bc13c24

Browse files
authored
Merge pull request #3123 from element-hq/feature/fga/fix_timeline_text_item_not_refreshed
Timeline : fix text item not refreshed when content change
2 parents b46f47f + f15e9da commit bc13c24

File tree

1 file changed

+18
-19
lines changed
  • features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event

1 file changed

+18
-19
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,30 @@ fun TimelineItemTextView(
7474
internal fun getTextWithResolvedMentions(content: TimelineItemTextBasedContent): CharSequence {
7575
val userProfileCache = LocalRoomMemberProfilesCache.current
7676
val lastCacheUpdate by userProfileCache.lastCacheUpdate.collectAsState()
77-
val formattedBody = remember(content.htmlBody, lastCacheUpdate) {
78-
updateMentionSpans(content.formattedBody, userProfileCache)
79-
SpannableString(content.formattedBody ?: content.body)
77+
val formattedBody = remember(content.formattedBody, lastCacheUpdate) {
78+
content.formattedBody?.let { formattedBody ->
79+
updateMentionSpans(formattedBody, userProfileCache)
80+
formattedBody
81+
}
8082
}
81-
82-
return formattedBody
83+
return SpannableString(formattedBody ?: content.body)
8384
}
8485

85-
private fun updateMentionSpans(text: CharSequence?, cache: RoomMemberProfilesCache): Boolean {
86+
private fun updateMentionSpans(text: CharSequence, cache: RoomMemberProfilesCache): Boolean {
8687
var changedContents = false
87-
if (text != null) {
88-
for (mentionSpan in text.getMentionSpans()) {
89-
when (mentionSpan.type) {
90-
MentionSpan.Type.USER -> {
91-
val displayName = cache.getDisplayName(UserId(mentionSpan.rawValue)) ?: mentionSpan.rawValue
92-
if (mentionSpan.text != displayName) {
93-
changedContents = true
94-
mentionSpan.text = displayName
95-
}
88+
for (mentionSpan in text.getMentionSpans()) {
89+
when (mentionSpan.type) {
90+
MentionSpan.Type.USER -> {
91+
val displayName = cache.getDisplayName(UserId(mentionSpan.rawValue)) ?: mentionSpan.rawValue
92+
if (mentionSpan.text != displayName) {
93+
changedContents = true
94+
mentionSpan.text = displayName
9695
}
97-
// There's no need to do anything for `@room` pills
98-
MentionSpan.Type.EVERYONE -> Unit
99-
// Nothing yet for room mentions
100-
MentionSpan.Type.ROOM -> Unit
10196
}
97+
// There's no need to do anything for `@room` pills
98+
MentionSpan.Type.EVERYONE -> Unit
99+
// Nothing yet for room mentions
100+
MentionSpan.Type.ROOM -> Unit
102101
}
103102
}
104103
return changedContents

0 commit comments

Comments
 (0)