mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-06 05:37:47 +00:00
core, ios, android: rename BadgeStorePurchase to OpenStorePurchase, and drop a dead canBuy clause
This commit is contained in:
@@ -105,7 +105,7 @@ final class BadgeStore: ObservableObject {
|
||||
// one-time transactions the store holds unfinished: each is a payment taken and not yet credited
|
||||
@Published private var unfinished: [UInt64: BadgeStoreReceipt] = [:]
|
||||
// core's open store purchases for the profile they were read for: core knows whose a purchase is
|
||||
@Published private var storePurchases: (userId: Int64, purchases: [BadgeStorePurchase])? = nil
|
||||
@Published private var storePurchases: (userId: Int64, purchases: [OpenStorePurchase])? = nil
|
||||
// invoices whose purchase this session is still waiting on the store for
|
||||
@Published private var buying: Set<String> = []
|
||||
// kept for this run only: StoreKit lists no deferred purchase, and a declined one delivers nothing
|
||||
@@ -130,14 +130,13 @@ final class BadgeStore: ObservableObject {
|
||||
|
||||
func canBuy(_ userId: Int64?) -> Bool {
|
||||
reconciledOnce && buying.isEmpty && purchaseState(userId) == nil
|
||||
&& !openStorePurchases(userId).contains(where: { $0.transactionRef == nil })
|
||||
}
|
||||
|
||||
func setStorePurchases(_ userId: Int64, _ purchases: [BadgeStorePurchase]) {
|
||||
func setStorePurchases(_ userId: Int64, _ purchases: [OpenStorePurchase]) {
|
||||
storePurchases = (userId, purchases)
|
||||
}
|
||||
|
||||
private func openStorePurchases(_ userId: Int64?) -> [BadgeStorePurchase] {
|
||||
private func openStorePurchases(_ userId: Int64?) -> [OpenStorePurchase] {
|
||||
guard let storePurchases, storePurchases.userId == userId else { return [] }
|
||||
return storePurchases.purchases
|
||||
}
|
||||
|
||||
+3
-4
@@ -147,7 +147,7 @@ object BadgeStore {
|
||||
// one-time purchases the store holds unfinished: each is a payment taken and not yet credited
|
||||
private val unfinished = mutableStateOf<Map<String, BadgeStoreReceipt>>(emptyMap())
|
||||
// core's open store purchases for the profile they were read for: core knows whose a purchase is
|
||||
private val storePurchases = mutableStateOf<Triple<Long?, Long, List<BadgeStorePurchase>>?>(null)
|
||||
private val storePurchases = mutableStateOf<Triple<Long?, Long, List<OpenStorePurchase>>?>(null)
|
||||
// invoices whose purchase this session is still waiting on the store for
|
||||
private val buying = mutableStateOf<Set<String>>(emptySet())
|
||||
// by invoice id, so a pending purchase shows only under the profile whose record it names
|
||||
@@ -172,13 +172,12 @@ object BadgeStore {
|
||||
|
||||
fun canBuy(userId: Long?): Boolean =
|
||||
reconciledOnce.value && buying.value.isEmpty() && purchaseState(userId) == null
|
||||
&& openStorePurchases(userId).none { it.transactionRef == null }
|
||||
|
||||
fun setStorePurchases(rhId: Long?, userId: Long, purchases: List<BadgeStorePurchase>) {
|
||||
fun setStorePurchases(rhId: Long?, userId: Long, purchases: List<OpenStorePurchase>) {
|
||||
storePurchases.value = Triple(rhId, userId, purchases)
|
||||
}
|
||||
|
||||
private fun openStorePurchases(userId: Long?): List<BadgeStorePurchase> {
|
||||
private fun openStorePurchases(userId: Long?): List<OpenStorePurchase> {
|
||||
val (rhId, readFor, purchases) = storePurchases.value ?: return emptyList()
|
||||
return if (rhId == chatModel.remoteHostId() && readFor == userId) purchases else emptyList()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user