1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2025-02-06 04:13:28 +01:00

fix: Poll percentages were wrong due to wrong count being used (votes vs voters) (#834)

This commit is contained in:
Marcus Kida 2022-12-31 02:22:00 +01:00 committed by GitHub
parent bb1c003228
commit 6d80df1279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -33,12 +33,12 @@ extension PollOptionView {
.store(in: &disposeBag)
// percentage
Publishers.CombineLatest(
option.poll.publisher(for: \.votesCount),
option.poll.publisher(for: \.votersCount),
option.publisher(for: \.votesCount)
)
.map { pollVotesCount, optionVotesCount -> Double? in
guard pollVotesCount > 0, optionVotesCount >= 0 else { return 0 }
return Double(optionVotesCount) / Double(pollVotesCount)
.map { pollVotersCount, optionVotesCount -> Double? in
guard pollVotersCount > 0, optionVotesCount >= 0 else { return 0 }
return Double(optionVotesCount) / Double(pollVotersCount)
}
.assign(to: \.percentage, on: viewModel)
.store(in: &disposeBag)

View File

@ -175,7 +175,7 @@ extension PollOptionView.ViewModel {
view.voteProgressStripView.setProgress(0.0, animated: false)
case .reveal(let voted, let percentage, let animating):
view.optionPercentageLabel.isHidden = false
view.optionPercentageLabel.text = String(Int(100 * percentage)) + "%"
view.optionPercentageLabel.text = String(Int(round(100 * percentage))) + "%"
view.voteProgressStripView.isHidden = false
view.voteProgressStripView.tintColor = voted ? self.primaryStripProgressViewTintColor : self.secondaryStripProgressViewTintColor
view.voteProgressStripView.setProgress(CGFloat(percentage), animated: animating)