@@ -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-
9415struct 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+ }
0 commit comments