Skip to content

Commit

Permalink
flip logic back for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
belleklaviyo committed Dec 18, 2024
1 parent fab95ea commit a5963ac
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Klaviyo supports custom badge counts when configuring your push notification in
#### Autoclearing Badge Count
By default, Klaviyo SDK automatically clears all badges on app open. If you want to disable this behavior, in your app's `Info.plist`, add a new entry for `disable_Klaviyo_badge_autoclearing` as a Boolean set to `YES`.
By default, Klaviyo SDK automatically clears all badges on app open. If you want to disable this behavior, in your app's `Info.plist`, add a new entry for `klaviyo_badge_autoclearing` as a Boolean set to `NO`. You can turn this on again by setting this to `YES`.

#### Handling Other Badging Sources

Expand Down
10 changes: 5 additions & 5 deletions Sources/KlaviyoCore/KlaviyoEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct KlaviyoEnvironment {
notificationCenterPublisher: @escaping (NSNotification.Name) -> AnyPublisher<Notification, Never>,
getNotificationSettings: @escaping () async -> PushEnablement,
getBackgroundSetting: @escaping () -> PushBackground,
getBadgeAutoClearingIsDisabled: @escaping () async -> Bool,
getBadgeAutoClearingSetting: @escaping () async -> Bool,
startReachability: @escaping () throws -> Void,
stopReachability: @escaping () -> Void,
reachabilityStatus: @escaping () -> Reachability.NetworkStatus?,
Expand All @@ -49,7 +49,7 @@ public struct KlaviyoEnvironment {
self.notificationCenterPublisher = notificationCenterPublisher
self.getNotificationSettings = getNotificationSettings
self.getBackgroundSetting = getBackgroundSetting
self.getBadgeAutoClearingIsDisabled = getBadgeAutoClearingIsDisabled
self.getBadgeAutoClearingSetting = getBadgeAutoClearingSetting
self.startReachability = startReachability
self.stopReachability = stopReachability
self.reachabilityStatus = reachabilityStatus
Expand Down Expand Up @@ -96,7 +96,7 @@ public struct KlaviyoEnvironment {
public var notificationCenterPublisher: (NSNotification.Name) -> AnyPublisher<Notification, Never>
public var getNotificationSettings: () async -> PushEnablement
public var getBackgroundSetting: () -> PushBackground
public var getBadgeAutoClearingIsDisabled: () async -> Bool
public var getBadgeAutoClearingSetting: () async -> Bool

public var startReachability: () throws -> Void
public var stopReachability: () -> Void
Expand Down Expand Up @@ -154,8 +154,8 @@ public struct KlaviyoEnvironment {
getBackgroundSetting: {
.create(from: UIApplication.shared.backgroundRefreshStatus)
},
getBadgeAutoClearingIsDisabled: {
Bundle.main.object(forInfoDictionaryKey: "disable_Klaviyo_badge_autoclearing") as? Bool ?? false
getBadgeAutoClearingSetting: {
Bundle.main.object(forInfoDictionaryKey: "klaviyo_badge_autoclearing") as? Bool ?? true
},
startReachability: {
try reachabilityService?.startNotifier()
Expand Down
8 changes: 4 additions & 4 deletions Sources/KlaviyoSwift/StateManagement/StateManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ struct KlaviyoReducer: ReducerProtocol {
.run { send in
let settings = await environment.getNotificationSettings()
await send(KlaviyoAction.setPushEnablement(settings))
let disabled = await environment.getBadgeAutoClearingIsDisabled()
if disabled {
KlaviyoBadgeCountUtil.syncBadgeCount()
} else {
let autoclearing = await environment.getBadgeAutoClearingSetting()
if autoclearing {
await send(KlaviyoAction.setBadgeCount(0))
} else {
KlaviyoBadgeCountUtil.syncBadgeCount()
}
},
environment.timer(state.flushInterval)
Expand Down
2 changes: 1 addition & 1 deletion Tests/KlaviyoCoreTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension KlaviyoEnvironment {
notificationCenterPublisher: { _ in Empty<Notification, Never>().eraseToAnyPublisher() },
getNotificationSettings: { .authorized },
getBackgroundSetting: { .available },
getBadgeAutoClearingIsDisabled: { false },
getBadgeAutoClearingSetting: { true },
startReachability: {},
stopReachability: {},
reachabilityStatus: { nil },
Expand Down
2 changes: 1 addition & 1 deletion Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension KlaviyoEnvironment {
notificationCenterPublisher: { _ in Empty<Notification, Never>().eraseToAnyPublisher() },
getNotificationSettings: { .authorized },
getBackgroundSetting: { .available },
getBadgeAutoClearingIsDisabled: { false },
getBadgeAutoClearingSetting: { true },
startReachability: {},
stopReachability: {},
reachabilityStatus: { nil },
Expand Down
4 changes: 2 additions & 2 deletions Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
@MainActor
func testDefaultBadgeClearingOn() async throws {
let apiKey = "fake-key"
environment.getBadgeAutoClearingIsDisabled = { false }
environment.getBadgeAutoClearingSetting = { true }
let expectation = XCTestExpectation(description: "Should set badge to 0")
klaviyoSwiftEnvironment.setBadgeCount = { _ in
expectation.fulfill()
Expand Down Expand Up @@ -380,7 +380,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
@MainActor
func testDefaultBadgeClearingOff() async {
let apiKey = "fake-key"
environment.getBadgeAutoClearingIsDisabled = { true }
environment.getBadgeAutoClearingSetting = { false }
let expectation = XCTestExpectation(description: "Should not set badge to 0")
expectation.isInverted = true
klaviyoSwiftEnvironment.setBadgeCount = { _ in
Expand Down

0 comments on commit a5963ac

Please sign in to comment.