From e745d78d67b862f44c4bf62998eece29465ca4f5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 22 May 2021 11:30:40 -0400 Subject: [PATCH] Fix polls not being collapsed inside CW Closes #119 --- Tusker/Views/Poll/StatusPollView.swift | 9 ++++++--- Tusker/Views/Status/BaseStatusTableViewCell.swift | 11 ++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tusker/Views/Poll/StatusPollView.swift b/Tusker/Views/Poll/StatusPollView.swift index dd5d3bc2..99b87424 100644 --- a/Tusker/Views/Poll/StatusPollView.swift +++ b/Tusker/Views/Poll/StatusPollView.swift @@ -23,7 +23,7 @@ class StatusPollView: UIView { weak var mastodonController: MastodonController! private var statusID: String! - private var poll: Poll! + private(set) var poll: Poll? private var optionsView: PollOptionsView! private var voteButton: UIButton! @@ -76,12 +76,15 @@ class StatusPollView: UIView { ]) } - func updateUI(status: StatusMO, poll: Poll) { + func updateUI(status: StatusMO, poll: Poll?) { self.statusID = status.id self.poll = poll + // remove old options options.forEach { $0.removeFromSuperview() } + 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 { canVote = false @@ -138,7 +141,7 @@ class StatusPollView: UIView { UIImpactFeedbackGenerator(style: .medium).impactOccurred() - let request = Poll.vote(poll.id, choices: optionsView.checkedOptionIndices) + let request = Poll.vote(poll!.id, choices: optionsView.checkedOptionIndices) mastodonController.run(request) { (response) in switch response { case let .failure(error): diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index ba84e786..70550d09 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -215,13 +215,9 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { // keep menu in sync with changed states e.g. bookmarked, muted moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: actionsForStatus(status, sourceView: moreButton)) - if let poll = status.poll { - pollView.isHidden = false - pollView.mastodonController = mastodonController - pollView.updateUI(status: status, poll: poll) - } else { - pollView.isHidden = true - } + pollView.isHidden = status.poll == nil + pollView.mastodonController = mastodonController + pollView.updateUI(status: status, poll: status.poll) } func updateUI(account: AccountMO) { @@ -359,6 +355,7 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { contentTextView.isHidden = collapsed cardView.isHidden = cardView.card == nil || collapsed attachmentsView.isHidden = attachmentsView.attachments.count == 0 || collapsed + pollView.isHidden = pollView.poll == nil || collapsed let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")!