Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AND-319] Improve poll creation process(compose). #5634

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

VelikovPetar
Copy link
Contributor

@VelikovPetar VelikovPetar commented Feb 14, 2025

🎯 Goal

If a client is using the AttachmentsPicker component in their code, handling the creation of a poll is a bit difficult. They would need to copy-paste the whole logic for transforming the AttachmentPickerPollCreation into a PollConfig, which can be error prone, and is not something that they should know how it is done internally. They currently need to do the following:

AttachmentsPicker(
  onAttachmentPickerAction = { action ->
                        if (action is AttachmentPickerPollCreation) {
                            composerViewModel.createPoll(
                                pollConfig = PollConfig(
                                    name = action.question,
                                    options = action.options.filter { it.title.isNotEmpty() }.map { it.title },
                                    description = action.question,
                                    allowUserSuggestedOptions = action.switches.any { it.key == "allowUserSuggestedOptions" && it.enabled },
                                    votingVisibility = if (action.switches.any { it.key == "votingVisibility" && it.enabled }) {
                                        VotingVisibility.ANONYMOUS
                                    } else {
                                        VotingVisibility.PUBLIC
                                    },
                                    maxVotesAllowed = if (action.switches.any { it.key == "maxVotesAllowed" && it.enabled }) {
                                        action.switches.first { it.key == "maxVotesAllowed" }.pollSwitchInput?.value.toString()
                                            .toInt()
                                    } else {
                                        1
                                    },
                                ),
                            )
                        }
                    },
)

After the change, all they would need to do handle the poll creation properly is:

AttachmentsPicker(
  onAttachmentPickerAction = { action ->
    if (action is AttachmentPickerPollCreation) {
      composerViewModel.createPoll(action.toPollConfig())
    }
  }
)

🚨This is a breaking change. 🚨 However, I think that we must do this, as the code that integrators need to write to make this work currently is an internal logic, and it shouldn't be exposed like this. Additionally, a migration from this to the new API should be very straight forward.

🛠 Implementation details

  • Change the AttachmentPickerPollCreation to hold a prepared PollConfig, instead of question: String, options: List<PollOptionItem> and switches: List<PollSwitchItem>.
  • Make the PollConfig creation login internal in AttachmentsPickerPollUtils

🧪 Testing

  1. Open compose app
  2. Open channel
  3. Open attachments picker and choose poll
  4. The poll should be created successfully as before

Copy link
Contributor

github-actions bot commented Feb 14, 2025

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 3.17 MB 3.17 MB 0.00 MB 🟢
stream-chat-android-offline 3.38 MB 3.38 MB 0.00 MB 🟢
stream-chat-android-ui-components 7.86 MB 7.86 MB 0.00 MB 🟢
stream-chat-android-compose 8.75 MB 8.75 MB 0.00 MB 🟢

@VelikovPetar VelikovPetar marked this pull request as ready for review February 14, 2025 09:22
@VelikovPetar VelikovPetar requested a review from a team as a code owner February 14, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant