From c4b8f129d70e3256f16b359c7b7b189080fc6400 Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 15 Jul 2022 03:29:04 +0800 Subject: [PATCH] fix: empty banner could be preview issue --- .../Protocol/Provider/DataSourceFacade+Media.swift | 10 +++++++++- .../Scene/MediaPreview/MediaPreviewViewModel.swift | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift index 329a7f39c..3e767f2d3 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Media.swift @@ -5,6 +5,7 @@ // Created by MainasuK on 2022-1-26. // +import os.log import UIKit import CoreDataStack import MastodonUI @@ -153,6 +154,8 @@ extension DataSourceFacade { user: ManagedObjectRecord, previewContext: ImagePreviewContext ) async throws { + let logger = Logger(subsystem: "DataSourceFacade", category: "Media") + let managedObjectContext = dependency.context.managedObjectContext var _avatarAssetURL: String? @@ -216,13 +219,18 @@ extension DataSourceFacade { thumbnail: thumbnail )) case .profileBanner: - return .profileAvatar(.init( + return .profileBanner(.init( assetURL: _headerAssetURL, thumbnail: thumbnail )) } }() + guard mediaPreviewItem.isAssetURLValid else { + logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): discard preview due to assetURL invalid") + return + } + coordinateToMediaPreviewScene( dependency: dependency, mediaPreviewItem: mediaPreviewItem, diff --git a/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift b/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift index 5912e559a..2fbc5f0ac 100644 --- a/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift +++ b/Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift @@ -116,6 +116,19 @@ extension MediaPreviewViewModel { case profileAvatar(ProfileAvatarPreviewContext) case profileBanner(ProfileBannerPreviewContext) // case local(LocalImagePreviewMeta) + + var isAssetURLValid: Bool { + switch self { + case .attachment: + return true // default valid + case .profileAvatar: + return true // default valid + case .profileBanner(let item): + guard let assertURL = item.assetURL else { return false } + guard !assertURL.hasSuffix("missing.png") else { return false } + return true + } + } } struct AttachmentPreviewContext {