Speeding up the boost method

This commit is contained in:
Vitor Pamplona 2023-10-28 16:38:12 -04:00
parent 712d498788
commit 2f2914077b
2 changed files with 29 additions and 20 deletions

View File

@ -645,25 +645,8 @@ fun BoostReaction(
IconButton(
modifier = iconButtonModifier,
onClick = {
if (accountViewModel.isWriteable()) {
if (accountViewModel.hasBoosted(baseNote)) {
accountViewModel.deleteBoostsTo(baseNote)
} else {
wantsToBoost = true
}
} else {
if (accountViewModel.loggedInWithExternalSigner()) {
if (accountViewModel.hasBoosted(baseNote)) {
accountViewModel.deleteBoostsTo(baseNote)
} else {
wantsToBoost = true
}
} else {
accountViewModel.toast(
R.string.read_only_user,
R.string.login_with_a_private_key_to_be_able_to_boost_posts
)
}
accountViewModel.tryBoost(baseNote) {
wantsToBoost = true
}
}
) {
@ -697,7 +680,9 @@ fun BoostIcon(baseNote: Note, iconSize: Dp = Size20dp, grayTint: Color, accountV
baseNote.live().boosts.map {
if (it.note.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint
}.distinctUntilChanged()
}.observeAsState(grayTint)
}.observeAsState(
if (baseNote.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint
)
val iconModifier = remember {
Modifier.size(iconSize)

View File

@ -14,6 +14,7 @@ import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import coil.imageLoader
import coil.request.ImageRequest
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.AccountState
import com.vitorpamplona.amethyst.model.AddressableNote
@ -915,6 +916,29 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
onReady(newSortedMentions)
}
}
fun tryBoost(baseNote: Note, onMore: () -> Unit) {
if (isWriteable()) {
if (hasBoosted(baseNote)) {
deleteBoostsTo(baseNote)
} else {
onMore()
}
} else {
if (loggedInWithExternalSigner()) {
if (hasBoosted(baseNote)) {
deleteBoostsTo(baseNote)
} else {
onMore()
}
} else {
toast(
R.string.read_only_user,
R.string.login_with_a_private_key_to_be_able_to_boost_posts
)
}
}
}
}
class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>, val account: Account) {