forked from shadowfacts/Tusker
parent
4c9d5e8465
commit
e745d78d67
|
@ -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):
|
||||
|
|
|
@ -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.isHidden = status.poll == nil
|
||||
pollView.mastodonController = mastodonController
|
||||
pollView.updateUI(status: status, poll: poll)
|
||||
} else {
|
||||
pollView.isHidden = true
|
||||
}
|
||||
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")!
|
||||
|
||||
|
|
Loading…
Reference in New Issue