Skip to content

Commit 0baa7c1

Browse files
Custom serialize IterableInAppMessage
1 parent 314e23d commit 0baa7c1

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

InAppClasses.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ enum IterableInAppTriggerType {
88

99
class IterableInAppTrigger {
1010
type: IterableInAppTriggerType
11-
dict: any
1211

13-
constructor(type: IterableInAppTriggerType, dict: any) {
12+
constructor(type: IterableInAppTriggerType) {
1413
this.type = type
15-
this.dict = dict
1614
}
1715

1816
static fromDict(dict: any): IterableInAppTrigger {
19-
const type = dict["type"] as IterableInAppTriggerType
20-
if (type) {
21-
return new IterableInAppTrigger(type, dict)
22-
} else {
23-
return new IterableInAppTrigger(IterableInAppTriggerType.immediate, dict)
24-
}
17+
const type = dict["type"] as IterableInAppTriggerType | IterableInAppTriggerType.immediate
18+
return new IterableInAppTrigger(type)
2519
}
2620
}
2721

index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ export enum IterableInAppTriggerType {
7979

8080
export class IterableInAppTrigger {
8181
type: IterableInAppTriggerType
82-
dict: any
8382

84-
constructor(type: IterableInAppTriggerType, dict: any)
83+
constructor(type: IterableInAppTriggerType)
8584

8685
static fromDict(dict: any): IterableInAppTrigger
8786
}

ios/RNIterableAPI/ReactIterableAPI.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ReactIterableAPI: RCTEventEmitter {
161161
@objc(getInAppMessages:rejecter:)
162162
func getInAppMessages(resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock) {
163163
ITBInfo()
164-
resolver(IterableAPI.inAppManager.getMessages().map{ $0.toDictionary() })
164+
resolver(IterableAPI.inAppManager.getMessages().map{ ReactIterableAPI.inAppMessageToDict(message: $0) })
165165
}
166166

167167
@objc(trackEvent:)
@@ -262,7 +262,35 @@ class ReactIterableAPI: RCTEventEmitter {
262262
dict["trigger"] = inAppTriggerToDict(trigger: message.trigger)
263263
dict["createdAt"] = message.createdAt.map { $0.iterableIntValue }
264264
dict["expiresAt"] = message.expiresAt.map { $0.iterableIntValue }
265-
// dict["content"] =
265+
dict["content"] = inAppContentToDict(content: message.content)
266+
dict["saveToInbox"] = message.saveToInbox
267+
dict["inboxMetadata"] = inboxMetadataToDict(metadata: message.inboxMetadata)
268+
dict["customPayload"] = message.customPayload
269+
dict["read"] = message.read
270+
return dict
271+
}
272+
273+
private static func inAppContentToDict(content: IterableInAppContent) -> [AnyHashable: Any] {
274+
guard let htmlInAppContent = content as? IterableHtmlInAppContent else {
275+
return [:]
276+
}
277+
278+
var dict = [AnyHashable: Any]()
279+
dict["type"] = htmlInAppContent.type.rawValue
280+
dict["edgeInsets"] = edgeInsetsToDict(edgeInsets: htmlInAppContent.edgeInsets)
281+
dict["backgroundAlpha"] = htmlInAppContent.backgroundAlpha
282+
dict["html"] = htmlInAppContent.html
283+
return dict
284+
}
285+
286+
private static func inboxMetadataToDict(metadata: IterableInboxMetadata?) -> [AnyHashable: Any]? {
287+
guard let metadata = metadata else {
288+
return nil
289+
}
290+
var dict = [AnyHashable: Any]()
291+
dict["title"] = metadata.title
292+
dict["subtitle"] = metadata.subtitle
293+
dict["icon"] = metadata.icon
266294
return dict
267295
}
268296
}

0 commit comments

Comments
 (0)