From a2868739c29ba376b6ea35cecbe00bf4a5d30b27 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 13 May 2022 10:00:11 -0400 Subject: [PATCH] Fix crash when poll voting fails --- Tusker/Views/Poll/StatusPollView.swift | 10 +++++++++- Tusker/Views/Status/BaseStatusTableViewCell.swift | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tusker/Views/Poll/StatusPollView.swift b/Tusker/Views/Poll/StatusPollView.swift index c991e35a..484d7754 100644 --- a/Tusker/Views/Poll/StatusPollView.swift +++ b/Tusker/Views/Poll/StatusPollView.swift @@ -21,6 +21,7 @@ class StatusPollView: UIView { }() weak var mastodonController: MastodonController! + weak var toastableViewController: ToastableViewController? private var statusID: String! private(set) var poll: Poll? @@ -151,7 +152,14 @@ class StatusPollView: UIView { mastodonController.run(request) { (response) in switch response { case let .failure(error): - fatalError("error voting in poll: \(error)") + DispatchQueue.main.async { + self.updateUI(status: self.mastodonController.persistentContainer.status(for: self.statusID)!, poll: self.poll) + + if let toastable = self.toastableViewController { + let config = ToastConfiguration(from: error, with: "Error Voting", in: toastable, retryAction: nil) + toastable.showToast(configuration: config, animated: true) + } + } case let .success(poll, _): let container = self.mastodonController.persistentContainer diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 5a8d8ce4..f25841e5 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -211,6 +211,7 @@ class BaseStatusTableViewCell: UITableViewCell { pollView.isHidden = status.poll == nil pollView.mastodonController = mastodonController + pollView.toastableViewController = delegate?.toastableViewController pollView.updateUI(status: status, poll: status.poll) }