filter caption strings for display

pull/1/head
Michael Kirk 7 years ago
parent 3b53ee08ba
commit 74b25c14f1

@ -4,6 +4,12 @@
import Foundation import Foundation
extension String {
var filterForDisplay: String? {
return (self as NSString).filterStringForDisplay()
}
}
public enum GalleryDirection { public enum GalleryDirection {
case before, after, around case before, after, around
} }
@ -12,10 +18,12 @@ public class MediaGalleryItem: Equatable, Hashable {
let message: TSMessage let message: TSMessage
let attachmentStream: TSAttachmentStream let attachmentStream: TSAttachmentStream
let galleryDate: GalleryDate let galleryDate: GalleryDate
let captionForDisplay: String?
init(message: TSMessage, attachmentStream: TSAttachmentStream) { init(message: TSMessage, attachmentStream: TSAttachmentStream) {
self.message = message self.message = message
self.attachmentStream = attachmentStream self.attachmentStream = attachmentStream
self.captionForDisplay = attachmentStream.caption?.filterForDisplay
self.galleryDate = GalleryDate(message: message) self.galleryDate = GalleryDate(message: message)
} }
@ -31,10 +39,6 @@ public class MediaGalleryItem: Equatable, Hashable {
return attachmentStream.isImage return attachmentStream.isImage
} }
var caption: String? {
return attachmentStream.caption
}
public typealias AsyncThumbnailBlock = (UIImage) -> Void public typealias AsyncThumbnailBlock = (UIImage) -> Void
func thumbnailImage(async:@escaping AsyncThumbnailBlock) -> UIImage? { func thumbnailImage(async:@escaping AsyncThumbnailBlock) -> UIImage? {
return attachmentStream.thumbnailImageSmall(success: async, failure: {}) return attachmentStream.thumbnailImageSmall(success: async, failure: {})

@ -172,7 +172,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
captionViewsContainer.addSubview(currentCaptionView) captionViewsContainer.addSubview(currentCaptionView)
currentCaptionView.autoPinEdgesToSuperviewEdges(with: .zero, excludingEdge: .top) currentCaptionView.autoPinEdgesToSuperviewEdges(with: .zero, excludingEdge: .top)
currentCaptionView.autoPinEdge(toSuperviewEdge: .top, withInset: 0, relation: .greaterThanOrEqual) currentCaptionView.autoPinEdge(toSuperviewEdge: .top, withInset: 0, relation: .greaterThanOrEqual)
currentCaptionView.text = currentItem.caption currentCaptionView.text = currentItem.captionForDisplay
let pendingCaptionView = CaptionView() let pendingCaptionView = CaptionView()
self.pendingCaptionView = pendingCaptionView self.pendingCaptionView = pendingCaptionView
@ -447,7 +447,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
CATransaction.begin() CATransaction.begin()
CATransaction.disableActions() CATransaction.disableActions()
if let pendingCaptionText = pendingViewController.galleryItem.caption, pendingCaptionText.count > 0 { if let pendingCaptionText = pendingViewController.galleryItem.captionForDisplay, pendingCaptionText.count > 0 {
self.pendingCaptionView.text = pendingCaptionText self.pendingCaptionView.text = pendingCaptionText
} else { } else {
self.pendingCaptionView.text = nil self.pendingCaptionView.text = nil

Loading…
Cancel
Save