Skip to content

Commit

Permalink
Avoid showing duplicate poll options
Browse files Browse the repository at this point in the history
This is an invalid state, but currently it is possible to create a valid poll (no identical options) and later edit it so that two or more options contain identical strings. Bug (#33707) has been filed for the mastodon repository.

Fixes #1332 [BUG] Mastodon app crashes when a poll with identical answers reaches the screen
  • Loading branch information
whattherestimefor committed Jan 23, 2025
1 parent f45ccac commit a7f82c4
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ extension StatusView {
guard let poll = statusEdit.poll else { return }

let pollItems = poll.options.map { PollItem.history(option: $0) }
self.viewModel.pollItems = pollItems
self.viewModel.pollItems = pollItems.removingDuplicates()
pollStatusStackView.isHidden = true

var _snapshot = NSDiffableDataSourceSnapshot<PollSection, PollItem>()
Expand All @@ -506,7 +506,7 @@ extension StatusView {

let options = poll.options
let items: [PollItem] = options.map { .option(record: $0) }
self.viewModel.pollItems = items
self.viewModel.pollItems = items.removingDuplicates()

let hasSelectedOption = options.contains(where: { $0.isSelected == true })
viewModel.isVoteButtonEnabled = hasSelectedOption
Expand Down Expand Up @@ -551,7 +551,7 @@ extension StatusView {

let options = poll.options
let items: [PollItem] = options.map { .pollOption($0) }
self.viewModel.pollItems = items
self.viewModel.pollItems = items.removingDuplicates()

viewModel.isVoteButtonEnabled = !viewModel.selectedPollItems.isEmpty

Expand Down

0 comments on commit a7f82c4

Please sign in to comment.