Speeding up the boost method
This commit is contained in:
@@ -645,25 +645,8 @@ fun BoostReaction(
|
|||||||
IconButton(
|
IconButton(
|
||||||
modifier = iconButtonModifier,
|
modifier = iconButtonModifier,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (accountViewModel.isWriteable()) {
|
accountViewModel.tryBoost(baseNote) {
|
||||||
if (accountViewModel.hasBoosted(baseNote)) {
|
wantsToBoost = true
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@@ -697,7 +680,9 @@ fun BoostIcon(baseNote: Note, iconSize: Dp = Size20dp, grayTint: Color, accountV
|
|||||||
baseNote.live().boosts.map {
|
baseNote.live().boosts.map {
|
||||||
if (it.note.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint
|
if (it.note.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
}.observeAsState(grayTint)
|
}.observeAsState(
|
||||||
|
if (baseNote.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint
|
||||||
|
)
|
||||||
|
|
||||||
val iconModifier = remember {
|
val iconModifier = remember {
|
||||||
Modifier.size(iconSize)
|
Modifier.size(iconSize)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import androidx.lifecycle.map
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import coil.imageLoader
|
import coil.imageLoader
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.AccountState
|
import com.vitorpamplona.amethyst.model.AccountState
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
@@ -915,6 +916,29 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
onReady(newSortedMentions)
|
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) {
|
class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>, val account: Account) {
|
||||||
|
|||||||
Reference in New Issue
Block a user