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() { func loadAttachment() {
guard AttachmentsContainerView.supportedAttachmentTypes.contains(attachment.kind) else {
fatalError("invalid attachment type")
}
if let hash = attachment.blurHash { if let hash = attachment.blurHash {
AttachmentView.queue.async { [weak self] in AttachmentView.queue.async { [weak self] in
guard let self = self else { return } guard let self = self else { return }
@ -142,8 +138,8 @@ class AttachmentView: GIFImageView {
loadAudio() loadAudio()
case .gifv: case .gifv:
loadGifv() loadGifv()
default: case .unknown:
fatalError("invalid attachment type") 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 @MainActor
private func displayImage() { private func displayImage() {
isGrayscale = Preferences.shared.grayscaleImages isGrayscale = Preferences.shared.grayscaleImages

View File

@ -11,8 +11,6 @@ import Pachyderm
class AttachmentsContainerView: UIView { class AttachmentsContainerView: UIView {
static let supportedAttachmentTypes = [Attachment.Kind.image, .video, .audio, .gifv]
weak var delegate: AttachmentViewDelegate? weak var delegate: AttachmentViewDelegate?
private var attachmentTokens: [AttachmentToken] = [] private var attachmentTokens: [AttachmentToken] = []
@ -70,7 +68,6 @@ class AttachmentsContainerView: UIView {
// MARK: - User Interaface // MARK: - User Interaface
func updateUI(attachments: [Attachment]) { func updateUI(attachments: [Attachment]) {
let attachments = attachments.filter { AttachmentsContainerView.supportedAttachmentTypes.contains($0.kind) }
let newTokens = attachments.map { AttachmentToken(attachment: $0) } let newTokens = attachments.map { AttachmentToken(attachment: $0) }
guard self.attachmentTokens != newTokens else { guard self.attachmentTokens != newTokens else {