mirror of
https://github.com/twofas/2fas-ios.git
synced 2024-11-22 02:10:19 +01:00
TF-1311 Local notification state handler connected
This commit is contained in:
parent
155ccf35ad
commit
f7e12b7eb0
@ -254,4 +254,20 @@ public final class InteractorFactory {
|
||||
cloudBackupStateInteractor: cloudBackupStateInteractor(listenerID: "MDMInteractor")
|
||||
)
|
||||
}
|
||||
|
||||
public func localNotificationStateInteractor() -> LocalNotificationStateInteracting {
|
||||
LocalNotificationStateInteractor(
|
||||
mainRepository: MainRepositoryImpl.shared,
|
||||
serviceListingInteractor: serviceListingInteractor(),
|
||||
cloudBackup: cloudBackupStateInteractor(listenerID: "localNotificationStateInteractor"),
|
||||
pairingDeviceInteractor: pairingWebExtensionInteractor(),
|
||||
mdmInteractor: mdmInteractor()
|
||||
)
|
||||
}
|
||||
|
||||
public func localNotificationFetchInteractor() -> LocalNotificationFetchInteracting {
|
||||
LocalNotificationFetchInteractor(
|
||||
mainRepository: MainRepositoryImpl.shared
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public struct LocalNotification: Hashable {
|
||||
public let wasRead: Bool
|
||||
}
|
||||
|
||||
protocol LocalNotificationFetchInteracting: AnyObject {
|
||||
public protocol LocalNotificationFetchInteracting: AnyObject {
|
||||
func getNotification(completion: @escaping (LocalNotification?) -> Void)
|
||||
func markNotificationAsRead()
|
||||
}
|
||||
@ -64,7 +64,7 @@ final class LocalNotificationFetchInteractor {
|
||||
}
|
||||
}
|
||||
|
||||
extension LocalNotificationFetchInteractor {
|
||||
extension LocalNotificationFetchInteractor: LocalNotificationFetchInteracting {
|
||||
func getNotification(completion: @escaping (LocalNotification?) -> Void) {
|
||||
if mainRepository.localNotificationsHandled {
|
||||
fetched = true
|
||||
@ -79,7 +79,7 @@ extension LocalNotificationFetchInteractor {
|
||||
}
|
||||
}
|
||||
|
||||
private extension LocalNotificationFetchInteractor {
|
||||
private extension LocalNotificationFetchInteractor {
|
||||
@objc
|
||||
private func notificationsHandled() {
|
||||
guard !fetched else { return }
|
||||
|
@ -33,8 +33,12 @@ final class LocalNotificationStateInteractor {
|
||||
|
||||
private let notificationCenter = NotificationCenter.default
|
||||
|
||||
private let cycleDays: Int = 30
|
||||
private let firstNotificationDays: Int = 2
|
||||
|
||||
private var backupStateKnown = false
|
||||
private var activateCalled = false
|
||||
|
||||
private var lastActivationDate: Date?
|
||||
|
||||
private var awaitsBackupStateChange: Callback?
|
||||
|
||||
@ -58,14 +62,14 @@ final class LocalNotificationStateInteractor {
|
||||
self?.awaitsBackupStateChange = nil
|
||||
}
|
||||
}
|
||||
|
||||
private let cycleDays: Int = 30
|
||||
private let firstNotificationDays: Int = 2
|
||||
|
||||
/// Call on appear
|
||||
}
|
||||
|
||||
extension LocalNotificationStateInteractor: LocalNotificationStateInteracting {
|
||||
func activate() {
|
||||
guard !activateCalled else { return }
|
||||
activateCalled = true
|
||||
if let lastActivationDate {
|
||||
guard lastActivationDate.days(from: .now) >= 1 else { return }
|
||||
}
|
||||
lastActivationDate = .now
|
||||
|
||||
if runCount == 0 { // First run
|
||||
saveCycle(-2)
|
||||
|
@ -64,6 +64,7 @@ final class MainModuleInteractor {
|
||||
private let rootInteractor: RootInteracting
|
||||
private let mdmInteractor: MDMInteracting
|
||||
private let protectionInteractor: ProtectionInteracting
|
||||
private let localNotificationStateInteractor: LocalNotificationStateInteracting
|
||||
|
||||
init(
|
||||
logUploadingInteractor: LogUploadingInteracting,
|
||||
@ -75,7 +76,8 @@ final class MainModuleInteractor {
|
||||
appInfoInteractor: AppInfoInteracting,
|
||||
rootInteractor: RootInteracting,
|
||||
mdmInteractor: MDMInteracting,
|
||||
protectionInteractor: ProtectionInteracting
|
||||
protectionInteractor: ProtectionInteracting,
|
||||
localNotificationStateInteractor: LocalNotificationStateInteracting
|
||||
) {
|
||||
self.logUploadingInteractor = logUploadingInteractor
|
||||
self.cloudBackupStateInteractor = cloudBackupStateInteractor
|
||||
@ -86,6 +88,7 @@ final class MainModuleInteractor {
|
||||
self.rootInteractor = rootInteractor
|
||||
self.mdmInteractor = mdmInteractor
|
||||
self.protectionInteractor = protectionInteractor
|
||||
self.localNotificationStateInteractor = localNotificationStateInteractor
|
||||
|
||||
cloudBackupStateInteractor.secretSyncError = { [weak self] in self?.secretSyncError?($0) }
|
||||
}
|
||||
@ -98,6 +101,10 @@ extension MainModuleInteractor: MainModuleInteracting {
|
||||
appInfoInteractor.markDateOfFirstRunIfNeeded()
|
||||
}
|
||||
|
||||
func refreshLocalNotifications() {
|
||||
localNotificationStateInteractor.activate()
|
||||
}
|
||||
|
||||
func checkForImport() -> URL? {
|
||||
fileInteractor.url
|
||||
}
|
||||
|
@ -37,12 +37,17 @@ final class MainPresenter {
|
||||
|
||||
func viewDidLoad() {
|
||||
interactor.initialize()
|
||||
interactor.refreshLocalNotifications()
|
||||
flowController.toSetupSplit()
|
||||
}
|
||||
|
||||
func viewWillAppear() {
|
||||
viewIsVisible()
|
||||
}
|
||||
|
||||
func handleAppDidBecomeActive() {
|
||||
interactor.refreshLocalNotifications()
|
||||
}
|
||||
|
||||
func handleSwitchToSetupPIN() {
|
||||
view?.navigateToViewPath(.settings(option: .security))
|
||||
|
@ -63,7 +63,7 @@ extension MainViewController {
|
||||
)
|
||||
notificationCenter.addObserver(
|
||||
self,
|
||||
selector: #selector(refreshAuthList),
|
||||
selector: #selector(appDidBecomeActive),
|
||||
name: UIApplication.didBecomeActiveNotification,
|
||||
object: nil
|
||||
)
|
||||
@ -128,6 +128,12 @@ extension MainViewController {
|
||||
presenter.handleClearAuthList()
|
||||
}
|
||||
|
||||
@objc
|
||||
private func appDidBecomeActive() {
|
||||
presenter.handleAppDidBecomeActive()
|
||||
presenter.handleRefreshAuthList()
|
||||
}
|
||||
|
||||
@objc
|
||||
private func refreshAuthList() {
|
||||
presenter.handleRefreshAuthList()
|
||||
|
Loading…
Reference in New Issue
Block a user