diff --git a/Modules/Images/Sources/Images/ImageDownloader.swift b/Modules/Images/Sources/Images/ImageDownloader.swift index 54cb95c6b..3152e52d5 100644 --- a/Modules/Images/Sources/Images/ImageDownloader.swift +++ b/Modules/Images/Sources/Images/ImageDownloader.swift @@ -62,6 +62,7 @@ extension ImageDownloadError: LocalizedError { private init() { NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidGoToBackground(_:)), name: .appDidGoToBackground, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleDownloadedImageDidChange(_:)), name: .downloadedImageDidChange, object: nil) } @objc func handleAppDidGoToBackground(_ notification: Notification) { @@ -72,6 +73,17 @@ extension ImageDownloadError: LocalizedError { imageCache.removeAllObjects() } + /// Made again even when not in memory, since icons made from the old copy may be cached elsewhere. + @objc func handleDownloadedImageDidChange(_ notification: Notification) { + guard let url = notification.userInfo?[DownloadedImageCache.urlKey] as? String else { + return + } + imageCache.removeObject(forKey: url as NSString) + Task { @MainActor in + await findImage(url, activityOwner: nil, activityKind: nil, activityDetail: nil) + } + } + /// Returns the data if in memory, else makes it from `DownloadedImageCache`’s copy and returns nil. /// Posts `.imageDidBecomeAvailable` when it’s ready. /// Activity log fires only when the fetch reaches the network.