|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +enum IterableInAppTriggerType { |
| 4 | + immediate = 0, |
| 5 | + event = 1, |
| 6 | + never = 2, |
| 7 | +} |
| 8 | + |
| 9 | +class IterableInAppTrigger { |
| 10 | + type: IterableInAppTriggerType |
| 11 | + dict: any |
| 12 | + |
| 13 | + constructor(type: IterableInAppTriggerType, dict: any) { |
| 14 | + this.type = type |
| 15 | + this.dict = dict |
| 16 | + } |
| 17 | + |
| 18 | + 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 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +enum IterableInAppContentType { |
| 29 | + html = 0, |
| 30 | + alert = 1, |
| 31 | + banner = 2, |
| 32 | +} |
| 33 | + |
| 34 | +class IterableEdgeInsets { |
| 35 | + top: number |
| 36 | + left: number |
| 37 | + bottom: number |
| 38 | + right: number |
| 39 | + |
| 40 | + constructor(top: number, left: number, bottom: number, right: number) { |
| 41 | + this.top = top |
| 42 | + this.left = left |
| 43 | + this.bottom = bottom |
| 44 | + this.right = right |
| 45 | + } |
| 46 | + |
| 47 | + static fromDict(dict: any): IterableEdgeInsets { |
| 48 | + return new IterableEdgeInsets(dict["top"] as number, dict["left"] as number, dict["bottom"] as number, dict["right"] as number) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +interface IterableInAppContent { |
| 53 | + type: IterableInAppContentType |
| 54 | +} |
| 55 | + |
| 56 | +class IterableHtmlInAppContent implements IterableInAppContent { |
| 57 | + type: IterableInAppContentType = IterableInAppContentType.html |
| 58 | + edgeInsets: IterableEdgeInsets |
| 59 | + backgroundAlpha: number |
| 60 | + html: String |
| 61 | + |
| 62 | + constructor(edgeInsets: IterableEdgeInsets, backgroundAlpha: number, html: String) { |
| 63 | + this.edgeInsets = edgeInsets |
| 64 | + this.backgroundAlpha = backgroundAlpha |
| 65 | + this.html = html |
| 66 | + } |
| 67 | + |
| 68 | + static fromDict(dict: any): IterableHtmlInAppContent { |
| 69 | + return new IterableHtmlInAppContent( |
| 70 | + IterableEdgeInsets.fromDict(dict["edgeInsets"]), |
| 71 | + dict["backgroundAlpha"] as number, |
| 72 | + dict["html"] as String) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +class IterableInboxMetadata { |
| 77 | + title?: String |
| 78 | + subTitle?: String |
| 79 | + icon?: String |
| 80 | + |
| 81 | + constructor(title: String | undefined, subTitle: String | undefined, icon: String | undefined) { |
| 82 | + this.title = title |
| 83 | + this.subTitle = subTitle |
| 84 | + this.icon = icon |
| 85 | + } |
| 86 | + |
| 87 | + static fromDict(dict: any): IterableInboxMetadata { |
| 88 | + return new IterableInboxMetadata(dict["title"], dict["subtitle"], dict["icon"]) |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +class IterableInAppMessage { |
| 93 | + readonly messageId: String |
| 94 | + readonly campaignId: String |
| 95 | + readonly trigger: IterableInAppTrigger |
| 96 | + readonly createdAt?: Date |
| 97 | + readonly expiresAt?: Date |
| 98 | + readonly content: IterableInAppContent |
| 99 | + readonly saveToInbox: Boolean |
| 100 | + readonly inboxMetadata: IterableInboxMetadata |
| 101 | + readonly customPayload?: any |
| 102 | + readonly read: Boolean |
| 103 | + |
| 104 | + constructor(messageId: String, |
| 105 | + campaignId: String, |
| 106 | + trigger: IterableInAppTrigger, |
| 107 | + createdAt: Date | undefined, |
| 108 | + expiresAt: Date | undefined, |
| 109 | + content: IterableInAppContent, |
| 110 | + saveToInbox: Boolean, |
| 111 | + inboxMetadata: IterableInboxMetadata, |
| 112 | + customPayload: any | undefined, |
| 113 | + read: Boolean) { |
| 114 | + this.campaignId = campaignId |
| 115 | + this.messageId = messageId |
| 116 | + this.trigger = trigger |
| 117 | + this.createdAt = createdAt |
| 118 | + this.expiresAt = expiresAt |
| 119 | + this.content = content |
| 120 | + this.saveToInbox = saveToInbox |
| 121 | + this.inboxMetadata = inboxMetadata |
| 122 | + this.customPayload = customPayload |
| 123 | + this.read = read |
| 124 | + } |
| 125 | + |
| 126 | + isSilentInbox(): Boolean { |
| 127 | + return this.saveToInbox && this.trigger.type == IterableInAppTriggerType.never |
| 128 | + } |
| 129 | + |
| 130 | + static fromDict(dict: any): IterableInAppMessage { |
| 131 | + const messageId = dict["messageId"] as String |
| 132 | + const campaignId = dict["campaignId"] as String |
| 133 | + const trigger = IterableInAppTrigger.fromDict(dict["trigger"]) |
| 134 | + let createdAt = dict["createdAt"] |
| 135 | + if (createdAt) { |
| 136 | + createdAt = new Date(createdAt as number) |
| 137 | + } |
| 138 | + let expiresAt = dict["expiresAt"] |
| 139 | + if (expiresAt) { |
| 140 | + expiresAt = new Date(expiresAt as number) |
| 141 | + } |
| 142 | + let content = IterableHtmlInAppContent.fromDict(dict["content"]) |
| 143 | + let saveToInbox = dict["saveToInbox"] as Boolean |
| 144 | + let inboxMetadata = IterableInboxMetadata.fromDict(dict["inboxMetadata"]) |
| 145 | + let customPayload = dict["customPayload"] |
| 146 | + let read = dict["read"] as Boolean |
| 147 | + |
| 148 | + return new IterableInAppMessage( |
| 149 | + messageId, |
| 150 | + campaignId, |
| 151 | + trigger, |
| 152 | + createdAt, |
| 153 | + expiresAt, |
| 154 | + content, |
| 155 | + saveToInbox, |
| 156 | + inboxMetadata, |
| 157 | + customPayload, |
| 158 | + read |
| 159 | + ) |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +export { IterableInAppMessage } |
0 commit comments