From 94675cda8c023ccf80c40db00f4bb74a5226efc5 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 1 Oct 2026 13:57:09 +0400 Subject: [PATCH] core, ios, android: rename BadgeStorePurchase to OpenStorePurchase, and drop a dead canBuy clause --- apps/ios/Shared/Views/Badges/BadgeStore.swift | 7 +++---- .../kotlin/chat/simplex/common/views/badges/BadgeStore.kt | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/ios/Shared/Views/Badges/BadgeStore.swift b/apps/ios/Shared/Views/Badges/BadgeStore.swift index 398cfb6594..ae48c9548f 100644 --- a/apps/ios/Shared/Views/Badges/BadgeStore.swift +++ b/apps/ios/Shared/Views/Badges/BadgeStore.swift @@ -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 = [] // 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 } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/badges/BadgeStore.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/badges/BadgeStore.kt index bd23034ca5..53b7fdb2bb 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/badges/BadgeStore.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/badges/BadgeStore.kt @@ -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>(emptyMap()) // core's open store purchases for the profile they were read for: core knows whose a purchase is - private val storePurchases = mutableStateOf>?>(null) + private val storePurchases = mutableStateOf>?>(null) // invoices whose purchase this session is still waiting on the store for private val buying = mutableStateOf>(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) { + fun setStorePurchases(rhId: Long?, userId: Long, purchases: List) { storePurchases.value = Triple(rhId, userId, purchases) } - private fun openStorePurchases(userId: Long?): List { + private fun openStorePurchases(userId: Long?): List { val (rhId, readFor, purchases) = storePurchases.value ?: return emptyList() return if (rhId == chatModel.remoteHostId() && readFor == userId) purchases else emptyList() }