mirror of
https://github.com/confirmedcode/Lockdown-iOS.git
synced 2025-12-21 12:14:02 +01:00
46 lines
1.1 KiB
Swift
46 lines
1.1 KiB
Swift
//
|
|
// LockdownUser.swift
|
|
// Lockdown
|
|
//
|
|
// Created by Aliaksandr Dvoineu on 4.05.23.
|
|
// Copyright © 2023 Confirmed Inc. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
final class LockdownUser {
|
|
private(set) var currentSubscription: Subscription?
|
|
|
|
@CodableUserDefaults(key: "cahedUsedSubscription")
|
|
private var cachedUserSubscription: Subscription?
|
|
|
|
func updateSubscription(to newSubscription: Subscription?) {
|
|
currentSubscription = newSubscription
|
|
updateCachedSubscription(to: newSubscription)
|
|
}
|
|
|
|
private func updateCachedSubscription(to newSubscription: Subscription?) {
|
|
guard let newSubscription else {
|
|
return
|
|
}
|
|
|
|
cachedUserSubscription = newSubscription
|
|
}
|
|
|
|
func cachedSubscription() -> Subscription? {
|
|
guard let subscription = cachedUserSubscription else {
|
|
return nil
|
|
}
|
|
|
|
guard subscription.expirationDate > Date() else {
|
|
cachedUserSubscription = nil
|
|
return nil
|
|
}
|
|
return subscription
|
|
}
|
|
|
|
func resetCache() {
|
|
cachedUserSubscription = nil
|
|
}
|
|
}
|