Migrates poll and invoice option availability to a mutable state

This commit is contained in:
Vitor Pamplona 2023-04-07 17:20:18 -04:00
parent 97490bb6ef
commit 03b76357ff
2 changed files with 7 additions and 10 deletions

View File

@ -270,13 +270,13 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
postViewModel.upload(it, context)
}
if (postViewModel.canUsePoll()) {
if (postViewModel.canUsePoll) {
AddPollButton(postViewModel.wantsPoll) {
postViewModel.wantsPoll = !postViewModel.wantsPoll
}
}
if (postViewModel.canAddLnInvoice()) {
if (postViewModel.canAddInvoice) {
AddLnInvoiceButton(postViewModel.wantsInvoice) {
postViewModel.wantsInvoice = !postViewModel.wantsInvoice
}

View File

@ -38,6 +38,7 @@ open class NewPostViewModel : ViewModel() {
var userSuggestionAnchor: TextRange? = null
// Polls
var canUsePoll by mutableStateOf(false)
var wantsPoll by mutableStateOf(false)
var zapRecipients = mutableStateListOf<HexKey>()
var pollOptions = newStateMapPollOptions()
@ -53,6 +54,7 @@ open class NewPostViewModel : ViewModel() {
var isValidClosedAt = mutableStateOf(true)
// Invoices
var canAddInvoice by mutableStateOf(false)
var wantsInvoice by mutableStateOf(false)
open fun load(account: Account, replyingTo: Note?, quote: Note?) {
@ -79,6 +81,9 @@ open class NewPostViewModel : ViewModel() {
message = TextFieldValue(message.text + "\n\n@${it.idNote()}")
}
canAddInvoice = account.userProfile().info?.lnAddress() != null
canUsePoll = originalNote?.event !is PrivateDmEvent && originalNote?.channel() == null
this.account = account
}
@ -190,12 +195,4 @@ open class NewPostViewModel : ViewModel() {
return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice &&
(!wantsPoll || pollOptions.values.all { it.isNotEmpty() })
}
fun canUsePoll(): Boolean {
return originalNote?.event !is PrivateDmEvent && originalNote?.channel() == null
}
fun canAddLnInvoice(): Boolean {
return account?.userProfile()?.info?.lnAddress() != null
}
}