From ce7ce3ac92e7711e658eec21ab1b01250c021326 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 14 Nov 2022 21:31:30 -0500 Subject: [PATCH] Fix crash when requests race with own account If the notifications/etc load first, and the table view cells are created, mastodonController.account may still be nil --- Tusker/Views/Poll/StatusPollView.swift | 4 ++-- Tusker/Views/Status/BaseStatusTableViewCell.swift | 2 +- Tusker/Views/Status/StatusCollectionViewCell.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tusker/Views/Poll/StatusPollView.swift b/Tusker/Views/Poll/StatusPollView.swift index 27c38817..a428becf 100644 --- a/Tusker/Views/Poll/StatusPollView.swift +++ b/Tusker/Views/Poll/StatusPollView.swift @@ -95,7 +95,7 @@ class StatusPollView: UIView { guard let poll = poll else { return } // poll.voted is nil if there is no user (e.g., public timeline), in which case the poll also cannot be voted upon - if (poll.voted ?? true) || poll.expired || status.account.id == mastodonController.account.id { + if (poll.voted ?? true) || poll.expired || status.account.id == mastodonController.account?.id { canVote = false } else { canVote = true @@ -126,7 +126,7 @@ class StatusPollView: UIView { if expired { voteButton.disabledTitle = "Expired" } else if poll.voted ?? false { - if status.account.id == mastodonController.account.id { + if status.account.id == mastodonController.account?.id { voteButton.isHidden = true } else { voteButton.disabledTitle = "Voted" diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 3e9122d1..98a32dda 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -170,7 +170,7 @@ class BaseStatusTableViewCell: UITableViewCell { let reblogDisabled: Bool if mastodonController.instanceFeatures.boostToOriginalAudience { // Pleroma allows 'Boost to original audience' for your own private posts - reblogDisabled = status.visibility == .direct || (status.visibility == .private && status.account.id != mastodonController.account.id) + reblogDisabled = status.visibility == .direct || (status.visibility == .private && status.account.id != mastodonController.account?.id) } else { reblogDisabled = status.visibility == .private || status.visibility == .direct } diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 6e46875b..da7f39f9 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -131,7 +131,7 @@ extension StatusCollectionViewCell { } if status.visibility == .direct || status.visibility == .private { if mastodonController.instanceFeatures.boostToOriginalAudience, - status.account.id == mastodonController.account.id { + status.account.id == mastodonController.account?.id { return true } return false