Show unknown attachments

Closes #47
This commit is contained in:
Shadowfacts 2023-05-16 11:40:59 -04:00
parent f2f6eb81f7
commit 8db5649cd5
2 changed files with 21 additions and 9 deletions

View File

@ -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

View File

@ -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 {