react-native-netmera 2.0.0-beta01 → 2.0.0-beta03

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +2 -2
  2. package/RNNetmera.podspec +1 -1
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/netmera/reactnativesdk/RNNetmeraPushActionCallbacks.kt +13 -17
  5. package/android/src/main/java/com/netmera/reactnativesdk/RNNetmeraUtil.kt +39 -8
  6. package/ios/RNNetmera.swift +54 -55
  7. package/ios/RNNetmeraPushLifecycleDelegate.swift +14 -18
  8. package/ios/RNNetmeraPushObject.swift +77 -88
  9. package/lib/module/Netmera.js +37 -16
  10. package/lib/module/Netmera.js.map +1 -1
  11. package/lib/module/index.js +5 -2
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/models/NetmeraCarouselObject.js +18 -0
  14. package/lib/module/models/NetmeraCarouselObject.js.map +1 -0
  15. package/lib/module/models/NetmeraInteractiveAction.js +18 -0
  16. package/lib/module/models/NetmeraInteractiveAction.js.map +1 -0
  17. package/lib/module/models/NetmeraPushAction.js +27 -0
  18. package/lib/module/models/NetmeraPushAction.js.map +1 -0
  19. package/lib/module/models/NetmeraPushObject.js +58 -0
  20. package/lib/module/models/NetmeraPushObject.js.map +1 -0
  21. package/lib/typescript/src/Netmera.d.ts +8 -4
  22. package/lib/typescript/src/Netmera.d.ts.map +1 -1
  23. package/lib/typescript/src/index.d.ts +5 -2
  24. package/lib/typescript/src/index.d.ts.map +1 -1
  25. package/lib/typescript/src/models/NetmeraCarouselObject.d.ts +8 -0
  26. package/lib/typescript/src/models/NetmeraCarouselObject.d.ts.map +1 -0
  27. package/lib/typescript/src/models/NetmeraCategory.d.ts +2 -2
  28. package/lib/typescript/src/models/NetmeraCategory.d.ts.map +1 -1
  29. package/lib/typescript/src/models/NetmeraInteractiveAction.d.ts +9 -0
  30. package/lib/typescript/src/models/NetmeraInteractiveAction.d.ts.map +1 -0
  31. package/lib/typescript/src/models/NetmeraPushAction.d.ts +17 -0
  32. package/lib/typescript/src/models/NetmeraPushAction.d.ts.map +1 -0
  33. package/lib/typescript/src/models/NetmeraPushObject.d.ts +40 -0
  34. package/lib/typescript/src/models/NetmeraPushObject.d.ts.map +1 -0
  35. package/package.json +1 -1
  36. package/src/Netmera.ts +57 -36
  37. package/src/index.ts +10 -2
  38. package/src/models/NetmeraCarouselObject.ts +23 -0
  39. package/src/models/NetmeraCategory.ts +2 -2
  40. package/src/models/NetmeraInteractiveAction.ts +21 -0
  41. package/src/models/NetmeraPushAction.ts +28 -0
  42. package/src/models/NetmeraPushObject.ts +90 -0
  43. package/lib/module/models/NetmeraInbox.js +0 -8
  44. package/lib/module/models/NetmeraInbox.js.map +0 -1
  45. package/lib/typescript/src/models/NetmeraInbox.d.ts +0 -22
  46. package/lib/typescript/src/models/NetmeraInbox.d.ts.map +0 -1
  47. package/src/models/NetmeraInbox.ts +0 -25
package/README.md CHANGED
@@ -173,8 +173,8 @@ RNNetmera.initNetmera()
173
173
 
174
174
  ```
175
175
  // For receiving Media Push, you must add Netmera pods to top of your Podfile.
176
- pod 'NetmeraNotificationServiceExtension', "4.18.0"
177
- pod "NetmeraNotificationContentExtension", "4.18.0"
176
+ pod 'NetmeraNotificationServiceExtension', "4.19.0"
177
+ pod "NetmeraNotificationContentExtension", "4.19.0"
178
178
  ```
179
179
 
180
180
  7. In order to use the widget URL callback, add these lines into `AppDelegate.swift` file.
