mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 13:21:50 +01:00
Optimizes caching for hidden chars on emoji
This commit is contained in:
parent
311964ce33
commit
de2b1a6c95
@ -41,6 +41,12 @@ object CachedRichTextParser {
|
||||
return result
|
||||
}
|
||||
|
||||
fun cachedText(
|
||||
content: String,
|
||||
tags: ImmutableListOfLists<String>,
|
||||
callbackUri: String? = null,
|
||||
): RichTextViewerState? = richTextCache[hashCodeCache(content, tags, callbackUri)]
|
||||
|
||||
fun parseText(
|
||||
content: String,
|
||||
tags: ImmutableListOfLists<String>,
|
||||
|
@ -530,20 +530,22 @@ fun DisplaySecretEmoji(
|
||||
) {
|
||||
if (canPreview && quotesLeft > 0) {
|
||||
var secretContent by remember {
|
||||
mutableStateOf<RichTextViewerState?>(null)
|
||||
mutableStateOf(CachedRichTextParser.cachedText(EmojiCoder.decode(segment.segmentText), state.tags))
|
||||
}
|
||||
|
||||
var showPopup by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
LaunchedEffect(segment) {
|
||||
launch(Dispatchers.Default) {
|
||||
secretContent =
|
||||
CachedRichTextParser.parseText(
|
||||
EmojiCoder.decode(segment.segmentText),
|
||||
state.tags,
|
||||
)
|
||||
if (secretContent == null) {
|
||||
LaunchedEffect(segment) {
|
||||
launch(Dispatchers.Default) {
|
||||
secretContent =
|
||||
CachedRichTextParser.parseText(
|
||||
EmojiCoder.decode(segment.segmentText),
|
||||
state.tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,6 @@ import androidx.compose.ui.window.Popup
|
||||
import androidx.compose.ui.window.PopupProperties
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.emojicoder.EmojiCoder
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextViewerState
|
||||
import com.vitorpamplona.amethyst.model.FeatureSetType
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.NoteState
|
||||
@ -251,21 +250,23 @@ fun DisplaySecretEmojiAsReaction(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
var secretContent by remember {
|
||||
mutableStateOf<RichTextViewerState?>(null)
|
||||
var secretContent by remember(reaction) {
|
||||
mutableStateOf(CachedRichTextParser.cachedText(EmojiCoder.decode(reaction), EmptyTagList))
|
||||
}
|
||||
|
||||
var showPopup by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
LaunchedEffect(reaction) {
|
||||
launch(Dispatchers.Default) {
|
||||
secretContent =
|
||||
CachedRichTextParser.parseText(
|
||||
EmojiCoder.decode(reaction),
|
||||
EmptyTagList,
|
||||
)
|
||||
if (secretContent == null) {
|
||||
LaunchedEffect(reaction) {
|
||||
launch(Dispatchers.Default) {
|
||||
secretContent =
|
||||
CachedRichTextParser.parseText(
|
||||
EmojiCoder.decode(reaction),
|
||||
EmptyTagList,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,6 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
@ -79,13 +78,10 @@ import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.emojicoder.EmojiCoder
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextViewerState
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||
import com.vitorpamplona.amethyst.service.CachedRichTextParser
|
||||
import com.vitorpamplona.amethyst.service.firstFullChar
|
||||
import com.vitorpamplona.amethyst.ui.components.AnimatedBorderTextCornerRadius
|
||||
import com.vitorpamplona.amethyst.ui.components.CoreSecretMessage
|
||||
import com.vitorpamplona.amethyst.ui.components.InLineIconRenderer
|
||||
import com.vitorpamplona.amethyst.ui.components.SetDialogToEdgeToEdge
|
||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
||||
@ -380,53 +376,6 @@ private fun RenderReactionOption(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DisplaySecretEmoji(
|
||||
text: String,
|
||||
state: RichTextViewerState,
|
||||
callbackUri: String?,
|
||||
canPreview: Boolean,
|
||||
quotesLeft: Int,
|
||||
backgroundColor: MutableState<Color>,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
if (canPreview && quotesLeft > 0) {
|
||||
var secretContent by remember {
|
||||
mutableStateOf<RichTextViewerState?>(null)
|
||||
}
|
||||
|
||||
var showPopup by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
LaunchedEffect(text) {
|
||||
launch(Dispatchers.Default) {
|
||||
secretContent =
|
||||
CachedRichTextParser.parseText(
|
||||
EmojiCoder.decode(text),
|
||||
state.tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val localSecretContent = secretContent
|
||||
|
||||
AnimatedBorderTextCornerRadius(
|
||||
text,
|
||||
Modifier.clickable {
|
||||
showPopup = !showPopup
|
||||
},
|
||||
)
|
||||
|
||||
if (localSecretContent != null && showPopup) {
|
||||
CoreSecretMessage(localSecretContent, callbackUri, quotesLeft, backgroundColor, accountViewModel, nav)
|
||||
}
|
||||
} else {
|
||||
Text(text)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmojiSelector(
|
||||
accountViewModel: AccountViewModel,
|
||||
|
Loading…
x
Reference in New Issue
Block a user