core, ios, android: rename BadgeStorePurchase to OpenStorePurchase, and drop a dead canBuy clause

This commit is contained in:
spaced4ndy
2026-10-01 13:57:12 +04:00
parent abf775020f
commit 94675cda8c
2 changed files with 6 additions and 8 deletions
@@ -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
}
@@ -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()
}