Fix voted indicator on poll missing (IOS-274)

This commit is contained in:
Marcus Kida 2024-05-22 13:45:22 +02:00
parent f1aebc4220
commit 478cffa5b8
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
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 }