mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-09 19:22:39 +02:00
Migrates poll and invoice option availability to a mutable state
This commit is contained in:
@@ -270,13 +270,13 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
|
|||||||
postViewModel.upload(it, context)
|
postViewModel.upload(it, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postViewModel.canUsePoll()) {
|
if (postViewModel.canUsePoll) {
|
||||||
AddPollButton(postViewModel.wantsPoll) {
|
AddPollButton(postViewModel.wantsPoll) {
|
||||||
postViewModel.wantsPoll = !postViewModel.wantsPoll
|
postViewModel.wantsPoll = !postViewModel.wantsPoll
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postViewModel.canAddLnInvoice()) {
|
if (postViewModel.canAddInvoice) {
|
||||||
AddLnInvoiceButton(postViewModel.wantsInvoice) {
|
AddLnInvoiceButton(postViewModel.wantsInvoice) {
|
||||||
postViewModel.wantsInvoice = !postViewModel.wantsInvoice
|
postViewModel.wantsInvoice = !postViewModel.wantsInvoice
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
var userSuggestionAnchor: TextRange? = null
|
var userSuggestionAnchor: TextRange? = null
|
||||||
|
|
||||||
// Polls
|
// Polls
|
||||||
|
var canUsePoll by mutableStateOf(false)
|
||||||
var wantsPoll by mutableStateOf(false)
|
var wantsPoll by mutableStateOf(false)
|
||||||
var zapRecipients = mutableStateListOf<HexKey>()
|
var zapRecipients = mutableStateListOf<HexKey>()
|
||||||
var pollOptions = newStateMapPollOptions()
|
var pollOptions = newStateMapPollOptions()
|
||||||
@@ -53,6 +54,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
var isValidClosedAt = mutableStateOf(true)
|
var isValidClosedAt = mutableStateOf(true)
|
||||||
|
|
||||||
// Invoices
|
// Invoices
|
||||||
|
var canAddInvoice by mutableStateOf(false)
|
||||||
var wantsInvoice by mutableStateOf(false)
|
var wantsInvoice by mutableStateOf(false)
|
||||||
|
|
||||||
open fun load(account: Account, replyingTo: Note?, quote: Note?) {
|
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()}")
|
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
|
this.account = account
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,12 +195,4 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice &&
|
return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice &&
|
||||||
(!wantsPoll || pollOptions.values.all { it.isNotEmpty() })
|
(!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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user