Просмотр исходного кода

Stop restoring free AI uses when StoreKit transactions are deleted.

Purchase history and free-tier consumption are now one-way, so sandbox transaction resets no longer grant another 3 free uses.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 3 недель назад
Родитель
Сommit
614448c60c

+ 0 - 6
App AI for Reddit/Managers/AIFreeUsageManager.swift

@@ -32,12 +32,6 @@ final class AIFreeUsageManager {
         persistUsedCount()
     }
 
-    /// Restores the free AI quota for users who have never purchased premium (e.g. sandbox transaction reset).
-    func resetFreeUses() {
-        usedCount = 0
-        persistUsedCount()
-    }
-
     /// Permanently removes free AI access after a purchase or refund.
     func forfeitFreeUses() {
         usedCount = Self.maxFreeUses

+ 3 - 18
App AI for Reddit/Managers/SubscriptionManager.swift

@@ -499,37 +499,22 @@ final class SubscriptionManager: ObservableObject {
     }
 
     /// Aligns local purchase flags with StoreKit history.
-    /// - Purchases/refunds still on record → user has bought before; no free tier.
-    /// - No transactions at all (sandbox delete) → treat as a new user with 3 free uses.
+    /// Purchase history is sticky: once a user has bought, they keep that status even if
+    /// StoreKit history is cleared (e.g. sandbox transaction delete).
     private func syncPurchaseHistory() async {
-        var hasRecordedPurchase = false
-
         for await result in Transaction.all {
             guard case .verified(let transaction) = result else { continue }
             guard SubscriptionProductID.all.contains(transaction.productID) else { continue }
-            hasRecordedPurchase = true
-            break
-        }
 
-        if hasRecordedPurchase {
             if !hasEverPurchasedPremium {
                 hasEverPurchasedPremium = true
                 UserDefaults.standard.set(true, forKey: Self.cachedHasEverPurchasedKey)
                 AIFreeUsageManager.shared.forfeitFreeUses()
             }
-        } else if hasEverPurchasedPremium {
-            resetToNeverPurchasedState()
+            return
         }
     }
 
-    private func resetToNeverPurchasedState() {
-        hasEverPurchasedPremium = false
-        UserDefaults.standard.set(false, forKey: Self.cachedHasEverPurchasedKey)
-        UserDefaults.standard.removeObject(forKey: "SubscriptionManager.hadPremiumAccess")
-        AIFreeUsageManager.shared.resetFreeUses()
-        trialDisplayByPlan = [:]
-    }
-
     private func refreshTrialOffers() async {
         guard isEligibleForIntroTrial else {
             trialDisplayByPlan = [:]