mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-03 20:33:29 +02:00
Moves zaps from Compose scope to ViewModel Scope
This commit is contained in:
@@ -341,7 +341,6 @@ fun ZapVote(
|
||||
} else if (accountViewModel.account.zapAmountChoices.size == 1 &&
|
||||
pollViewModel.isValidInputVoteAmount(accountViewModel.account.zapAmountChoices.first())
|
||||
) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
||||
@@ -363,7 +362,6 @@ fun ZapVote(
|
||||
},
|
||||
zapType = accountViewModel.account.defaultZapType
|
||||
)
|
||||
}
|
||||
} else {
|
||||
wantsToZap = true
|
||||
}
|
||||
@@ -462,7 +460,6 @@ fun FilteredZapAmountChoicePopup(
|
||||
}
|
||||
|
||||
val zapMessage = ""
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
val sortedOptions = remember(accountState) {
|
||||
pollViewModel.createZapOptionsThatMatchThePollingParameters()
|
||||
@@ -482,7 +479,6 @@ fun FilteredZapAmountChoicePopup(
|
||||
Button(
|
||||
modifier = Modifier.padding(horizontal = 3.dp),
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amountInSats * 1000,
|
||||
@@ -494,7 +490,6 @@ fun FilteredZapAmountChoicePopup(
|
||||
defaultZapType
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
},
|
||||
shape = ButtonBorder,
|
||||
colors = ButtonDefaults
|
||||
@@ -508,7 +503,6 @@ fun FilteredZapAmountChoicePopup(
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.combinedClickable(
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amountInSats * 1000,
|
||||
@@ -520,7 +514,6 @@ fun FilteredZapAmountChoicePopup(
|
||||
defaultZapType
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
onChangeAmount()
|
||||
|
@@ -1088,7 +1088,6 @@ private fun zapClick(
|
||||
.show()
|
||||
}
|
||||
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
||||
@@ -1110,7 +1109,6 @@ private fun zapClick(
|
||||
},
|
||||
zapType = accountViewModel.account.defaultZapType
|
||||
)
|
||||
}
|
||||
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
||||
onMultipleChoices()
|
||||
}
|
||||
@@ -1422,7 +1420,6 @@ fun ZapAmountChoicePopup(
|
||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||
val account = accountState?.account ?: return
|
||||
val zapMessage = ""
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
Popup(
|
||||
alignment = Alignment.BottomCenter,
|
||||
@@ -1434,7 +1431,6 @@ fun ZapAmountChoicePopup(
|
||||
Button(
|
||||
modifier = Modifier.padding(horizontal = 3.dp),
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amountInSats * 1000,
|
||||
@@ -1446,7 +1442,6 @@ fun ZapAmountChoicePopup(
|
||||
account.defaultZapType
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
},
|
||||
shape = ButtonBorder,
|
||||
colors = ButtonDefaults
|
||||
@@ -1460,7 +1455,6 @@ fun ZapAmountChoicePopup(
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.combinedClickable(
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amountInSats * 1000,
|
||||
@@ -1472,7 +1466,6 @@ fun ZapAmountChoicePopup(
|
||||
account.defaultZapType
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
onChangeAmount()
|
||||
|
@@ -102,7 +102,6 @@ fun ZapCustomDialog(onClose: () -> Unit, accountViewModel: AccountViewModel, bas
|
||||
ZapButton(
|
||||
isActive = postViewModel.canSend()
|
||||
) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
postViewModel.value()!! * 1000L,
|
||||
@@ -123,7 +122,6 @@ fun ZapCustomDialog(onClose: () -> Unit, accountViewModel: AccountViewModel, bas
|
||||
},
|
||||
zapType = selectedZapType
|
||||
)
|
||||
}
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
@@ -130,6 +130,12 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
||||
}
|
||||
|
||||
fun zap(note: Note, amount: Long, pollOption: Int?, message: String, context: Context, onError: (String) -> Unit, onProgress: (percent: Float) -> Unit, zapType: LnZapEvent.ZapType) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
innerZap(note, amount, pollOption, message, context, onError, onProgress, zapType)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun innerZap(note: Note, amount: Long, pollOption: Int?, message: String, context: Context, onError: (String) -> Unit, onProgress: (percent: Float) -> Unit, zapType: LnZapEvent.ZapType) {
|
||||
val lud16 = note.event?.zapAddress() ?: note.author?.info?.lud16?.trim() ?: note.author?.info?.lud06?.trim()
|
||||
|
||||
if (lud16.isNullOrBlank()) {
|
||||
@@ -197,7 +203,10 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
||||
}
|
||||
|
||||
fun report(user: User, type: ReportEvent.ReportType) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
account.report(user, type)
|
||||
account.hideUser(user.pubkeyHex)
|
||||
}
|
||||
}
|
||||
|
||||
fun boost(note: Note) {
|
||||
|
Reference in New Issue
Block a user