Skip to content

Commit 21e57a6

Browse files
committed
Fix checkbox not marked when current user voted from another device
1 parent 4883a85 commit 21e57a6

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/Polls/PollAttachmentViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public class PollAttachmentViewModel: ObservableObject, PollControllerDelegate {
198198

199199
/// True, if the current user has voted for the specified option, otherwise false.
200200
public func optionVotedByCurrentUser(_ option: PollOption) -> Bool {
201-
currentUserVote(for: option) != nil
201+
poll.hasCurrentUserVoted(for: option)
202202
}
203203

204204
/// Adds a new option to the poll.

StreamChatSwiftUITests/Tests/ChatChannel/PollAttachmentViewModel_Tests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ final class PollAttachmentViewModel_Tests: StreamChatTestCase {
9292

9393
func test_pollAttachmentViewModel_optionVotedByCurrentUser() {
9494
// Given
95+
let vote = makePollVote()
9596
let pollController = makePollController()
9697
let viewModel = PollAttachmentViewModel(
9798
message: .mock(),
98-
poll: .unique,
99+
poll: .mock(ownVotes: [vote]),
99100
pollController: pollController
100101
)
101-
let vote = makePollVote()
102102
let option = PollOption(id: vote.optionId!, text: "")
103-
viewModel.currentUserVotes = [vote]
104103

105104
// When
106105
let optionVoted = viewModel.optionVotedByCurrentUser(option)

0 commit comments

Comments
 (0)