Moves reaction calls to the viewModelScope

This commit is contained in:
Vitor Pamplona
2023-09-20 18:12:41 -04:00
parent dc73843447
commit a706b71d7c
2 changed files with 17 additions and 21 deletions

View File

@@ -1366,18 +1366,14 @@ private fun ActionableReactionButton(
onChangeAmount: () -> Unit, onChangeAmount: () -> Unit,
toRemove: Set<String> toRemove: Set<String>
) { ) {
val scope = rememberCoroutineScope()
Button( Button(
modifier = Modifier.padding(horizontal = 3.dp), modifier = Modifier.padding(horizontal = 3.dp),
onClick = { onClick = {
scope.launch(Dispatchers.IO) {
accountViewModel.reactToOrDelete( accountViewModel.reactToOrDelete(
baseNote, baseNote,
reactionType reactionType
) )
onDismiss() onDismiss()
}
}, },
shape = ButtonBorder, shape = ButtonBorder,
colors = ButtonDefaults colors = ButtonDefaults
@@ -1388,13 +1384,11 @@ private fun ActionableReactionButton(
val thisModifier = remember(reactionType) { val thisModifier = remember(reactionType) {
Modifier.combinedClickable( Modifier.combinedClickable(
onClick = { onClick = {
scope.launch(Dispatchers.IO) {
accountViewModel.reactToOrDelete( accountViewModel.reactToOrDelete(
baseNote, baseNote,
reactionType reactionType
) )
onDismiss() onDismiss()
}
}, },
onLongClick = { onLongClick = {
onChangeAmount() onChangeAmount()

View File

@@ -117,6 +117,7 @@ class AccountViewModel(val account: Account) : ViewModel(), Dao {
} }
fun reactToOrDelete(note: Note, reaction: String) { fun reactToOrDelete(note: Note, reaction: String) {
viewModelScope.launch(Dispatchers.IO) {
val currentReactions = account.reactionTo(note, reaction) val currentReactions = account.reactionTo(note, reaction)
if (currentReactions.isNotEmpty()) { if (currentReactions.isNotEmpty()) {
account.delete(currentReactions) account.delete(currentReactions)
@@ -124,6 +125,7 @@ class AccountViewModel(val account: Account) : ViewModel(), Dao {
account.reactTo(note, reaction) account.reactTo(note, reaction)
} }
} }
}
fun isNoteHidden(note: Note): Boolean { fun isNoteHidden(note: Note): Boolean {
val isSensitive = note.event?.isSensitive() ?: false val isSensitive = note.event?.isSensitive() ?: false