1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2025-01-23 14:10:26 +01:00

Fix voted indicator on poll missing (IOS-274) (#1301)

# Rationale

Fixes #1289
This commit is contained in:
Marcus Kida 2024-05-22 16:31:50 +02:00 committed by GitHub
commit e2c1cf301a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -144,7 +144,6 @@ extension StatusSection {
authContext: AuthContext,
statusView: StatusView
) {
let managedObjectContext = context.managedObjectContext
statusView.pollTableViewDiffableDataSource = UITableViewDiffableDataSource<PollSection, PollItem>(tableView: statusView.pollTableView) { tableView, indexPath, item in
switch item {
case .history:

View File

@ -56,14 +56,17 @@ public final class MastodonPollOption: ObservableObject, Hashable {
@Published public var voted: Bool?
public private(set) var optionIndex: Int? = nil
public init(poll: MastodonPoll, option: Mastodon.Entity.Poll.Option, isSelected: Bool = false) {
public init(poll: MastodonPoll, option: Mastodon.Entity.Poll.Option) {
self.poll = poll
self.option = option
self.isSelected = isSelected
self.votesCount = option.votesCount
self.title = option.title
self.optionIndex = poll.options.firstIndex(of: self)
self.isSelected = {
guard let ownVotes = poll.entity.ownVotes else { return false }
guard let index = poll.entity.options.firstIndex(of: option) else { return false }
return ownVotes.contains(index)
}()
self.voted = {
guard let ownVotes = poll.entity.ownVotes else { return false }
guard let optionIndex else { return false }