Fix crash when poll voting fails

This commit is contained in:
Shadowfacts 2022-05-13 10:00:11 -04:00
parent 2f75510889
commit a2868739c2
2 changed files with 10 additions and 1 deletions

View File

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

View File

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