package/RNNetmera.podspec CHANGED
@@ -19,7 +19,7 @@ NETMERA is a Mobile Application Engagement Platform. We offer a series of develo
19
19
  s.source_files = "ios/**/*.{h,m,mm,swift}"
20
20
  s.public_header_files = "ios/RNNetmera.h"
21
21
 
22
- netmera_version = '4.18.0'
22
+ netmera_version = '4.19.0'
23
23
 
24
24
  s.dependency "NetmeraAnalytic", netmera_version
25
25
  s.dependency "NetmeraAnalyticAutotracking", netmera_version
@@ -75,7 +75,7 @@ repositories {
75
75
  google()
76
76
  }
77
77
 
78
- def netmeraAndroidVersion = '4.14.4'
78
+ def netmeraAndroidVersion = '4.15.1'
79
79
 
80
80
  def kotlin_version = getExtOrDefault("kotlinVersion")
81
81
 
@@ -7,7 +7,6 @@ import android.os.Bundle
7
7
  import android.util.Log
8
8
  import com.facebook.react.HeadlessJsTaskService
9
9
  import com.facebook.react.bridge.Arguments
10
- import com.facebook.react.bridge.ReadableMap
11
10
  import com.facebook.react.bridge.WritableMap
12
11
  import com.netmera.NetmeraCarouselObject
13
12
  import com.netmera.NetmeraPushObject
@@ -28,26 +27,31 @@ class RNNetmeraPushActionCallbacks : NMPushActionCallbacks {
28
27
 
29
28
  override fun onPushRegister(context: Context, gcmSenderId: String, pushToken: String) {
30
29
  val bundle = Bundle().apply {
31
- putString("gcmSenderId", gcmSenderId)
32
30
  putString("pushToken", pushToken)
33
31
  }
34
32
  sendEvent(context, ON_PUSH_REGISTER, Arguments.fromBundle(bundle))
35
33
  }
36
34
 
37
35
  override fun onPushReceive(context: Context, bundle: Bundle?, netmeraPushObject: NetmeraPushObject) {
38
- sendEvent(context, ON_PUSH_RECEIVE, mergeMap(bundle, netmeraPushObject))
36
+ sendEvent(context, ON_PUSH_RECEIVE, RNNetmeraUtil.mapPushObject(netmeraPushObject))
39
37
  }
40
38
 
41
39
  override fun onPushOpen(context: Context, bundle: Bundle?, netmeraPushObject: NetmeraPushObject) {
42
- sendEvent(context, ON_PUSH_OPEN, mergeMap(bundle, netmeraPushObject))
40
+ sendEvent(context, ON_PUSH_OPEN, RNNetmeraUtil.mapPushObject(netmeraPushObject))
43
41
  }
44
42
 
45
43
  override fun onPushDismiss(context: Context, bundle: Bundle?, netmeraPushObject: NetmeraPushObject) {
46
- sendEvent(context, ON_PUSH_DISMISS, mergeMap(bundle, netmeraPushObject))
44
+ sendEvent(context, ON_PUSH_DISMISS, RNNetmeraUtil.mapPushObject(netmeraPushObject))
47
45
  }
48
46
 
49
47
  override fun onPushButtonClicked(context: Context, bundle: Bundle?, netmeraPushObject: NetmeraPushObject) {
50
- sendEvent(context, ON_PUSH_BUTTON_CLICKED, mergeMap(bundle, netmeraPushObject))
48
+ val map = RNNetmeraUtil.mapPushObject(netmeraPushObject)
49
+ val clickedIndex = bundle?.getInt("key.clicked.button.index", -1) ?: -1
50
+ val actions = netmeraPushObject.interactiveActions
51
+ if (clickedIndex >= 0 && actions != null && clickedIndex < actions.size) {
52
+ map.putMap("clickedAction", RNNetmeraUtil.mapInteractiveAction(actions[clickedIndex]))
53
+ }
54
+ sendEvent(context, ON_PUSH_BUTTON_CLICKED, map)
51
55
  }
52
56
 
53
57
  override fun onCarouselObjectSelected(
@@ -57,10 +61,9 @@ class RNNetmeraPushActionCallbacks : NMPushActionCallbacks {
57
61
  selectedIndex: Int,
58
62
  netmeraCarouselObject: NetmeraCarouselObject
59
63
  ) {
60
- val newBundle = bundle ?: Bundle()
61
- newBundle.putInt("selectedIndex", selectedIndex)
62
- val map = RNNetmeraUtil.mapCarouselObject(netmeraCarouselObject)
63
- map.merge(mergeMap(newBundle, netmeraPushObject))
64
+ val map = RNNetmeraUtil.mapPushObject(netmeraPushObject)
65
+ val carouselMap = RNNetmeraUtil.mapCarouselObject(netmeraCarouselObject)
66
+ map.putMap("carouselItem", carouselMap)
64
67
  sendEvent(context, ON_CAROUSEL_OBJECT_SELECTED, map)
65
68
  }
66
69
 
@@ -79,11 +82,4 @@ class RNNetmeraPushActionCallbacks : NMPushActionCallbacks {
79
82
  }
80
83
  }
81
84
 
82
- private fun mergeMap(bundle: Bundle?, netmeraPushObject: NetmeraPushObject): WritableMap {
83
- val mapPushObject = RNNetmeraUtil.mapPushObject(netmeraPushObject)
84
- val mapBundle: ReadableMap? = bundle?.let { Arguments.fromBundle(it) }
85
- mapBundle?.let { mapPushObject.merge(it) }
86
- return mapPushObject
87
- }
88
-
89
85
  }
