Skip to content

Commit 9867d83

Browse files
Merge pull request #409 from Iterable/feature/mob-2108-make-public
[MOB-2108] - Make IterablePushNotificationMetadata public
1 parent 6ec4121 commit 9867d83

File tree

3 files changed

+86
-79
lines changed

3 files changed

+86
-79
lines changed

swift-sdk.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
AC776DA22118B86600C27C27 /* DeviceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC776DA12118B86600C27C27 /* DeviceInfo.swift */; };
113113
AC776DA4211A17C700C27C27 /* IterableRequestUtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC776DA3211A17C700C27C27 /* IterableRequestUtilTests.swift */; };
114114
AC776DA6211A1B8A00C27C27 /* IterableRequestUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC776DA5211A1B8A00C27C27 /* IterableRequestUtil.swift */; };
115+
AC78F0E7253D7F09006378A5 /* IterablePushNotificationMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC78F0E6253D7F09006378A5 /* IterablePushNotificationMetadata.swift */; };
115116
AC7A5261227BB9D10064D67E /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7A5260227BB9D10064D67E /* DependencyContainer.swift */; };
116117
AC7B143020D02CE200877BFE /* IterableSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC2263DF20CF49B8009800EB /* IterableSDK.framework */; };
117118
AC7B4AF923C6547A00DB4758 /* CustomInboxCell3.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B4AF823C6547A00DB4758 /* CustomInboxCell3.swift */; };
@@ -448,6 +449,7 @@
448449
AC776DA12118B86600C27C27 /* DeviceInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceInfo.swift; sourceTree = "<group>"; };
449450
AC776DA3211A17C700C27C27 /* IterableRequestUtilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableRequestUtilTests.swift; sourceTree = "<group>"; };
450451
AC776DA5211A1B8A00C27C27 /* IterableRequestUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableRequestUtil.swift; sourceTree = "<group>"; };
452+
AC78F0E6253D7F09006378A5 /* IterablePushNotificationMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterablePushNotificationMetadata.swift; sourceTree = "<group>"; };
451453
AC7A5260227BB9D10064D67E /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
452454
AC7B142B20D02CE200877BFE /* swift-sdk-swift-tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "swift-sdk-swift-tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
453455
AC7B142F20D02CE200877BFE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -755,6 +757,7 @@
755757
AC7125EE20D4579E0043BBC1 /* IterableConfig.swift */,
756758
AC3C10F8213F46A900A9B839 /* IterableLogging.swift */,
757759
ACA8D1A221910C66001B1332 /* IterableMessaging.swift */,
760+
AC78F0E6253D7F09006378A5 /* IterablePushNotificationMetadata.swift */,
758761
);
759762
path = "swift-sdk";
760763
sourceTree = "<group>";
@@ -1662,6 +1665,7 @@
16621665
AC7A5261227BB9D10064D67E /* DependencyContainer.swift in Sources */,
16631666
AC776DA6211A1B8A00C27C27 /* IterableRequestUtil.swift in Sources */,
16641667
ACEDF41D2183C2EC000B9BFE /* Promise.swift in Sources */,
1668+
AC78F0E7253D7F09006378A5 /* IterablePushNotificationMetadata.swift in Sources */,
16651669
AC7125EF20D4579E0043BBC1 /* IterableConfig.swift in Sources */,
16661670
AC03094B21E532470003A288 /* InAppPersistence.swift in Sources */,
16671671
557AE6BF24A56E5E00B57750 /* Auth.swift in Sources */,

swift-sdk/Internal/NotificationHelper.swift

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,6 @@ enum NotificationInfo {
1212
case other
1313
}
1414

