Skip to content

Commit

Permalink
Abstract layer for Push Notifications and Deep Linking (#263)
Browse files Browse the repository at this point in the history
* chore: added abstract layer for push notifications

* chore: abstract layer for deep linking

* chore: renamed some func

* chore: small refactor

* chore: added RawStringExtractable to configs

* chore: address review feedback

* chore: address review feedback
  • Loading branch information
rnr authored Feb 12, 2024
1 parent 9d214f1 commit 35e7cbe
Show file tree
Hide file tree
Showing 19 changed files with 571 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
07E0939F2B308D2800F1E4B2 /* Data_Certificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07E0939E2B308D2800F1E4B2 /* Data_Certificate.swift */; };
141F1D302B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 141F1D2F2B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift */; };
A53A32352B233DEC005FE38A /* ThemeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53A32342B233DEC005FE38A /* ThemeConfig.swift */; };
A595689B2B6173DF00ED4F90 /* BranchConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A595689A2B6173DF00ED4F90 /* BranchConfig.swift */; };
A5F4E7B52B61544A00ACD166 /* BrazeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */; };
BA30427F2B20B320009B64B7 /* SocialAuthError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA30427D2B20B299009B64B7 /* SocialAuthError.swift */; };
BA4AFB442B6A5AF100A21367 /* CheckBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */; };
BA4AFB422B5A7A0900A21367 /* VideoDownloadQualityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AFB412B5A7A0900A21367 /* VideoDownloadQualityView.swift */; };
Expand Down Expand Up @@ -300,6 +302,8 @@
60153262DBC2F9E660D7E11B /* Pods-App-Core.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.release.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.release.xcconfig"; sourceTree = "<group>"; };
9D5B06CAA99EA5CD49CBE2BB /* Pods-App-Core.debugdev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugdev.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugdev.xcconfig"; sourceTree = "<group>"; };
A53A32342B233DEC005FE38A /* ThemeConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeConfig.swift; sourceTree = "<group>"; };
A595689A2B6173DF00ED4F90 /* BranchConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BranchConfig.swift; sourceTree = "<group>"; };
A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrazeConfig.swift; sourceTree = "<group>"; };
BA30427D2B20B299009B64B7 /* SocialAuthError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocialAuthError.swift; sourceTree = "<group>"; };
BA4AFB432B6A5AF100A21367 /* CheckBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxView.swift; sourceTree = "<group>"; };
BA4AFB412B5A7A0900A21367 /* VideoDownloadQualityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoDownloadQualityView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -772,6 +776,8 @@
0604C9A92B22FACF00AD5DBF /* UIComponentsConfig.swift */,
0727876F28D23411002E9142 /* Config.swift */,
DBF6F2402B014ADA0098414B /* FirebaseConfig.swift */,
A5F4E7B42B61544A00ACD166 /* BrazeConfig.swift */,
A595689A2B6173DF00ED4F90 /* BranchConfig.swift */,
DBF6F2492B0380E00098414B /* FeaturesConfig.swift */,
DBF6F2452B01DAFE0098414B /* AgreementConfig.swift */,
BAFB99812B0E2354007D09F9 /* FacebookConfig.swift */,
Expand Down Expand Up @@ -1055,6 +1061,7 @@
021D925728DCF12900ACC565 /* AlertView.swift in Sources */,
027BD3A82909474200392132 /* KeyboardAvoidingViewController.swift in Sources */,
02E93F852AEBAEBC006C4750 /* AppReviewViewModel.swift in Sources */,
A595689B2B6173DF00ED4F90 /* BranchConfig.swift in Sources */,
0770DE2528D08FBA006D8A5D /* CoreStorage.swift in Sources */,
BA8FA6612AD5974300EA029A /* AppleAuthProvider.swift in Sources */,
BA8FA6702AD59EA300EA029A /* MicrosoftAuthProvider.swift in Sources */,
Expand Down Expand Up @@ -1082,6 +1089,7 @@
DBF6F2412B014ADA0098414B /* FirebaseConfig.swift in Sources */,
072787B628D37A0E002E9142 /* Validator.swift in Sources */,
0236961D28F9A2D200EEF206 /* Data_AuthResponse.swift in Sources */,
A5F4E7B52B61544A00ACD166 /* BrazeConfig.swift in Sources */,
02AFCC182AEFDB24000360F0 /* ThirdPartyMailClient.swift in Sources */,
0233D5712AF13EC800BAC8BD /* SelectMailClientView.swift in Sources */,
BAFB99842B0E282E007D09F9 /* MicrosoftConfig.swift in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions Core/Core/Configuration/Config/BranchConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// BranchConfig.swift
// Core
//
// Created by Anton Yarmolenka on 24/01/2024.
//

import Foundation

private enum BranchKeys: String, RawStringExtractable {
case enabled = "ENABLED"
case key = "KEY"
}

public final class BranchConfig: NSObject {
public var enabled: Bool = false
public var key: String?

init(dictionary: [String: AnyObject]) {
super.init()
enabled = dictionary[BranchKeys.enabled] as? Bool == true
key = dictionary[BranchKeys.key] as? String
}
}

private let branchKey = "BRANCH"
extension Config {
public var branch: BranchConfig {
BranchConfig(dictionary: self[branchKey] as? [String: AnyObject] ?? [:])
}
}
32 changes: 32 additions & 0 deletions Core/Core/Configuration/Config/BrazeConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// BrazeConfig.swift
// Core
//
// Created by Anton Yarmolenka on 24/01/2024.
//

import Foundation

private enum BrazeKeys: String, RawStringExtractable {
case enabled = "ENABLED"
case pushNotificationsEnabled = "PUSH_NOTIFICATIONS_ENABLED"
}

public final class BrazeConfig: NSObject {
public var enabled: Bool = false
public var pushNotificationsEnabled: Bool = false

init(dictionary: [String: AnyObject]) {
super.init()
enabled = dictionary[BrazeKeys.enabled] as? Bool == true
let pushNotificationsEnabled = dictionary[BrazeKeys.pushNotificationsEnabled] as? Bool ?? false
self.pushNotificationsEnabled = enabled && pushNotificationsEnabled
}
}

private let brazeKey = "BRAZE"
extension Config {
public var braze: BrazeConfig {
BrazeConfig(dictionary: self[brazeKey] as? [String: AnyObject] ?? [:])
}
}
2 changes: 2 additions & 0 deletions Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public protocol ConfigProtocol {
var theme: ThemeConfig { get }
var uiComponents: UIComponentsConfig { get }
var discovery: DiscoveryConfig { get }
var braze: BrazeConfig { get }
var branch: BranchConfig { get }
var program: DiscoveryConfig { get }
var URIScheme: String { get }
}
Expand Down
21 changes: 21 additions & 0 deletions Core/CoreTests/Configuration/ConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class ConfigTests: XCTestCase {
],
"APPLE_SIGNIN": [
"ENABLED": true
],
"BRAZE": [
"ENABLED": true,
"PUSH_NOTIFICATIONS_ENABLED": true
],
"BRANCH": [
"ENABLED": true,
"KEY": "testBranchKey"
]
]

Expand Down Expand Up @@ -115,4 +123,17 @@ class ConfigTests: XCTestCase {

XCTAssertTrue(config.appleSignIn.enabled)
}

func testBrazeConfigInitialization() {
let config = Config(properties: properties)

XCTAssertTrue(config.braze.pushNotificationsEnabled)
}

func testBranchConfigInitialization() {
let config = Config(properties: properties)

XCTAssertTrue(config.branch.enabled)
XCTAssertEqual(config.branch.key, "testBranchKey")
}
}
104 changes: 102 additions & 2 deletions OpenEdX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
07D5DA3E28D075AB00752FD9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 07D5DA3D28D075AB00752FD9 /* Assets.xcassets */; };
07D5DA4128D075AB00752FD9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 07D5DA3F28D075AB00752FD9 /* LaunchScreen.storyboard */; };
95C140F3BDF778364986E83B /* Pods_App_OpenEdX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F138C15C3A2515F8F94DAA8B /* Pods_App_OpenEdX.framework */; };
A500668B2B613ED10024680B /* PushNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A500668A2B613ED10024680B /* PushNotificationsManager.swift */; };
A500668D2B6143000024680B /* FCMProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A500668C2B6143000024680B /* FCMProvider.swift */; };
A50066912B61467B0024680B /* BrazeProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50066902B61467B0024680B /* BrazeProvider.swift */; };
A50066932B614DCD0024680B /* FCMListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50066922B614DCD0024680B /* FCMListener.swift */; };
A50066952B614DEF0024680B /* BrazeListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50066942B614DEF0024680B /* BrazeListener.swift */; };
A59568952B61630500ED4F90 /* DeepLinkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59568942B61630500ED4F90 /* DeepLinkManager.swift */; };
A59568972B61653700ED4F90 /* DeepLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59568962B61653700ED4F90 /* DeepLink.swift */; };
A59568992B616D9400ED4F90 /* PushLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59568982B616D9400ED4F90 /* PushLink.swift */; };
A59585AF2B62A07100A35A20 /* BranchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59585AE2B62A07100A35A20 /* BranchService.swift */; };
BA3042792B1F7147009B64B7 /* MSAL in Frameworks */ = {isa = PBXBuildFile; productRef = BA3042782B1F7147009B64B7 /* MSAL */; };
E0D6E6A32B1626B10089F9C9 /* Theme.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0D6E6A22B1626B10089F9C9 /* Theme.framework */; };
E0D6E6A42B1626D60089F9C9 /* Theme.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E0D6E6A22B1626B10089F9C9 /* Theme.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -115,6 +124,15 @@
6F54C19C823A769E18923FA8 /* Pods-App-OpenEdX.debugstage.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-OpenEdX.debugstage.xcconfig"; path = "Target Support Files/Pods-App-OpenEdX/Pods-App-OpenEdX.debugstage.xcconfig"; sourceTree = "<group>"; };
8284179FC05AEE2591573E20 /* Pods-App-OpenEdX.debugdev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-OpenEdX.debugdev.xcconfig"; path = "Target Support Files/Pods-App-OpenEdX/Pods-App-OpenEdX.debugdev.xcconfig"; sourceTree = "<group>"; };
A24D6A8E1BC4DF46AD68904C /* Pods-App-OpenEdX.releaseprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-OpenEdX.releaseprod.xcconfig"; path = "Target Support Files/Pods-App-OpenEdX/Pods-App-OpenEdX.releaseprod.xcconfig"; sourceTree = "<group>"; };
A500668A2B613ED10024680B /* PushNotificationsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationsManager.swift; sourceTree = "<group>"; };
A500668C2B6143000024680B /* FCMProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FCMProvider.swift; sourceTree = "<group>"; };
A50066902B61467B0024680B /* BrazeProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrazeProvider.swift; sourceTree = "<group>"; };
A50066922B614DCD0024680B /* FCMListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FCMListener.swift; sourceTree = "<group>"; };
A50066942B614DEF0024680B /* BrazeListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrazeListener.swift; sourceTree = "<group>"; };
A59568942B61630500ED4F90 /* DeepLinkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLinkManager.swift; sourceTree = "<group>"; };
A59568962B61653700ED4F90 /* DeepLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLink.swift; sourceTree = "<group>"; };
A59568982B616D9400ED4F90 /* PushLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushLink.swift; sourceTree = "<group>"; };
A59585AE2B62A07100A35A20 /* BranchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BranchService.swift; sourceTree = "<group>"; };
A89AD827F52CF6A6B903606E /* Pods-App-OpenEdX.releasestage.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-OpenEdX.releasestage.xcconfig"; path = "Target Support Files/Pods-App-OpenEdX/Pods-App-OpenEdX.releasestage.xcconfig"; sourceTree = "<group>"; };
BB08ACD2CCA33D6DDDDD31B4 /* Pods-App-OpenEdX.releasedev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-OpenEdX.releasedev.xcconfig"; path = "Target Support Files/Pods-App-OpenEdX/Pods-App-OpenEdX.releasedev.xcconfig"; sourceTree = "<group>"; };
E0D6E6A22B1626B10089F9C9 /* Theme.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Theme.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -200,8 +218,7 @@
07D5DA3428D075AA00752FD9 /* AppDelegate.swift */,
0770DE1628D080A1006D8A5D /* RouteController.swift */,
0770DE1F28D0858A006D8A5D /* Router.swift */,
0298DF2F2A4EF7230023A257 /* AnalyticsManager.swift */,
02F175302A4DA95B0019CD70 /* MainScreenAnalytics.swift */,
A50066882B613E800024680B /* Managers */,
0293A2012A6FC9E30090A336 /* Data */,
0727878C28D347B2002E9142 /* View */,
0770DE1A28D084BC006D8A5D /* DI */,
Expand Down Expand Up @@ -248,6 +265,80 @@
path = Pods;
sourceTree = "<group>";
};
A50066872B613E4B0024680B /* PushNotificationsManager */ = {
isa = PBXGroup;
children = (
A500668A2B613ED10024680B /* PushNotificationsManager.swift */,
A50066962B614F0C0024680B /* Providers */,
A50066972B614F2B0024680B /* Listeners */,
);
path = PushNotificationsManager;
sourceTree = "<group>";
};
A50066882B613E800024680B /* Managers */ = {
isa = PBXGroup;
children = (
A59568932B6162E400ED4F90 /* DeepLinkManager */,
A50066872B613E4B0024680B /* PushNotificationsManager */,
A50066892B613E990024680B /* AnalyticsManager */,
);
path = Managers;
sourceTree = "<group>";
};
A50066892B613E990024680B /* AnalyticsManager */ = {
isa = PBXGroup;
children = (
0298DF2F2A4EF7230023A257 /* AnalyticsManager.swift */,
02F175302A4DA95B0019CD70 /* MainScreenAnalytics.swift */,
);
path = AnalyticsManager;
sourceTree = "<group>";
};
A50066962B614F0C0024680B /* Providers */ = {
isa = PBXGroup;
children = (
A500668C2B6143000024680B /* FCMProvider.swift */,
A50066902B61467B0024680B /* BrazeProvider.swift */,
);
path = Providers;
sourceTree = "<group>";
};
A50066972B614F2B0024680B /* Listeners */ = {
isa = PBXGroup;
children = (
A50066922B614DCD0024680B /* FCMListener.swift */,
A50066942B614DEF0024680B /* BrazeListener.swift */,
);
path = Listeners;
sourceTree = "<group>";
};
A59568932B6162E400ED4F90 /* DeepLinkManager */ = {
isa = PBXGroup;
children = (
A59568942B61630500ED4F90 /* DeepLinkManager.swift */,
A5F46FD02B692B140003EEEF /* Services */,
A59585AD2B62677B00A35A20 /* Link */,
);
path = DeepLinkManager;
sourceTree = "<group>";
};
A59585AD2B62677B00A35A20 /* Link */ = {
isa = PBXGroup;
children = (
A59568962B61653700ED4F90 /* DeepLink.swift */,
A59568982B616D9400ED4F90 /* PushLink.swift */,
);
path = Link;
sourceTree = "<group>";
};
A5F46FD02B692B140003EEEF /* Services */ = {
isa = PBXGroup;
children = (
A59585AE2B62A07100A35A20 /* BranchService.swift */,
);
path = Services;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -413,22 +504,31 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A500668B2B613ED10024680B /* PushNotificationsManager.swift in Sources */,
0293A2052A6FCD430090A336 /* CoursePersistence.swift in Sources */,
020CA5D92AA0A25300970AAF /* AppStorage.swift in Sources */,
0298DF302A4EF7230023A257 /* AnalyticsManager.swift in Sources */,
A59585AF2B62A07100A35A20 /* BranchService.swift in Sources */,
A50066912B61467B0024680B /* BrazeProvider.swift in Sources */,
0293A2072A6FCDA30090A336 /* DiscoveryPersistence.swift in Sources */,
07D5DA3528D075AA00752FD9 /* AppDelegate.swift in Sources */,
02F175312A4DA95B0019CD70 /* MainScreenAnalytics.swift in Sources */,
0727878E28D347C7002E9142 /* MainScreenView.swift in Sources */,
0770DE5028D0A707006D8A5D /* NetworkAssembly.swift in Sources */,
0293A2032A6FCA590090A336 /* CorePersistence.swift in Sources */,
0770DE1E28D084E8006D8A5D /* AppAssembly.swift in Sources */,
A50066932B614DCD0024680B /* FCMListener.swift in Sources */,
A500668D2B6143000024680B /* FCMProvider.swift in Sources */,
025AD4AC2A6FB95C00AB8FA7 /* DatabaseManager.swift in Sources */,
024E69202AEFC3FB00FA0B59 /* MainScreenViewModel.swift in Sources */,
0770DE2028D0858A006D8A5D /* Router.swift in Sources */,
0293A2092A6FCDE50090A336 /* DashboardPersistence.swift in Sources */,
0770DE1728D080A1006D8A5D /* RouteController.swift in Sources */,
A59568952B61630500ED4F90 /* DeepLinkManager.swift in Sources */,
A50066952B614DEF0024680B /* BrazeListener.swift in Sources */,
071009C928D1DB3F00344290 /* ScreenAssembly.swift in Sources */,
A59568972B61653700ED4F90 /* DeepLink.swift in Sources */,
A59568992B616D9400ED4F90 /* PushLink.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 35e7cbe

Please sign in to comment.