From 8db5649cd51135bc2a661383a515764fef2f4be8 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 16 May 2023 11:40:59 -0400 Subject: [PATCH] Show unknown attachments Closes #47 --- Tusker/Views/Attachments/AttachmentView.swift | 27 ++++++++++++++----- .../AttachmentsContainerView.swift | 3 --- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 01ef3479..fa1b657b 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -107,10 +107,6 @@ class AttachmentView: GIFImageView { } func loadAttachment() { - guard AttachmentsContainerView.supportedAttachmentTypes.contains(attachment.kind) else { - fatalError("invalid attachment type") - } - if let hash = attachment.blurHash { AttachmentView.queue.async { [weak self] in guard let self = self else { return } @@ -142,8 +138,8 @@ class AttachmentView: GIFImageView { loadAudio() case .gifv: loadGifv() - default: - fatalError("invalid attachment type") + case .unknown: + createUnknownLabel() } } @@ -301,6 +297,25 @@ class AttachmentView: GIFImageView { ]) } + func createUnknownLabel() { + backgroundColor = .appSecondaryBackground + let label = UILabel() + label.text = "Unknown Attachment Type" + label.numberOfLines = 0 + label.textAlignment = .center + label.textColor = .secondaryLabel + label.font = .preferredFont(forTextStyle: .body) + label.adjustsFontForContentSizeCategory = true + label.translatesAutoresizingMaskIntoConstraints = false + addSubview(label) + NSLayoutConstraint.activate([ + label.leadingAnchor.constraint(equalTo: leadingAnchor), + label.trailingAnchor.constraint(equalTo: trailingAnchor), + label.topAnchor.constraint(equalTo: topAnchor), + label.bottomAnchor.constraint(equalTo: bottomAnchor), + ]) + } + @MainActor private func displayImage() { isGrayscale = Preferences.shared.grayscaleImages diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 77d72d66..662e38f6 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -10,8 +10,6 @@ import UIKit import Pachyderm class AttachmentsContainerView: UIView { - - static let supportedAttachmentTypes = [Attachment.Kind.image, .video, .audio, .gifv] weak var delegate: AttachmentViewDelegate? @@ -70,7 +68,6 @@ class AttachmentsContainerView: UIView { // MARK: - User Interaface func updateUI(attachments: [Attachment]) { - let attachments = attachments.filter { AttachmentsContainerView.supportedAttachmentTypes.contains($0.kind) } let newTokens = attachments.map { AttachmentToken(attachment: $0) } guard self.attachmentTokens != newTokens else {