From d39d1239f653cc78a1e61db2878703e35d3e9e6e Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 19 Jun 2024 12:36:09 -0400 Subject: [PATCH] Moves uncited hashtag parsing to a thread --- .../note/elements/DisplayUncitedHashtags.kt | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayUncitedHashtags.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayUncitedHashtags.kt index 97c48e96f..a65af1105 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayUncitedHashtags.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayUncitedHashtags.kt @@ -37,7 +37,7 @@ import com.vitorpamplona.amethyst.ui.theme.lessImportantLink import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.toImmutableListOfLists import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext +import kotlinx.coroutines.launch @Composable fun DisplayUncitedHashtags( @@ -56,35 +56,34 @@ fun DisplayUncitedHashtags( ) { val unusedHashtags by produceState(initialValue = emptyList()) { - withContext(Dispatchers.Default) { - val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists()) + val tagsInEvent = event.hashtags() + if (tagsInEvent.isNotEmpty()) { + launch(Dispatchers.Default) { + val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists()) - val tagsInEvent = event.hashtags() - - if (tagsInEvent.isEmpty()) return@withContext - - val tagsInContent = - state - .paragraphs - .map { - it.words.mapNotNull { - if (it is HashTagSegment) { - it.hashtag - } else { - null + val tagsInContent = + state + .paragraphs + .map { + it.words.mapNotNull { + if (it is HashTagSegment) { + it.hashtag + } else { + null + } } + }.flatten() + + val unusedHashtags = + tagsInEvent.filterNot { eventTag -> + tagsInContent.any { contentTag -> + eventTag.equals(contentTag, true) } - }.flatten() - - val unusedHashtags = - tagsInEvent.filterNot { eventTag -> - tagsInContent.any { contentTag -> - eventTag.equals(contentTag, true) } - } - if (unusedHashtags.isNotEmpty()) { - value = unusedHashtags + if (unusedHashtags.isNotEmpty()) { + value = unusedHashtags + } } } }