pull/782/head
Ryan Zhao 1 year ago
parent da0fb2602c
commit 5c629b2ab4

@ -16,7 +16,7 @@ public class MediaView: UIView {
// MARK: -
private let mediaCache: NSCache<NSString, AnyObject>
private let mediaCache: NSCache<NSString, AnyObject>?
public let attachment: Attachment
private let isOutgoing: Bool
private var loadBlock: (() -> Void)?
@ -45,7 +45,7 @@ public class MediaView: UIView {
// MARK: - Initializers
public required init(
mediaCache: NSCache<NSString, AnyObject>,
mediaCache: NSCache<NSString, AnyObject>? = nil,
attachment: Attachment,
isOutgoing: Bool
) {
@ -393,7 +393,7 @@ public class MediaView: UIView {
applyMediaBlock(media)
self?.mediaCache.setObject(media, forKey: cacheKey as NSString)
self?.mediaCache?.setObject(media, forKey: cacheKey as NSString)
self?.loadState.mutate { $0 = .loaded }
}
@ -402,7 +402,7 @@ public class MediaView: UIView {
return
}
if let media: AnyObject = self.mediaCache.object(forKey: cacheKey as NSString) {
if let media: AnyObject = self.mediaCache?.object(forKey: cacheKey as NSString) {
Logger.verbose("media cache hit")
guard Thread.isMainThread else {

@ -8,7 +8,6 @@ extension MediaInfoVC {
final class MediaPreviewView: UIView {
private static let cornerRadius: CGFloat = 8
private let mediaCache: NSCache<NSString, AnyObject>
private let attachment: Attachment
private let isOutgoing: Bool
@ -16,7 +15,6 @@ extension MediaInfoVC {
private lazy var mediaView: MediaView = {
let result: MediaView = MediaView.init(
mediaCache: mediaCache,
attachment: attachment,
isOutgoing: isOutgoing
)
@ -42,12 +40,7 @@ extension MediaInfoVC {
// MARK: - Lifecycle
init(
mediaCache: NSCache<NSString, AnyObject>,
attachment: Attachment,
isOutgoing: Bool
) {
self.mediaCache = mediaCache
init(attachment: Attachment, isOutgoing: Bool) {
self.attachment = attachment
self.isOutgoing = isOutgoing

@ -9,13 +9,6 @@ final class MediaInfoVC: BaseVC {
private let attachments: [Attachment]
private let isOutgoing: Bool
// FIXME: Would be good to create a Swift-based cache and replace this
lazy var mediaCache: NSCache<NSString, AnyObject> = {
let result = NSCache<NSString, AnyObject>()
result.countLimit = 40
return result
}()
// MARK: - Initialization
init(attachments: [Attachment], isOutgoing: Bool) {
@ -41,7 +34,6 @@ final class MediaInfoVC: BaseVC {
attachments.forEach {
let mediaPreviewView: MediaPreviewView = MediaPreviewView(
mediaCache: mediaCache,
attachment: $0,
isOutgoing: isOutgoing)
let mediaInfoView: MediaInfoView = MediaInfoView(attachment: $0)

Loading…
Cancel
Save