Skip to content

Commit

Permalink
[PBE-5908] Discrepancy in build default channel options state logic b…
Browse files Browse the repository at this point in the history
…etween platforms (#5396)

* Check chanel mute capability when building the channel options state

* Fix detekt rule break by extracting a method

* Spotless

---------

Co-authored-by: Kanat Kiialbaev <[email protected]>
  • Loading branch information
aleksandar-apostolov and kanat authored Sep 5, 2024
1 parent 973e800 commit 5d0a399
Showing 1 changed file with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public fun buildDefaultChannelOptionsState(
): List<ChannelOptionState> {
val canLeaveChannel = ownCapabilities.contains(ChannelCapabilities.LEAVE_CHANNEL)
val canDeleteChannel = ownCapabilities.contains(ChannelCapabilities.DELETE_CHANNEL)
val canMuteChannel = ownCapabilities.contains(ChannelCapabilities.MUTE_CHANNEL)

return listOfNotNull(
ChannelOptionState(
Expand All @@ -130,23 +131,7 @@ public fun buildDefaultChannelOptionsState(
} else {
null
},
if (isMuted) {
ChannelOptionState(
title = stringResource(id = R.string.stream_compose_selected_channel_menu_unmute_channel),
titleColor = ChatTheme.colors.textHighEmphasis,
iconPainter = painterResource(id = R.drawable.stream_compose_ic_unmute),
iconColor = ChatTheme.colors.textLowEmphasis,
action = UnmuteChannel(selectedChannel),
)
} else {
ChannelOptionState(
title = stringResource(id = R.string.stream_compose_selected_channel_menu_mute_channel),
titleColor = ChatTheme.colors.textHighEmphasis,
iconPainter = painterResource(id = R.drawable.stream_compose_ic_mute),
iconColor = ChatTheme.colors.textLowEmphasis,
action = MuteChannel(selectedChannel),
)
},
buildMuteOption(canMuteChannel, isMuted, selectedChannel),
if (canDeleteChannel) {
ChannelOptionState(
title = stringResource(id = R.string.stream_compose_selected_channel_menu_delete_conversation),
Expand All @@ -168,6 +153,37 @@ public fun buildDefaultChannelOptionsState(
)
}

@Composable
private fun buildMuteOption(
canMuteChannel: Boolean,
isMuted: Boolean,
selectedChannel: Channel,
) = if (canMuteChannel) {
val uiData = when (isMuted) {
true -> Triple(
R.string.stream_compose_selected_channel_menu_unmute_channel,
R.drawable.stream_compose_ic_unmute,
UnmuteChannel(selectedChannel),
)

false -> Triple(
R.string.stream_compose_selected_channel_menu_mute_channel,
R.drawable.stream_compose_ic_mute,
MuteChannel(selectedChannel),
)
}

ChannelOptionState(
title = stringResource(id = uiData.first),
titleColor = ChatTheme.colors.textHighEmphasis,
iconPainter = painterResource(id = uiData.second),
iconColor = ChatTheme.colors.textLowEmphasis,
action = uiData.third,
)
} else {
null
}

/**
* Preview of [ChannelOptions].
*
Expand Down

0 comments on commit 5d0a399

Please sign in to comment.