Skip to content

Commit

Permalink
Parse external links from braze (#1845)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifosli committed Aug 22, 2023
1 parent 15d3e2b commit 9a91c6b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Kickstarter-iOS/AppDelegateViewModel.swift
Expand Up @@ -331,17 +331,21 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
.skipNil()
.map(navigation(fromPushEnvelope:))

let deepLinkFromBrazeNotification = self.remoteNotificationProperty.signal.skipNil()
let urlFromBrazeNotification = self.remoteNotificationProperty.signal.skipNil()
.map(BrazePushEnvelope.decodeJSONDictionary)
.skipNil()
.map { $0.abURI }
.skipNil()
.map(URL.init(string:))
.skipNil()
.map(Navigation.deepLinkMatch)

let deepLinkFromBrazeInAppNotification = self.brazeInAppNotificationURLProperty.signal.skipNil()
.map(Navigation.deepLinkMatch)
let urlFromBraze = Signal
.merge(
urlFromBrazeNotification,
self.brazeInAppNotificationURLProperty.signal.skipNil()
)

let deepLinkFromBraze = urlFromBraze.map(Navigation.deepLinkMatch)

let continueUserActivity = self.applicationContinueUserActivityProperty.signal.skipNil()

Expand Down Expand Up @@ -379,8 +383,7 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
.merge(
deepLinkFromUrl,
deepLinkFromNotification,
deepLinkFromBrazeNotification,
deepLinkFromBrazeInAppNotification,
deepLinkFromBraze,
deepLinkFromShortcut
)
.skipNil()
Expand Down Expand Up @@ -554,8 +557,11 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
.filter { $0 == .tab(.me) }
.ignoreValues()

let resolvedRedirectUrl = deepLinkUrl
.filter { Navigation.deepLinkMatch($0) == nil }
let resolvedRedirectUrl = Signal.merge(
deepLinkUrl,
urlFromBraze
)
.filter { Navigation.deepLinkMatch($0) == nil }

self.goToMobileSafari = resolvedRedirectUrl

Expand Down
13 changes: 13 additions & 0 deletions Kickstarter-iOS/AppDelegateViewModelTests.swift
Expand Up @@ -2527,6 +2527,19 @@ final class AppDelegateViewModelTests: TestCase {
}
}

func testGoToMobileSafari_BrazeInAppNotificaton() {
self.vm.inputs.applicationDidFinishLaunching(
application: UIApplication.shared,
launchOptions: [:]
)

let url = URL(string: "https://fake-url.com")!
self.vm.inputs.urlFromBrazeInAppNotification(url)

self.goToMobileSafari.assertValues([url])
self.presentViewController.assertValues([])
}

func testRemoteConfigClientConfiguredNotification_Success() {
let mockService = MockService(serverConfig: ServerConfig.staging)

Expand Down

0 comments on commit 9a91c6b

Please sign in to comment.