Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,33 @@ import UserNotificationsUI
}
}
} else if templateType == TemplateConstants.kTemplateAutoCarousel || templateType == TemplateConstants.kTemplateManualCarousel {
// Add non empty image urls.
var imageUrls = [(url: String, description: String?)]()
var imageUrls = [(url: String, description: String?, deeplink: String)]()
if let url = jsonContent.pt_img1, !url.isEmpty {
imageUrls.append((url: url, description: jsonContent.pt_img1_alt_text))
imageUrls.append((url: url, description: jsonContent.pt_img1_alt_text, deeplink: resolveDeeplink(jsonContent.pt_dl1, fallback: actionUrl)))
}
if let url = jsonContent.pt_img2, !url.isEmpty {
imageUrls.append((url: url, description: jsonContent.pt_img2_alt_text))
imageUrls.append((url: url, description: jsonContent.pt_img2_alt_text, deeplink: resolveDeeplink(jsonContent.pt_dl2, fallback: actionUrl)))
}
if let url = jsonContent.pt_img3, !url.isEmpty {
imageUrls.append((url: url, description: jsonContent.pt_img3_alt_text))
imageUrls.append((url: url, description: jsonContent.pt_img3_alt_text, deeplink: resolveDeeplink(jsonContent.pt_dl3, fallback: actionUrl)))
}

let dispatchGroup = DispatchGroup()
var imageIndex = 1
for (_,imageDetails) in imageUrls.enumerated() {
var orderedItemViews = [Int: CTCaptionedImageView]()
for (index, imageDetails) in imageUrls.enumerated() {
dispatchGroup.enter()
CTUtiltiy.checkImageUrlValid(imageUrl: imageDetails.url) { [weak self] (imageData) in
DispatchQueue.main.async {
if imageData != nil {
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: imageDetails.url, actionUrl: actionUrl, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: imageDetails.description ?? "\(CTAccessibility.kDefaultImageDescription) \(imageIndex)")
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
self?.itemViews.append(itemView)
imageIndex = imageIndex + 1
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: imageDetails.url, actionUrl: imageDetails.deeplink, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: imageDetails.description ?? "\(CTAccessibility.kDefaultImageDescription) \(index + 1)")
orderedItemViews[index] = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
}
dispatchGroup.leave()
}
}
}
dispatchGroup.notify(queue: .main) {
self.itemViews = (0..<imageUrls.count).compactMap { orderedItemViews[$0] }
self.setUpConstraints()
}
}
Expand Down Expand Up @@ -402,4 +400,9 @@ import UserNotificationsUI
let deeplink = itemViews[currentItemIndex].components.actionUrl
return deeplink
}

private func resolveDeeplink(_ deeplink: String?, fallback: String) -> String {
guard let deeplink = deeplink, !deeplink.isEmpty else { return fallback }
return deeplink
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct CarouselProperties: Decodable {
let pt_msg: String?
let pt_msg_summary: String?
let pt_dl1: String?
let pt_dl2: String?
let pt_dl3: String?
let pt_big_img: String?
let pt_img1: String?
let pt_img2: String?
Expand Down