Fix polls not being collapsed inside CW

Closes #119
This commit is contained in:
Shadowfacts 2021-05-22 11:30:40 -04:00
parent 4c9d5e8465
commit e745d78d67
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ class StatusPollView: UIView {
weak var mastodonController: MastodonController! weak var mastodonController: MastodonController!
private var statusID: String! private var statusID: String!
private var poll: Poll! private(set) var poll: Poll?
private var optionsView: PollOptionsView! private var optionsView: PollOptionsView!
private var voteButton: UIButton! 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.statusID = status.id
self.poll = poll self.poll = poll
// remove old options
options.forEach { $0.removeFromSuperview() } 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 // 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 canVote = false
@ -138,7 +141,7 @@ class StatusPollView: UIView {
UIImpactFeedbackGenerator(style: .medium).impactOccurred() 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 mastodonController.run(request) { (response) in
switch response { switch response {
case let .failure(error): case let .failure(error):

View File

@ -215,13 +215,9 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider {
// keep menu in sync with changed states e.g. bookmarked, muted // 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)) moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: actionsForStatus(status, sourceView: moreButton))
if let poll = status.poll { pollView.isHidden = status.poll == nil
pollView.isHidden = false pollView.mastodonController = mastodonController
pollView.mastodonController = mastodonController pollView.updateUI(status: status, poll: status.poll)
pollView.updateUI(status: status, poll: poll)
} else {
pollView.isHidden = true
}
} }
func updateUI(account: AccountMO) { func updateUI(account: AccountMO) {
@ -359,6 +355,7 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider {
contentTextView.isHidden = collapsed contentTextView.isHidden = collapsed
cardView.isHidden = cardView.card == nil || collapsed cardView.isHidden = cardView.card == nil || collapsed
attachmentsView.isHidden = attachmentsView.attachments.count == 0 || collapsed attachmentsView.isHidden = attachmentsView.attachments.count == 0 || collapsed
pollView.isHidden = pollView.poll == nil || collapsed
let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")! let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")!