diff --git a/godtools.xcodeproj/project.pbxproj b/godtools.xcodeproj/project.pbxproj index ff51a3841..fa03e4937 100644 --- a/godtools.xcodeproj/project.pbxproj +++ b/godtools.xcodeproj/project.pbxproj @@ -61,6 +61,9 @@ 45074B462D37FEC3004083F3 /* GetGlobalActivityEnabledUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45074B452D37FEC3004083F3 /* GetGlobalActivityEnabledUseCase.swift */; }; 45074B482D38017D004083F3 /* GetGlobalActivityIsEnabledInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45074B472D380147004083F3 /* GetGlobalActivityIsEnabledInterface.swift */; }; 45074B4A2D3801BE004083F3 /* GetGlobalActivityIsEnabled.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45074B492D3801BA004083F3 /* GetGlobalActivityIsEnabled.swift */; }; + 45074B502D380F81004083F3 /* FirebaseRemoteConfigSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 45074B4F2D380F81004083F3 /* FirebaseRemoteConfigSwift */; }; + 45074B572D384B7B004083F3 /* FirebaseRemoteConfigWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45074B532D384B7B004083F3 /* FirebaseRemoteConfigWrapper.swift */; }; + 45074B582D384B7B004083F3 /* RemoteConfigRemoteDatabaseInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45074B552D384B7B004083F3 /* RemoteConfigRemoteDatabaseInterface.swift */; }; 450A3A4B282D38C300FC2E14 /* TransparentModalCustomViewLayoutType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450A3A4A282D38C300FC2E14 /* TransparentModalCustomViewLayoutType.swift */; }; 450ADC452BECFE2F00988455 /* MockAppLanguagesRepositorySync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450ADC442BECFE2F00988455 /* MockAppLanguagesRepositorySync.swift */; }; 450B7FC22B2B53A2000B9035 /* ToolSettingsToolLanguagesListTypeDomainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450B7FC12B2B53A2000B9035 /* ToolSettingsToolLanguagesListTypeDomainModel.swift */; }; @@ -409,10 +412,6 @@ 4550BC722A33B2CD00256DEE /* UserIsAuthenticatedDomainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4550BC712A33B2CD00256DEE /* UserIsAuthenticatedDomainModel.swift */; }; 455258492D36F66E00FAC98D /* RemoteConfigRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455258472D36F66E00FAC98D /* RemoteConfigRepository.swift */; }; 4552584A2D36F66E00FAC98D /* RemoteConfigDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455258462D36F66E00FAC98D /* RemoteConfigDataModel.swift */; }; - 4552584E2D36F6D700FAC98D /* RemoteConfigCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4552584D2D36F6D200FAC98D /* RemoteConfigCache.swift */; }; - 455258512D36F72E00FAC98D /* RealmRemoteConfigObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455258502D36F71800FAC98D /* RealmRemoteConfigObject.swift */; }; - 455258542D36F82B00FAC98D /* RemoteConfigApiInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455258532D36F82600FAC98D /* RemoteConfigApiInterface.swift */; }; - 455258582D37007E00FAC98D /* FirebaseRemoteConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455258572D37007800FAC98D /* FirebaseRemoteConfig.swift */; }; 4552F54A2AD4745A0075415E /* TrackScreenViewAnalyticsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4552F5472AD474590075415E /* TrackScreenViewAnalyticsUseCase.swift */; }; 4552F54B2AD4745A0075415E /* TrackActionAnalyticsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4552F5482AD4745A0075415E /* TrackActionAnalyticsUseCase.swift */; }; 4552F54C2AD4745A0075415E /* TrackExitLinkAnalyticsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4552F5492AD4745A0075415E /* TrackExitLinkAnalyticsUseCase.swift */; }; @@ -1756,6 +1755,8 @@ 45074B452D37FEC3004083F3 /* GetGlobalActivityEnabledUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetGlobalActivityEnabledUseCase.swift; sourceTree = ""; }; 45074B472D380147004083F3 /* GetGlobalActivityIsEnabledInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetGlobalActivityIsEnabledInterface.swift; sourceTree = ""; }; 45074B492D3801BA004083F3 /* GetGlobalActivityIsEnabled.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetGlobalActivityIsEnabled.swift; sourceTree = ""; }; + 45074B532D384B7B004083F3 /* FirebaseRemoteConfigWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfigWrapper.swift; sourceTree = ""; }; + 45074B552D384B7B004083F3 /* RemoteConfigRemoteDatabaseInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfigRemoteDatabaseInterface.swift; sourceTree = ""; }; 450A3A4A282D38C300FC2E14 /* TransparentModalCustomViewLayoutType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransparentModalCustomViewLayoutType.swift; sourceTree = ""; }; 450ADC442BECFE2F00988455 /* MockAppLanguagesRepositorySync.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockAppLanguagesRepositorySync.swift; sourceTree = ""; }; 450B7FC12B2B53A2000B9035 /* ToolSettingsToolLanguagesListTypeDomainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolSettingsToolLanguagesListTypeDomainModel.swift; sourceTree = ""; }; @@ -2094,10 +2095,6 @@ 4550BC712A33B2CD00256DEE /* UserIsAuthenticatedDomainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserIsAuthenticatedDomainModel.swift; sourceTree = ""; }; 455258462D36F66E00FAC98D /* RemoteConfigDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfigDataModel.swift; sourceTree = ""; }; 455258472D36F66E00FAC98D /* RemoteConfigRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfigRepository.swift; sourceTree = ""; }; - 4552584D2D36F6D200FAC98D /* RemoteConfigCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfigCache.swift; sourceTree = ""; }; - 455258502D36F71800FAC98D /* RealmRemoteConfigObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealmRemoteConfigObject.swift; sourceTree = ""; }; - 455258532D36F82600FAC98D /* RemoteConfigApiInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfigApiInterface.swift; sourceTree = ""; }; - 455258572D37007800FAC98D /* FirebaseRemoteConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfig.swift; sourceTree = ""; }; 4552F5472AD474590075415E /* TrackScreenViewAnalyticsUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackScreenViewAnalyticsUseCase.swift; sourceTree = ""; }; 4552F5482AD4745A0075415E /* TrackActionAnalyticsUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackActionAnalyticsUseCase.swift; sourceTree = ""; }; 4552F5492AD4745A0075415E /* TrackExitLinkAnalyticsUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackExitLinkAnalyticsUseCase.swift; sourceTree = ""; }; @@ -3472,6 +3469,7 @@ 457771B629A00C5C00EA8115 /* FirebaseDynamicLinks in Frameworks */, 45E7D4C42977430A008C7503 /* ZipArchive in Frameworks */, D4997E0E28D4CED800205B4C /* YouTubeiOSPlayerHelper in Frameworks */, + 45074B502D380F81004083F3 /* FirebaseRemoteConfigSwift in Frameworks */, 457771B429A00C5C00EA8115 /* FirebaseCrashlytics in Frameworks */, 45E39EDC27457E0C006A59E4 /* Lottie in Frameworks */, 457771B829A00C5C00EA8115 /* FirebaseInAppMessaging-Beta in Frameworks */, @@ -3812,6 +3810,23 @@ path = ButtonsWithTitle; sourceTree = ""; }; + 45074B542D384B7B004083F3 /* Firebase */ = { + isa = PBXGroup; + children = ( + 45074B532D384B7B004083F3 /* FirebaseRemoteConfigWrapper.swift */, + ); + path = Firebase; + sourceTree = ""; + }; + 45074B562D384B7B004083F3 /* RemoteDatabase */ = { + isa = PBXGroup; + children = ( + 45074B542D384B7B004083F3 /* Firebase */, + 45074B552D384B7B004083F3 /* RemoteConfigRemoteDatabaseInterface.swift */, + ); + path = RemoteDatabase; + sourceTree = ""; + }; 450ADC412BECFE1F00988455 /* Data */ = { isa = PBXGroup; children = ( @@ -5523,48 +5538,13 @@ 455258482D36F66E00FAC98D /* RemoteConfigRepository */ = { isa = PBXGroup; children = ( - 455258522D36F82200FAC98D /* Api */, - 4552584B2D36F6CE00FAC98D /* Cache */, + 45074B562D384B7B004083F3 /* RemoteDatabase */, 455258472D36F66E00FAC98D /* RemoteConfigRepository.swift */, 455258462D36F66E00FAC98D /* RemoteConfigDataModel.swift */, ); path = RemoteConfigRepository; sourceTree = ""; }; - 4552584B2D36F6CE00FAC98D /* Cache */ = { - isa = PBXGroup; - children = ( - 4552584D2D36F6D200FAC98D /* RemoteConfigCache.swift */, - 4552584F2D36F6F400FAC98D /* Models */, - ); - path = Cache; - sourceTree = ""; - }; - 4552584F2D36F6F400FAC98D /* Models */ = { - isa = PBXGroup; - children = ( - 455258502D36F71800FAC98D /* RealmRemoteConfigObject.swift */, - ); - path = Models; - sourceTree = ""; - }; - 455258522D36F82200FAC98D /* Api */ = { - isa = PBXGroup; - children = ( - 455258562D37007400FAC98D /* Firebase */, - 455258532D36F82600FAC98D /* RemoteConfigApiInterface.swift */, - ); - path = Api; - sourceTree = ""; - }; - 455258562D37007400FAC98D /* Firebase */ = { - isa = PBXGroup; - children = ( - 455258572D37007800FAC98D /* FirebaseRemoteConfig.swift */, - ); - path = Firebase; - sourceTree = ""; - }; 455582D0269F2C1000C3FF14 /* Views */ = { isa = PBXGroup; children = ( @@ -12088,6 +12068,7 @@ 45D40C6A2A5315D500E8E4AE /* Fuzi */, 4581EAA22BFBE194008115FF /* RealmSwift */, 45F671902C3344010017C8C2 /* LocalizationServices */, + 45074B4F2D380F81004083F3 /* FirebaseRemoteConfigSwift */, ); productName = godtools; productReference = 4F5732891EA69CF00082035C /* godtools.app */; @@ -12851,7 +12832,6 @@ 45F7162C290A12D70019B715 /* ShareAStoryWithUsWebContent.swift in Sources */, D47DF0422B28F94A0079219B /* RealmDownloadedLanguage.swift in Sources */, 45AE975127C97A9500C2CB33 /* Image+MobileContentRenderableModel.swift in Sources */, - 4552584E2D36F6D700FAC98D /* RemoteConfigCache.swift in Sources */, 454B47D12AE01F9E00C7B5E7 /* GetOnboardingTutorialIsAvailableUseCase.swift in Sources */, D4B060072915647B005852D0 /* KeychainServiceResponse.swift in Sources */, 45A8352A2AD1AE12004F5593 /* ToolDetailsFeatureDataLayerDependencies.swift in Sources */, @@ -13045,7 +13025,6 @@ 457FEEFE2CBEA3C90092E84B /* LinkShareable.swift in Sources */, 454CA2042B7BD358009A3976 /* ViewAppLanguagesUseCase.swift in Sources */, 452D55372A33615900DE70BF /* MenuAccountSectionVisibility.swift in Sources */, - 455258582D37007E00FAC98D /* FirebaseRemoteConfig.swift in Sources */, 4598BD122BF7DF6800196463 /* AuthenticationProviderInterface.swift in Sources */, 45373D762BE110390058E990 /* LocalizableStringKeys.swift in Sources */, 453AC11428F4A10400291791 /* FollowUpsService.swift in Sources */, @@ -13116,7 +13095,6 @@ 45EA98F82AFD67CA00E7EA9A /* GetCreatingToolScreenShareSessionTimedOutInterfaceStringsRepositoryInterface.swift in Sources */, 45F3D39129A4FC9A00446F69 /* OnboardingTutorialReadyForEveryConversationView.swift in Sources */, 458CFEA229D4E15D007B423C /* MenuStringKeys.swift in Sources */, - 455258512D36F72E00FAC98D /* RealmRemoteConfigObject.swift in Sources */, 45C152342A43D1BD00F2A1E8 /* ToolSettingsOptionsView.swift in Sources */, 45369AD22AFA7FA500BD10F0 /* ToolScreenShareTutorialDomainModel.swift in Sources */, 45BDA64D2954FF08007E259B /* WebArchiveOperation.swift in Sources */, @@ -13308,7 +13286,6 @@ 457766F12AD71C070093B19A /* GetToolDetailsMediaRepository.swift in Sources */, 45F305832A9BAF4200BDFB93 /* SwiftUIPreviewDatabase.swift in Sources */, 450EE28829A6648900524F64 /* DashboardPathDeepLinkParser.swift in Sources */, - 455258542D36F82B00FAC98D /* RemoteConfigApiInterface.swift in Sources */, 45AC9DEE2B28A9CD00DEEBFE /* DownloadableLanguagesViewModel.swift in Sources */, 4585BF642AC391D200A6D720 /* SetAppLanguageUseCase.swift in Sources */, 457739E827A0955000999270 /* MobileContentViewWidth.swift in Sources */, @@ -13397,6 +13374,8 @@ 45060D1E2B38815600A2A44C /* ResourcesFilter.swift in Sources */, 455583EA269F2DA500C3FF14 /* MobileContentView.swift in Sources */, 45BB42A42CBEA1C300290F64 /* MobileContentRendererLanguages.swift in Sources */, + 45074B572D384B7B004083F3 /* FirebaseRemoteConfigWrapper.swift in Sources */, + 45074B582D384B7B004083F3 /* RemoteConfigRemoteDatabaseInterface.swift in Sources */, 45E8FAAB2883020A00D7D569 /* FileCacheLocation.swift in Sources */, 45EA5AB22B22482900D9E330 /* ToolSettingsDomainLayerDependencies.swift in Sources */, D1CE0959273EACCC00C8832C /* TutorialVideoAnalytics.swift in Sources */, @@ -15332,7 +15311,7 @@ repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git"; requirement = { kind = upToNextMinorVersion; - minimumVersion = 10.24.0; + minimumVersion = 11.7.0; }; }; 4581EAA12BFBE194008115FF /* XCRemoteSwiftPackageReference "realm-swift" */ = { @@ -15426,6 +15405,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 45074B4F2D380F81004083F3 /* FirebaseRemoteConfigSwift */ = { + isa = XCSwiftPackageProductDependency; + package = 457771B029A00C5C00EA8115 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseRemoteConfigSwift; + }; 452556432C383C3F00AA0046 /* RealmSwift */ = { isa = XCSwiftPackageProductDependency; package = 4581EAA12BFBE194008115FF /* XCRemoteSwiftPackageReference "realm-swift" */; diff --git a/godtools/App/DependencyContainer/AppDataLayerDependencies.swift b/godtools/App/DependencyContainer/AppDataLayerDependencies.swift index 404c9f63a..5182ffa42 100644 --- a/godtools/App/DependencyContainer/AppDataLayerDependencies.swift +++ b/godtools/App/DependencyContainer/AppDataLayerDependencies.swift @@ -230,8 +230,7 @@ class AppDataLayerDependencies { func getRemoteConfigRepository() -> RemoteConfigRepository { return RemoteConfigRepository( - api: FirebaseRemoteConfig(), - cache: RemoteConfigCache(realmDatabase: sharedRealmDatabase) + remoteDatabase: FirebaseRemoteConfigWrapper() ) } diff --git a/godtools/App/Features/GlobalActivity/Data-DomainInterface/GetGlobalActivityIsEnabled.swift b/godtools/App/Features/GlobalActivity/Data-DomainInterface/GetGlobalActivityIsEnabled.swift index 048183cdd..07f575c6e 100644 --- a/godtools/App/Features/GlobalActivity/Data-DomainInterface/GetGlobalActivityIsEnabled.swift +++ b/godtools/App/Features/GlobalActivity/Data-DomainInterface/GetGlobalActivityIsEnabled.swift @@ -21,7 +21,7 @@ class GetGlobalActivityIsEnabled: GetGlobalActivityIsEnabledInterface { func getIsEnabledPublisher() -> AnyPublisher { return remoteConfigRepository - .getRemoteConfigChangedPublisher() + .getRemoteConfigPublisher() .map { (dataModel: RemoteConfigDataModel?) in return dataModel?.globalActivityIsEnabled ?? false } diff --git a/godtools/App/Share/Data/RemoteConfigRepository/Api/Firebase/FirebaseRemoteConfig.swift b/godtools/App/Share/Data/RemoteConfigRepository/Api/Firebase/FirebaseRemoteConfig.swift deleted file mode 100644 index 76b8c07cd..000000000 --- a/godtools/App/Share/Data/RemoteConfigRepository/Api/Firebase/FirebaseRemoteConfig.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// FirebaseRemoteConfig.swift -// godtools -// -// Created by Levi Eggert on 1/14/25. -// Copyright © 2025 Cru. All rights reserved. -// - -import Foundation -import Combine - -class FirebaseRemoteConfig: RemoteConfigApiInterface { - - func getRemoteConfigPublisher() -> AnyPublisher { - - // TODO: Implement. ~Levi - - let dataModel = RemoteConfigDataModel(globalActivityIsEnabled: false, id: "1", updatedAt: Date()) - - return Just(dataModel) - .eraseToAnyPublisher() - } -} diff --git a/godtools/App/Share/Data/RemoteConfigRepository/Cache/Models/RealmRemoteConfigObject.swift b/godtools/App/Share/Data/RemoteConfigRepository/Cache/Models/RealmRemoteConfigObject.swift deleted file mode 100644 index 4a661def4..000000000 --- a/godtools/App/Share/Data/RemoteConfigRepository/Cache/Models/RealmRemoteConfigObject.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// RealmRemoteConfigObject.swift -// godtools -// -// Created by Levi Eggert on 1/14/25. -// Copyright © 2025 Cru. All rights reserved. -// - -import Foundation -import RealmSwift - -class RealmRemoteConfigObject: Object { - - @Persisted var globalActivityIsEnabled: Bool - @Persisted var id: String - @Persisted var updatedAt: Date - - override static func primaryKey() -> String? { - return "id" - } - - func mapFrom(dataModel: RemoteConfigDataModel) { - - id = dataModel.id - globalActivityIsEnabled = dataModel.globalActivityIsEnabled - updatedAt = dataModel.updatedAt - } -} diff --git a/godtools/App/Share/Data/RemoteConfigRepository/Cache/RemoteConfigCache.swift b/godtools/App/Share/Data/RemoteConfigRepository/Cache/RemoteConfigCache.swift deleted file mode 100644 index 3a3ff73bf..000000000 --- a/godtools/App/Share/Data/RemoteConfigRepository/Cache/RemoteConfigCache.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// RemoteConfigCache.swift -// godtools -// -// Created by Levi Eggert on 1/14/25. -// Copyright © 2025 Cru. All rights reserved. -// - -import Foundation -import Combine -import RealmSwift - -class RemoteConfigCache { - - private let realmDatabase: RealmDatabase - - init(realmDatabase: RealmDatabase) { - - self.realmDatabase = realmDatabase - } - - func getRemoteConfigChangedPublisher(id: String) -> AnyPublisher { - - return realmDatabase.openRealm() - .objects(RealmRemoteConfigObject.self) - .objectWillChange - .map { _ in - - return self.getRemoteConfig(id: id) - } - .eraseToAnyPublisher() - } - - private func getRemoteConfig(id: String) -> RemoteConfigDataModel? { - - let realmObject: RealmRemoteConfigObject? = realmDatabase.readObject(primaryKey: id) - - let dataModel: RemoteConfigDataModel? - - if let realmObject = realmObject { - - dataModel = RemoteConfigDataModel(realmObject: realmObject) - } - else { - - dataModel = nil - } - - return dataModel - } - - func storeRemoteConfigPublisher(remoteConfigDataModel: RemoteConfigDataModel) -> AnyPublisher { - - return realmDatabase.writeObjectsPublisher { (realm: Realm) in - - let realmRemoteConfigObject = RealmRemoteConfigObject() - - realmRemoteConfigObject.mapFrom(dataModel: remoteConfigDataModel) - - return [realmRemoteConfigObject] - - } mapInBackgroundClosure: { (objects: [RealmRemoteConfigObject]) in - - let dataModels: [RemoteConfigDataModel] = objects.map { - RemoteConfigDataModel(realmObject: $0) - } - - return dataModels - } - .map { (dataModels: [RemoteConfigDataModel]) in - - return remoteConfigDataModel - } - .eraseToAnyPublisher() - } -} diff --git a/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigDataModel.swift b/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigDataModel.swift index 08ee5f66f..f647aab7c 100644 --- a/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigDataModel.swift +++ b/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigDataModel.swift @@ -11,16 +11,4 @@ import Foundation struct RemoteConfigDataModel { let globalActivityIsEnabled: Bool - let id: String - let updatedAt: Date -} - -extension RemoteConfigDataModel { - - init(realmObject: RealmRemoteConfigObject) { - - globalActivityIsEnabled = realmObject.globalActivityIsEnabled - id = realmObject.id - updatedAt = realmObject.updatedAt - } } diff --git a/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigRepository.swift b/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigRepository.swift index 7ae08741c..10489504a 100644 --- a/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigRepository.swift +++ b/godtools/App/Share/Data/RemoteConfigRepository/RemoteConfigRepository.swift @@ -14,18 +14,22 @@ class RemoteConfigRepository { private static let sharedRemoteConfigId: String = "RemoteConfigRepository.shared.remoteConfig.id" - private let api: RemoteConfigApiInterface - private let cache: RemoteConfigCache + private let remoteDatabase: RemoteConfigRemoteDatabaseInterface - init(api: RemoteConfigApiInterface, cache: RemoteConfigCache) { + init(remoteDatabase: RemoteConfigRemoteDatabaseInterface) { - self.api = api - self.cache = cache + self.remoteDatabase = remoteDatabase } - func getRemoteConfigChangedPublisher(id: String = RemoteConfigRepository.sharedRemoteConfigId) -> AnyPublisher { + func syncDataPublisher() -> AnyPublisher { - return cache.getRemoteConfigChangedPublisher(id: id) + return remoteDatabase.syncFromRemoteDatabasePublisher() + .eraseToAnyPublisher() + } + + func getRemoteConfigPublisher(id: String = RemoteConfigRepository.sharedRemoteConfigId) -> AnyPublisher { + + return remoteDatabase.getRemoteConfigPublisher() .eraseToAnyPublisher() } } diff --git a/godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/Firebase/FirebaseRemoteConfigWrapper.swift b/godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/Firebase/FirebaseRemoteConfigWrapper.swift new file mode 100644 index 000000000..4c9aa39cc --- /dev/null +++ b/godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/Firebase/FirebaseRemoteConfigWrapper.swift @@ -0,0 +1,72 @@ +// +// FirebaseRemoteConfigWrapper.swift +// godtools +// +// Created by Levi Eggert on 1/14/25. +// Copyright © 2025 Cru. All rights reserved. +// + +import Foundation +import Combine +import FirebaseRemoteConfigInternal + +class FirebaseRemoteConfigWrapper: RemoteConfigRemoteDatabaseInterface { + + private let remoteConfig: RemoteConfig = RemoteConfig.remoteConfig() + + init() { + + } + + func syncFromRemoteDatabasePublisher() -> AnyPublisher { + + // NOTE: By default RemoteConfig fetches new data after 12 hours have elapsed. Can be configured in RemoteConfigSettings. ~Levi + + return fetchAndActivatePublisher() + .catch { _ in + return Just(RemoteConfigFetchAndActivateStatus.error) + .eraseToAnyPublisher() + } + .map { _ in + Void() + } + .eraseToAnyPublisher() + } + + func getRemoteConfigPublisher() -> AnyPublisher { + + return Just(getRemoteConfigDataModel()) + .eraseToAnyPublisher() + } + + private func getRemoteConfigDataModel() -> RemoteConfigDataModel? { + + let globalActivityIsEnabledValue: RemoteConfigValue? = remoteConfig.configValue(forKey: "ui_account_globalactivity_enabled") + + guard let globalActivityIsEnabled = globalActivityIsEnabledValue?.boolValue else { + return nil + } + + return RemoteConfigDataModel(globalActivityIsEnabled: globalActivityIsEnabled) + } +} + +extension FirebaseRemoteConfigWrapper { + + private func fetchAndActivatePublisher() -> AnyPublisher { + + return Future() { promise in + + self.remoteConfig.fetchAndActivate { (status: RemoteConfigFetchAndActivateStatus, error: Error?) in + + if let error = error { + promise(.failure(error)) + } + else { + promise(.success(status)) + } + } + } + .eraseToAnyPublisher() + } +} diff --git a/godtools/App/Share/Data/RemoteConfigRepository/Api/RemoteConfigApiInterface.swift b/godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/RemoteConfigRemoteDatabaseInterface.swift similarity index 53% rename from godtools/App/Share/Data/RemoteConfigRepository/Api/RemoteConfigApiInterface.swift rename to godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/RemoteConfigRemoteDatabaseInterface.swift index 5d988f3a1..d3c8f6546 100644 --- a/godtools/App/Share/Data/RemoteConfigRepository/Api/RemoteConfigApiInterface.swift +++ b/godtools/App/Share/Data/RemoteConfigRepository/RemoteDatabase/RemoteConfigRemoteDatabaseInterface.swift @@ -1,5 +1,5 @@ // -// RemoteConfigApiInterface.swift +// RemoteConfigRemoteDatabaseInterface.swift // godtools // // Created by Levi Eggert on 1/14/25. @@ -9,7 +9,8 @@ import Foundation import Combine -protocol RemoteConfigApiInterface { +protocol RemoteConfigRemoteDatabaseInterface { - func getRemoteConfigPublisher() -> AnyPublisher + func syncFromRemoteDatabasePublisher() -> AnyPublisher + func getRemoteConfigPublisher() -> AnyPublisher }