15-
struct IterablePushNotificationMetadata {
16-
let campaignId: NSNumber
17-
let templateId: NSNumber?
18-
let messageId: String
19-
let isGhostPush: Bool
20-
21-
init(campaignId: NSNumber, templateId: NSNumber?, messageId: String, isGhostPush: Bool) {
22-
self.campaignId = campaignId
23-
self.templateId = templateId
24-
self.messageId = messageId
25-
self.isGhostPush = isGhostPush
26-
}
27-
28-
static func metadata(fromLaunchOptions userInfo: [AnyHashable: Any]) -> IterablePushNotificationMetadata? {
29-
IterablePushNotificationMetadata(fromLaunchOptions: userInfo)
30-
}
31-
32-
func isRealCampaignNotification() -> Bool {
33-
!(isGhostPush || isProof() || isTestPush())
34-
}
35-
36-
func isProof() -> Bool {
37-
campaignId.intValue == 0 && templateId?.intValue != 0
38-
}
39-
40-
func isTestPush() -> Bool {
41-
campaignId.intValue == 0 && templateId?.intValue == 0
42-
}
43-
44-
private init?(fromLaunchOptions userInfo: [AnyHashable: Any]) {
45-
if case let NotificationInfo.iterable(iterablePushNotificationMetadata) = NotificationHelper.inspect(notification: userInfo) {
46-
self = iterablePushNotificationMetadata
47-
} else {
48-
return nil
49-
}
50-
}
51-
52-
fileprivate static func parse(itblElement: [AnyHashable: Any],
53-
isGhostPush: Bool) -> IterablePushNotificationMetadata? {
54-
guard isValidCampaignId(itblElement[Keys.campaignId.rawValue]) else {
55-
return nil
56-
}
57-
58-
guard let templateId = itblElement[Keys.templateId.rawValue] as? NSNumber else {
59-
return nil
60-
}
61-
62-
guard let messageId = itblElement[Keys.messageId.rawValue] as? String else {
63-
return nil
64-
}
65-
66-
let campaignId = itblElement[Keys.campaignId.rawValue] as? NSNumber ?? NSNumber(value: 0)
67-
68-
return IterablePushNotificationMetadata(campaignId: campaignId,
69-
templateId: templateId,
70-
messageId: messageId,
71-
isGhostPush: isGhostPush)
72-
}
73-
74-
private static func isValidCampaignId(_ campaignId: Any?) -> Bool {
75-
// campaignId doesn't have to be there (because of proofs)
76-
guard let campaignId = campaignId else {
77-
return true
78-
}
79-
80-
if let _ = campaignId as? NSNumber {
81-
return true
82-
} else {
83-
return false
84-
}
85-
}
86-
87-
enum Keys: String {
88-
case messageId
89-
case templateId
90-
case campaignId
91-
}
92-
}
93-
9415
struct ITBLSilentPushNotificationInfo {
9516
let notificationType: ITBLSilentPushNotificationType
9617
let messageId: String?
@@ -146,3 +67,56 @@ struct NotificationHelper {
14667
case isGhostPush
14768
}
14869
}
70+
71+
extension IterablePushNotificationMetadata {
72+
init?(fromLaunchOptions userInfo: [AnyHashable: Any]) {
73+
if case let NotificationInfo.iterable(iterablePushNotificationMetadata) = NotificationHelper.inspect(notification: userInfo) {
74+
self = iterablePushNotificationMetadata
75+
} else {
76+
return nil
77+
}
78+
}
79+
}
80+
81+
private extension IterablePushNotificationMetadata {
82+
static func parse(itblElement: [AnyHashable: Any],
83+
isGhostPush: Bool) -> IterablePushNotificationMetadata? {
84+
guard isValidCampaignId(itblElement[Keys.campaignId.rawValue]) else {
85+
return nil
86+
}
87+
88+
guard let templateId = itblElement[Keys.templateId.rawValue] as? NSNumber else {
89+
return nil
90+
}
91+
92+
guard let messageId = itblElement[Keys.messageId.rawValue] as? String else {
93+
return nil
94+
}
95+
96+
let campaignId = itblElement[Keys.campaignId.rawValue] as? NSNumber ?? NSNumber(value: 0)
97+
98+
return IterablePushNotificationMetadata(campaignId: campaignId,
99+
templateId: templateId,
100+
messageId: messageId,
101+
isGhostPush: isGhostPush)
102+
}
103+
104+
static func isValidCampaignId(_ campaignId: Any?) -> Bool {
105+
// campaignId doesn't have to be there (because of proofs)
106+
guard let campaignId = campaignId else {
107+
return true
108+
}
109+
110+
if let _ = campaignId as? NSNumber {
111+
return true
112+
} else {
113+
return false
114+
}
115+
}
116+
117+
enum Keys: String {
118+
case messageId
119+
case templateId
120+
case campaignId
121+
}
122+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Created by Tapash Majumder on 10/19/20.
3+
// Copyright © 2020 Iterable. All rights reserved.
4+
//
5+
6+
import Foundation
7+
8+
public struct IterablePushNotificationMetadata {
9+
public let campaignId: NSNumber
10+
public let templateId: NSNumber?
11+
public let messageId: String
12+
public let isGhostPush: Bool
13+
14+
public static func metadata(fromLaunchOptions userInfo: [AnyHashable: Any]) -> IterablePushNotificationMetadata? {
15+
IterablePushNotificationMetadata(fromLaunchOptions: userInfo)
16+
}
17+
18+
public func isRealCampaignNotification() -> Bool {
19+
!(isGhostPush || isProof() || isTestPush())
20+
}
21+
22+
public func isProof() -> Bool {
23+
campaignId.intValue == 0 && templateId?.intValue != 0
24+
}
25+
26+
public func isTestPush() -> Bool {
27+
campaignId.intValue == 0 && templateId?.intValue == 0
28+
}
29+
}

0 commit comments

Comments
 (0)