@@ -2,8 +2,9 @@ package com.netmera.reactnativesdk
2
2
 
3
3
  import android.text.format.DateFormat
4
4
  import com.facebook.react.bridge.*
5
- import com.google.gson.Gson
5
+ import com.google.gson.JsonObject
6
6
  import com.netmera.NetmeraCarouselObject
7
+ import com.netmera.NetmeraInteractiveAction
7
8
  import com.netmera.NetmeraPushObject
8
9
  import com.netmera.data.NMCategoryPreference
9
10
  import com.netmera.data.NMCouponDetail
@@ -149,8 +150,12 @@ object RNNetmeraUtil {
149
150
  map.putString("expireTime", DateFormat.format("yyyy-MM-dd HH:mm:ss", it).toString())
150
151
  }
151
152
 
152
- pushObject.interactiveActions?.let {
153
- if (it.isNotEmpty()) map.putString("interactiveActions", Gson().toJson(it))
153
+ pushObject.interactiveActions?.let { actions ->
154
+ if (actions.isNotEmpty()) {
155
+ val actionsArray = Arguments.createArray()
156
+ actions.forEach { action -> actionsArray.pushMap(mapInteractiveAction(action)) }
157
+ map.putArray("interactiveActions", actionsArray)
158
+ }
154
159
  }
155
160
 
156
161
  pushObject.pushStyle?.let { style ->
@@ -158,7 +163,11 @@ object RNNetmeraUtil {
158
163
  style.subText?.let { map.putString("subtitle", it) }
159
164
  style.contentText?.let { map.putString("body", it) }
160
165
  style.bigPicturePath?.let { map.putString("mediaAttachmentURL", it) }
161
- style.retrieveCarouselObjects()?.let { map.putString("carousel", Gson().toJson(it)) }
166
+ style.carouselObjects?.let { carouselObjects ->
167
+ val carouselArray = Arguments.createArray()
168
+ carouselObjects.forEach { item -> carouselArray.pushMap(mapCarouselObject(item)) }
169
+ map.putArray("carousel", carouselArray)
170
+ }
162
171
  }
163
172
 
164
173
  pushObject.sendDate?.let {
@@ -166,8 +175,8 @@ object RNNetmeraUtil {
166
175
  "sendDate", DateFormat.format("yyyy-MM-dd HH:mm:ss", it).toString()
167
176
  )
168
177
  }
169
- pushObject.pushAction?.let {
170
- map.putString("pushAction", Gson().toJson(it))
178
+ pushObject.pushAction?.let { pushAction ->
179
+ map.putMap("pushAction", mapPushAction(pushAction))
171
180
  pushObject.webPageUrl?.let { url -> map.putString("webPage", url) }
172
181
  }
173
182
 
@@ -177,8 +186,30 @@ object RNNetmeraUtil {
177
186
  fun mapCarouselObject(carouselObject: NetmeraCarouselObject): WritableMap {
178
187
  val map: WritableMap = Arguments.createMap()
179
188
  map.putString("id", carouselObject.id)
180
- map.putString("action", Gson().toJson(carouselObject.action))
181
- map.putString("picturePath", carouselObject.picturePath)
189
+ carouselObject.picturePath?.let { map.putString("picturePath", it) }
190
+ carouselObject.action?.let { map.putMap("action", mapPushAction(it)) }
191
+ return map
192
+ }
193
+
194
+ fun mapInteractiveAction(action: NetmeraInteractiveAction): WritableMap {
195
+ val map: WritableMap = Arguments.createMap()
196
+ map.putString("id", action.id)
197
+ action.actionTitle?.let { map.putString("title", it) }
198
+ action.action?.let { map.putMap("act", mapPushAction(it)) }
199
+ action.customJson?.let {
200
+ try {
201
+ map.putMap("prms", jsonToWritableMap(JSONObject(it.toString())))
202
+ } catch (_: Throwable) {
203
+ }
204
+ }
205
+ return map
206
+ }
207
+
208
+ private fun mapPushAction(pushAction: JsonObject): WritableMap {
209
+ val map: WritableMap = Arguments.createMap()
210
+ pushAction.get("at")?.asInt?.let { map.putInt("at", it) }
211
+ val url = pushAction.get("uri")?.asString ?: pushAction.get("url")?.asString
212
+ url?.let { map.putString("url", it) }
182
213
  return map
183
214
  }
184
215
 
@@ -212,23 +212,22 @@ public class RNNetmera: NSObject {
212
212
  func sendEvent(_ eventDictionary: [String: Any]) {
213
213
  var dict = eventDictionary.compactMapValues { $0 is NSNull ? nil : $0 }
214
214
 
215
- if let eventKey = dict["code"] as? String,
216
- let event = RNNetmeraEvent(eventKey: eventKey) {
217
-
218
- dict.removeValue(forKey: "code")
219
-
220
- if let revenue = dict["revenue"] as? Double {
221
- event.revenue = revenue
222
- dict.removeValue(forKey: "revenue")
223
- }
224
-
225
- let converted: [String: AnyCodable] = dict.reduce(into: [:]) { result, pair in
226
- result[pair.key] = AnyCodable(pair.value)
227
- }
228
-
229
- event.eventParameters = converted
230
- Netmera.send(event)
215
+ guard let eventKey = dict["code"] as? String,
216
+ let event = RNNetmeraEvent(eventKey: eventKey) else { return }
217
+
218
+ dict.removeValue(forKey: "code")
219
+
220
+ if let revenue = dict["revenue"] as? Double {
221
+ event.revenue = revenue
222
+ dict.removeValue(forKey: "revenue")
231
223
  }
224
+
225
+ let converted: [String: AnyCodable] = dict.reduce(into: [:]) { result, pair in
226
+ result[pair.key] = AnyCodable(pair.value)
227
+ }
228
+
229
+ event.eventParameters = converted
230
+ Netmera.send(event)
232
231
  }
233
232
 
234
233
  @objc(sendGenericEvent:attributes:)
@@ -467,9 +466,7 @@ public class RNNetmera: NSObject {
467
466
  manager.inbox { result in
468
467
  switch result {
469
468
  case .success:
470
- let array: [[String: Any]] = manager.objects.map {
471
- RNNetmeraPushObject.getPushObjectMap($0)
472
- }
469
+ let array = RNNetmeraPushObject.mapPushObjects(manager.objects)
473
470
  resolver(array)
474
471
  self.netmeraInbox = manager
475
472
  break
@@ -533,7 +530,9 @@ public class RNNetmera: NSObject {
533
530
  }
534
531
 
535
532
  let length = toIndex - fromIndex
536
- guard length > 0, fromIndex >= 0, toIndex <= inbox.objects.count else {
533
+ guard length > 0,
534
+ fromIndex >= 0,
535
+ toIndex <= inbox.objects.count else {
537
536
  rejecter(ERROR_CODE_UPDATE_STATUS,
538
537
  ERROR_MESSAGE_UPDATE_STATUS,
539
538
  nil)
@@ -584,26 +583,26 @@ public class RNNetmera: NSObject {
584
583
  manager.inboxCategory { result in
585
584
  switch result {
586
585
  case .success(let isSuccess):
587
- if isSuccess {
588
- self.categoryManager = manager
589
- resolver(manager.categories.map { categoryObject in
590
- var data: [String: Any] = [:]
591
- data["categoryName"] = categoryObject.categoryName
592
- data["readCount"] = categoryObject.statusCounts[.read] ?? 0
593
- data["unreadCount"] = categoryObject.statusCounts[.unread] ?? 0
594
- data["deletedCount"] = categoryObject.statusCounts[.deleted] ?? 0
595
- if let lastMessage = categoryObject.lastMessage {
596
- let lastMsg = RNNetmeraPushObject.getPushObjectMap(lastMessage)
597
- if let jsonData = try? JSONSerialization.data(withJSONObject: lastMsg, options: []),
598
- let jsonStr = String(data: jsonData, encoding: .utf8) {
599
- data["lastMessage"] = jsonStr
600
- }
601
- }
602
- return data
603
- })
604
- } else {
586
+ guard isSuccess else {
605
587
  rejecter(ERROR_CODE_NULL_CATEGORY, ERROR_MESSAGE_NULL_CATEGORY, nil)
588
+ return
606
589
  }
590
+ self.categoryManager = manager
591
+ resolver(manager.categories.map { categoryObject in
592
+ var data: [String: Any] = [:]
593
+ data["categoryName"] = categoryObject.categoryName
594
+ data["readCount"] = categoryObject.statusCounts[.read] ?? 0
595
+ data["unreadCount"] = categoryObject.statusCounts[.unread] ?? 0
596
+ data["deletedCount"] = categoryObject.statusCounts[.deleted] ?? 0
597
+ if let lastMessage = categoryObject.lastMessage {
598
+ let lastMsg = RNNetmeraPushObject.mapPushObject(lastMessage)
599
+ if let jsonData = try? JSONSerialization.data(withJSONObject: lastMsg, options: []),
600
+ let jsonStr = String(data: jsonData, encoding: .utf8) {
601
+ data["lastMessage"] = jsonStr
602
+ }
603
+ }
604
+ return data
605
+ })
607
606
  case .failure(let error):
608
607
  rejecter(
609
608
  ERROR_CODE_NULL_CATEGORY,
@@ -625,25 +624,25 @@ public class RNNetmera: NSObject {
625
624
  category.nextPage { status in
626
625
  switch status {
627
626
  case .success(let isSuccess):
628
- if isSuccess {
629
- resolve(category.categories.map { categoryObject in
630
- var data: [String: Any] = [:]
631
- data["categoryName"] = categoryObject.categoryName
632
- data["readCount"] = categoryObject.statusCounts[.read] ?? 0
633
- data["unreadCount"] = categoryObject.statusCounts[.unread] ?? 0
634
- data["deletedCount"] = categoryObject.statusCounts[.deleted] ?? 0
635
- if let lastMessage = categoryObject.lastMessage {
636
- let lastMsg = RNNetmeraPushObject.getPushObjectMap(lastMessage)
637
- if let jsonData = try? JSONSerialization.data(withJSONObject: lastMsg, options: []),
638
- let jsonStr = String(data: jsonData, encoding: .utf8) {
639
- data["lastMessage"] = jsonStr
640
- }
641
- }
642
- return data
643
- })
644
- } else {
627
+ guard isSuccess else {
645
628
  reject(ERROR_CODE_NULL_CATEGORY, ERROR_MESSAGE_NULL_CATEGORY, nil)
629
+ return
646
630
  }
631
+ resolve(category.categories.map { categoryObject in
632
+ var data: [String: Any] = [:]
633
+ data["categoryName"] = categoryObject.categoryName
634
+ data["readCount"] = categoryObject.statusCounts[.read] ?? 0
635
+ data["unreadCount"] = categoryObject.statusCounts[.unread] ?? 0
636
+ data["deletedCount"] = categoryObject.statusCounts[.deleted] ?? 0
637
+ if let lastMessage = categoryObject.lastMessage {
638
+ let lastMsg = RNNetmeraPushObject.mapPushObject(lastMessage)
639
+ if let jsonData = try? JSONSerialization.data(withJSONObject: lastMsg, options: []),
640
+ let jsonStr = String(data: jsonData, encoding: .utf8) {
641
+ data["lastMessage"] = jsonStr
642
+ }
643
+ }
644
+ return data
645
+ })
647
646
  case .failure(let error):
648
647
  reject(ERROR_CODE_NULL_CATEGORY,
649
648
  "There was a problem fetching next category page: \(error.localizedDescription)",
@@ -14,40 +14,36 @@ final class RNNetmeraPushLifecycleDelegate: NetmeraPushLifecycleDelegate {
14
14
  }
15
15
 
16
16
  func didReceive(_ push: NetmeraBasePush) {
17
- guard let payload = RNNetmeraPushObject.getBasePushObjectMap(push) else { return }
18
- RNNetmeraRCTEventEmitter.onPushReceive(["payload": payload])
17
+ RNNetmeraRCTEventEmitter.onPushReceive(RNNetmeraPushObject.getPushObjectMap(push))
19
18
  }
20
19
 
21
20
  func didOpen(_ push: NetmeraBasePush) {
22
21
  if let deeplink = push.deeplinkURL {
23
22
  RNNetmeraRCTEventEmitter.onDeeplinkTriggered(deeplink)
24
23
  }
25
- guard let payload = RNNetmeraPushObject.getBasePushObjectMap(push) else { return }
26
- RNNetmeraRCTEventEmitter.onPushOpen(["payload": payload])
24
+ RNNetmeraRCTEventEmitter.onPushOpen(RNNetmeraPushObject.getPushObjectMap(push))
27
25
  }
28
26
 
29
27
  func didTakeAction(_ action: NetmeraBaseAction?, from source: NetmeraActionSource, for push: NetmeraBasePush) {
30
28
  if let deeplink = action?.deeplinkURL {
31
- RNNetmeraRCTEventEmitter.onDeeplinkTriggered(deeplink)
32
- }
33
-
34
- guard let payload = RNNetmeraPushObject.getBasePushObjectMap(push),
35
- let actionMap = RNNetmeraPushObject.getActionMap(action) else {
36
- return
29
+ RNNetmeraRCTEventEmitter.onDeeplinkTriggered(deeplink)
37
30
  }
38
-
39
- let eventData: [String: Any] = [
40
- "payload": payload,
41
- "action": actionMap
42
- ]
31
+
32
+ var eventData = RNNetmeraPushObject.getPushObjectMap(push)
43
33
 
44
34
  switch source {
45
35
  case .interactiveButton:
46
- RNNetmeraRCTEventEmitter.onPushButtonClicked(eventData)
36
+ if let actionMap = RNNetmeraPushObject.getInteractiveActionMap(action) {
37
+ eventData["clickedAction"] = actionMap
38
+ }
39
+ RNNetmeraRCTEventEmitter.onPushButtonClicked(eventData)
47
40
  case .carouselItem:
48
- RNNetmeraRCTEventEmitter.onCarouselItemClicked(eventData)
41
+ if let content = action as? NetmeraContentPushItem {
42
+ eventData["carouselItem"] = RNNetmeraPushObject.getCarouselItemMap(content)
43
+ }
44
+ RNNetmeraRCTEventEmitter.onCarouselItemClicked(eventData)
49
45
  @unknown default:
50
- break
46
+ break
51
47
  }
52
48
  }
53
49
  }
@@ -16,114 +16,103 @@ import NetmeraNotificationCore
16
16
  class RNNetmeraPushObject {
17
17
 
18
18
  static func mapPushObjects(_ pushObjects: [NetmeraInboxPush]) -> [[String: Any]] {
19
- return pushObjects.map { getPushObjectMap($0) }
19
+ return pushObjects.map { mapPushObject($0) }
20
+ }
21
+
22
+ static func mapPushObject(_ push: NetmeraInboxPush) -> [String: Any] {
23
+ guard let payload = push.payload else { return [:] }
24
+
25
+ var data = getPushObjectMap(payload)
26
+ if let status = push.status { data["inboxStatus"] = status.rawValue }
27
+
28
+ return data
20
29
  }
21
30
 
22
- static func getPushObjectMap(_ pushObject: NetmeraInboxPush) -> [String: Any] {
31
+ static func getPushObjectMap(_ push: NetmeraBasePush?) -> [String: Any] {
23
32
  var data: [String: Any] = [:]
24
-
25
- let push = pushObject.payload
26
- data["pushType"] = push?.pushType.rawValue ?? 0
27
- data["pushId"] = push?.pushId ?? ""
28
- data["pushInstanceId"] = push?.pushInstanceId ?? ""
29
- data["inboxStatus"] = pushObject.status?.rawValue
30
- data["category"] = push?.category ?? ""
31
- data["customJson"] = push?.params ?? [:]
32
- data["mediaAttachmentURL"] = push?.mediaAttachmentURL ?? ""
33
- data["externalId"] = push?.externalId ?? ""
34
-
35
- if let carousel = push?.carousel {
36
- data["carousel"] = carousel.map { item in
37
- var itemMap: [String: Any?] = [:]
38
- itemMap["id"] = item.id
39
- itemMap["bpp"] = item.url?.absoluteString
40
- itemMap["ctitle"] = item.title
41
- itemMap["ctext"] = item.subtitle
42
-
43
- if let action = item.action {
44
- itemMap["action"] = mapAction(action)
45
- }
46
-
47
- return itemMap
33
+ guard let push else { return data }
34
+
35
+ // MARK: NetmeraBasePush fields
36
+ data["pushType"] = push.pushType.rawValue
37
+ if let pushId = push.pushId { data["pushId"] = pushId }
38
+ if let pushInstanceId = push.pushInstanceId { data["pushInstanceId"] = pushInstanceId }
39
+ if let category = push.category { data["category"] = category }
40
+ if let customJson = push.params { data["customJson"] = customJson }
41
+ if let externalId = push.externalId { data["externalId"] = externalId }
42
+ if let categories = push.categoryIds { data["categories"] = categories }
43
+ if let sd = push.sendDate { data["sendDate"] = formatDate(sd) }
44
+ if let ed = push.expirationDate { data["expireTime"] = formatDate(ed) }
45
+
46
+ if let action = push.action {
47
+ data["pushAction"] = mapPushAction(action)
48
+ if let dl = (action as? NetmeraDeeplinkAction)?.deeplinkURL {
49
+ data["deepLink"] = dl
50
+ } else if let url = (action as? NetmeraWebViewAction)?.url {
51
+ data["webPage"] = url
48
52
  }
49
53
  }
50
-
51
- if let categories = push?.categoryIds {
52
- data["categories"] = categories
53
- }
54
-
55
- let alert = pushObject.alert
56
- data["title"] = alert?.title ?? ""
57
- data["subtitle"] = alert?.subtitle ?? ""
58
- data["body"] = alert?.body ?? ""
59
-
60
- if let expireDate = push?.expirationDate {
61
- data["expireTime"] = formatDate(expireDate)
54
+
55
+ // MARK: NetmeraStandartPush fields
56
+ if let standartPush = push as? NetmeraStandartPush,
57
+ let alert = standartPush.aps?.alert {
58
+ if let title = alert.title { data["title"] = title }
59
+ if let subtitle = alert.subtitle { data["subtitle"] = subtitle }
60
+ if let body = alert.body { data["body"] = body }
62
61
  }
63
-
64
- if let action = push?.action {
65
- let mappedAction = mapAction(action)
66
- data["pushAction"] = mappedAction
67
-
68
- if (action.actionType == .openDeeplink) {
69
- if let a = action as? NetmeraDeeplinkAction {
70
- data["action_deeplink_url"] = a.deeplinkURL
71
- }
72
- } else if (action.actionType == .showWebView) {
73
- if let a = action as? NetmeraWebViewAction {
74
- data["action_webpage_url"] = a.url
62
+
63
+ // MARK: NetmeraInboxPush.Payload fields
64
+ if let inboxPush = push as? NetmeraInboxPush.Payload {
65
+ if let url = inboxPush.mediaAttachmentURL { data["mediaAttachmentURL"] = url }
66
+
67
+ if let carousel = inboxPush.carousel {
68
+ data["carousel"] = carousel.map { item -> [String: Any] in
69
+ var itemMap: [String: Any] = [:]
70
+ itemMap["id"] = item.id
71
+ itemMap["picturePath"] = item.url?.absoluteString
72
+ if let action = item.action { itemMap["action"] = mapPushAction(action) }
73
+ return itemMap
75
74
  }
76
75
  }
77
- }
78
-
79
- if let actions = push?.interactiveAction {
80
- let mapped = actions.map { actionItem -> [String: Any] in
81
- var dict: [String: Any] = [:]
82
- dict["id"] = actionItem.id ?? ""
83
- dict["text"] = actionItem.title ?? ""
84
- if let act = actionItem.action {
85
- dict["act"] = mapAction(act)
76
+
77
+ if let ia = inboxPush.interactiveAction {
78
+ let mapped = ia.map { actionItem -> [String: Any] in
79
+ var dict: [String: Any] = [:]
80
+ if let id = actionItem.id { dict["id"] = id }
81
+ if let title = actionItem.title { dict["title"] = title }
82
+ if let act = actionItem.action { dict["act"] = mapPushAction(act) }
83
+ dict["prms"] = actionItem.params ?? [:]
84
+ return dict
85
+ }
86
+ if let jsonData = try? JSONSerialization.data(withJSONObject: mapped, options: []) {
87
+ data["interactiveActions"] = String(data: jsonData, encoding: .utf8)
86
88
  }
87
- dict["prms"] = actionItem.params ?? [:]
88
- return dict
89
- }
90
-
91
- if let jsonData = try? JSONSerialization.data(withJSONObject: mapped, options: []) {
92
- data["interactiveActions"] = String(data: jsonData, encoding: .utf8)
93
89
  }
94
90
  }
95
91
 
96
- if let sendDate = push?.sendDate {
97
- data["sendDate"] = formatDate(sendDate)
98
- }
99
-
100
92
  return data
101
93
  }
102
94
 
103
- static func getBasePushObjectMap(_ push: NetmeraBasePush) -> [String: Any]? {
104
- guard
105
- let data = try? JSONEncoder().encode(push),
106
- let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
107
- else {
108
- return nil
109
- }
110
-
95
+ static func getCarouselItemMap(_ item: NetmeraContentPushItem) -> [String: Any] {
96
+ var dict: [String: Any] = [:]
97
+ if let id = item.id { dict["id"] = id }
98
+ if let url = item.url { dict["picturePath"] = url.absoluteString }
99
+ if let action = item.action { dict["action"] = mapPushAction(action) }
111
100
  return dict
112
101
  }
113
-
114
- static func getActionMap(_ action: NetmeraBaseAction?) -> [String: Any]? {
115
- guard
116
- let action,
117
- let data = try? JSONEncoder().encode(action),
118
- let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
119
- else {
120
- return nil
121
- }
122
102
 
103
+ static func getInteractiveActionMap(_ action: NetmeraBaseAction?) -> [String: Any]? {
104
+ guard let action else { return nil }
105
+ var dict: [String: Any] = [:]
106
+ if let id = action.id { dict["id"] = id }
107
+ if let prms = action.params { dict["prms"] = prms }
108
+ if let pushAction = action.action { dict["act"] = mapPushAction(pushAction) }
109
+ if let ia = action as? NetmeraPushInteractiveAction, let title = ia.title {
110
+ dict["title"] = title
111
+ }
123
112
  return dict
124
113
  }
125
114
 
126
- private static func mapAction(_ action: NetmeraPushAction) -> [String: Any] {
115
+ static func mapPushAction(_ action: NetmeraPushAction) -> [String: Any] {
127
116
  var dict: [String: Any] = [:]
128
117
  dict["at"] = action.actionType?.rawValue
129
118
 
@@ -144,7 +133,7 @@ class RNNetmeraPushObject {
144
133
  @unknown default:
145
134
  break
146
135
  }
147
- return dict.filter { !($0.value is NSNull) }
136
+ return dict.compactMapValues { $0 }
148
137
  }
149
138
 
150
139
  private static func formatDate(_ date: Date) -> String {