From b94bfca40613620661ad75f5aafda64c406be549 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 13 Sep 2020 13:55:33 -0400 Subject: [PATCH] Fix crash tapping attachments on instance public timelines --- Tusker/Views/Attachments/AttachmentView.swift | 6 +++--- Tusker/Views/Attachments/AttachmentsContainerView.swift | 4 ++-- Tusker/Views/Status/BaseStatusTableViewCell.swift | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 2748c812..f314ac95 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -12,7 +12,7 @@ import Gifu import AVFoundation protocol AttachmentViewDelegate: class { - func attachmentViewGallery(startingAt index: Int) -> UIViewController + func attachmentViewGallery(startingAt index: Int) -> UIViewController? func attachmentViewPresent(_ vc: UIViewController, animated: Bool) } @@ -230,8 +230,8 @@ class AttachmentView: UIImageView, GIFAnimatable { } func showGallery() { - if let delegate = delegate { - let gallery = delegate.attachmentViewGallery(startingAt: index) + if let delegate = delegate, + let gallery = delegate.attachmentViewGallery(startingAt: index) { delegate.attachmentViewPresent(gallery, animated: true) } } diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index c7c33b22..90928ab8 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -384,8 +384,8 @@ class AttachmentsContainerView: UIView { @objc func moreViewTapped() { guard attachments.count > 4 else { return } // the more view shows up in place of the fourth attachemtn view, show tapping it should start at the fourth attachment - if let delegate = delegate { - let gallery = delegate.attachmentViewGallery(startingAt: 3) + if let delegate = delegate, + let gallery = delegate.attachmentViewGallery(startingAt: 3) { delegate.attachmentViewPresent(gallery, animated: true) } } diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index c528bb84..4d83d095 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -366,10 +366,11 @@ class BaseStatusTableViewCell: UITableViewCell { } extension BaseStatusTableViewCell: AttachmentViewDelegate { - func attachmentViewGallery(startingAt index: Int) -> UIViewController { - guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } + func attachmentViewGallery(startingAt index: Int) -> UIViewController? { + guard let delegate = delegate, + let status = mastodonController.persistentContainer.status(for: statusID) else { return nil } let sourceViews = status.attachments.map(attachmentsView.getAttachmentView(for:)) - return delegate!.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) + return delegate.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) } func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {