Skip to content

Commit 7203869

Browse files
Port v6 XML poll improvements to develop (#6468)
* Fix MessageListView rotation crash and custom messagesStart not being applied (#6438) * Add configurable character limits and feature toggles for polls (#6435) * Add configurable character limits and feature toggles for polls Introduces PollsConfig to control poll feature availability and enforce character limits on questions and options. Poll features (multiple votes, anonymous voting, suggest options, add comments) can now be hidden or preset with default values through ChatUI.pollsConfig or passed directly to CreatePollDialogFragment. * addressing pr comments * 1. Detekt - Fixed the MaxLineLength violation in PollsConfig.kt:23 by breaking the long comment line 2. Spotless - Applied formatting fixes (added license header to PollFeatureConfig.kt) 3. API Check - Regenerated the API dump file * Update stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/composer/attachment/picker/poll/PollsConfig.kt Co-authored-by: Gianmarco <47775302+gpunto@users.noreply.github.com> * Apply suggestion from @gpunto --------- Co-authored-by: Gianmarco <47775302+gpunto@users.noreply.github.com> * Allow voters to suggest poll options in UI Components (#6439) * Allow voters to suggest poll options in UI Components * Use doAfterTextChanged * Align Compose & XML option name trimming * Apply optionTextLimit to suggest poll option dialog (#6446) * Allow voters to add poll comments in UI Components (#6444) * Allow voters to add poll comments in UI Components * Add missing KDoc and default params * Adjust poll comments commit to develop's APIs - Use UiCommonR for stream_ui_poll_action_view_comments plural - Update StateRegistry imports to client.api.state package * Reformat * Add default value to pollSuggestOptionTextStyle * Init poll suggest option confirm button state from current input * Validate poll text limits at PollsConfig construction * Make SuggestPollOptionDialogFragment internal for consistency * Reapply poll feature visibility on rotation in CreatePollDialogFragment * Add MessageListViewModel test for suggesting a poll option * Add CreatePollViewModel test for config propagation --------- Co-authored-by: Ryan Hurst <106116154+ryanhurststrava@users.noreply.github.com>
1 parent d103fc0 commit 7203869

36 files changed

Lines changed: 1840 additions & 17 deletions

File tree

stream-chat-android-core/src/testFixtures/kotlin/io/getstream/chat/android/Mother.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,22 @@ public fun randomOption(
921921
text = text,
922922
)
923923

924+
public fun randomVote(
925+
id: String = randomString(),
926+
pollId: String = randomString(),
927+
optionId: String = randomString(),
928+
createdAt: Date = randomDate(),
929+
updatedAt: Date = randomDate(),
930+
user: User? = randomUser(),
931+
): Vote = Vote(
932+
id = id,
933+
pollId = pollId,
934+
optionId = optionId,
935+
createdAt = createdAt,
936+
updatedAt = updatedAt,
937+
user = user,
938+
)
939+
924940
public fun randomPollOption(
925941
id: String? = randomString(),
926942
text: String = randomString(),

stream-chat-android-ui-common/api/stream-chat-android-ui-common.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ public final class io/getstream/chat/android/ui/common/feature/messages/list/Mes
847847
public fun <init> (Ljava/lang/String;Lio/getstream/chat/android/ui/common/helper/ClipboardHandler;ZLjava/lang/String;Ljava/lang/String;ILio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/client/setup/state/ClientState;Lkotlinx/coroutines/flow/StateFlow;ZLio/getstream/chat/android/ui/common/state/messages/list/MessageFooterVisibility;ZLio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/MessagePositionHandler;ZZ)V
848848
public synthetic fun <init> (Ljava/lang/String;Lio/getstream/chat/android/ui/common/helper/ClipboardHandler;ZLjava/lang/String;Ljava/lang/String;ILio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/client/setup/state/ClientState;Lkotlinx/coroutines/flow/StateFlow;ZLio/getstream/chat/android/ui/common/state/messages/list/MessageFooterVisibility;ZLio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/MessagePositionHandler;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
849849
public final fun addPollOption (Lio/getstream/chat/android/models/Poll;Ljava/lang/String;)V
850+
public final fun addPollOption (Ljava/lang/String;Ljava/lang/String;)V
850851
public final fun banUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)V
851852
public static synthetic fun banUser$default (Lio/getstream/chat/android/ui/common/feature/messages/list/MessageListController;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)V
852853
public final fun blockUser (Ljava/lang/String;)V

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,8 +2433,18 @@ public class MessageListController(
24332433
* @param option The text of the new option to be added.
24342434
*/
24352435
public fun addPollOption(poll: Poll, option: String) {
2436+
addPollOption(pollId = poll.id, option = option)
2437+
}
2438+
2439+
/**
2440+
* Creates a new poll option for the poll identified by [pollId].
2441+
*
2442+
* @param pollId The id of the poll to which the option will be added.
2443+
* @param option The text of the new option to be added.
2444+
*/
2445+
public fun addPollOption(pollId: String, option: String) {
24362446
scope.launch {
2437-
chatClient.createPollOption(poll.id, PollOption(text = option)).await()
2447+
chatClient.createPollOption(pollId, PollOption(text = option)).await()
24382448
}
24392449
}
24402450

stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListControllerTests.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import io.getstream.chat.android.models.Member
3939
import io.getstream.chat.android.models.Message
4040
import io.getstream.chat.android.models.MessageType
4141
import io.getstream.chat.android.models.MessagesState
42+
import io.getstream.chat.android.models.PollOption
4243
import io.getstream.chat.android.models.Reaction
4344
import io.getstream.chat.android.models.SyncStatus
4445
import io.getstream.chat.android.models.TypingEvent
@@ -53,6 +54,7 @@ import io.getstream.chat.android.randomMembers
5354
import io.getstream.chat.android.randomMessage
5455
import io.getstream.chat.android.randomMessageList
5556
import io.getstream.chat.android.randomOption
57+
import io.getstream.chat.android.randomPoll
5658
import io.getstream.chat.android.randomPollVote
5759
import io.getstream.chat.android.randomReaction
5860
import io.getstream.chat.android.randomString
@@ -1001,6 +1003,21 @@ internal class MessageListControllerTests {
10011003
controller.errorEvents.value `should be equal to` expectedEvent
10021004
}
10031005

1006+
@Test
1007+
fun `When calling addPollOption, ChatClient createPollOption is invoked`() = runTest {
1008+
val poll = randomPoll()
1009+
val optionText = randomString()
1010+
val chatClient = mock<ChatClient>()
1011+
val controller = Fixture(chatClient = chatClient)
1012+
.givenCurrentUser()
1013+
.givenChannelState(messagesState = MutableStateFlow(emptyList()))
1014+
.givenCreatePollOption(callFrom { PollOption(text = optionText) })
1015+
.get()
1016+
controller.addPollOption(poll = poll, option = optionText)
1017+
1018+
verify(chatClient).createPollOption(poll.id, PollOption(text = optionText))
1019+
}
1020+
10041021
@Test
10051022
fun `When toggleOriginalText, the message translation is toggled`() = runTest {
10061023
val messageId = randomString()
@@ -1344,6 +1361,10 @@ internal class MessageListControllerTests {
13441361
whenever(chatClient.removePollVote(any(), any(), voteId = any())) doReturn vote
13451362
}
13461363

1364+
fun givenCreatePollOption(option: Call<PollOption>) = apply {
1365+
whenever(chatClient.createPollOption(any(), any())) doReturn option
1366+
}
1367+
13471368
fun givenSendReaction(reaction: Call<Reaction>) = apply {
13481369
whenever(chatClient.sendReaction(any(), any(), any(), any())) doReturn reaction
13491370
}

0 commit comments

Comments
 (0)