Enforce poll maxVotesAllowed on the XML voting side#6502
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
SDK Size Comparison 📏
|
WalkthroughIntroduces a ChangesPoll Vote Eligibility Centralization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/list/internal/poll/AllPollOptionsDialogFragment.kt`:
- Around line 214-220: In the AllPollOptionsDialogFragment, the vote mutation
logic for casting or removing poll votes does not guard against closed polls.
Add an early return guard immediately after retrieving the poll object (after
`val poll = pollState.value ?: return@launch`) that checks if the poll is closed
and returns early from the coroutine using `if (poll.closed) return@launch`.
This prevents closed polls from triggering castPollVote or removePollVote API
calls even though the option rows remain clickable in the UI.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f263849d-4c0f-4cba-9a0b-5986bc84709d
📒 Files selected for processing (7)
stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.ktstream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollMoreOptionsDialog.ktstream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollOptionVotingRow.ktstream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/utils/extensions/Poll.ktstream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/utils/extensions/PollExtensionsTest.ktstream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/list/adapter/view/internal/PollView.ktstream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/list/internal/poll/AllPollOptionsDialogFragment.kt
💤 Files with no reviewable changes (2)
- stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.kt
- stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollMoreOptionsDialog.kt
|


Goal
The XML UI SDK never checks
Poll.maxVotesAllowedwhen the user taps an option to vote. Both the inline poll on the message (PollView) and the "see all options" bottom sheet (AllPollOptionsDialogFragment) callChatClient.castPollVoteunconditionally, so a user can vote past the configured limit.Closes AND-1237
Implementation
Poll.canCastVote()extension inui-common.PollView,AllPollOptionsDialogFragment) skip the cast whencanCastVote()is false. Un-voting always goes through.PollOptionVotingRow'scheckedCountparameter with a directpoll.canCastVote()call. Both callers passedpoll.ownVotes.size, so no behaviour change.Testing
PollExtensionsTest: three new cases covercanCastVote()formaxVotesAllowed = null,ownVotes.size < maxVotesAllowed, andownVotes.size == maxVotesAllowed.maxVotesAllowed = 1,2, and unlimited in both XML and Compose. Verified that tapping a third option in a 2-vote poll is now a no-op (XML inline + "see all options" sheet, and Compose).Summary by CodeRabbit
Bug Fixes
Tests