1616
1717package io.getstream.chat.android.compose.ui.channels.list
1818
19- import android.content.res.Resources
2019import androidx.compose.runtime.Composable
2120import androidx.compose.runtime.remember
2221import androidx.compose.runtime.rememberCoroutineScope
2322import androidx.compose.runtime.rememberUpdatedState
24- import androidx.compose.ui.platform.LocalContext
2523import androidx.compose.ui.platform.LocalResources
2624import androidx.compose.ui.res.painterResource
27- import io.getstream.chat.android.client.extensions.isPinned
2825import io.getstream.chat.android.compose.R
2926import io.getstream.chat.android.compose.state.channels.list.ItemState
27+ import io.getstream.chat.android.compose.ui.theme.ChatTheme
3028import io.getstream.chat.android.models.Channel
3129import io.getstream.chat.android.models.ChannelCapabilities
3230import io.getstream.chat.android.ui.common.state.channels.actions.ChannelAction
3331import io.getstream.chat.android.ui.common.state.channels.actions.MuteChannel
34- import io.getstream.chat.android.ui.common.state.channels.actions.PinChannel
3532import io.getstream.chat.android.ui.common.state.channels.actions.UnmuteChannel
36- import io.getstream.chat.android.ui.common.state.channels.actions.UnpinChannel
3733import kotlinx.coroutines.launch
3834
3935/* *
4036 * Default swipe actions for a channel list item.
4137 *
4238 * Shows two actions:
4339 * - **More** (gray, left): Opens the channel options bottom sheet.
44- * - **Primary action** (blue, right): Mute with fallback to Pin .
40+ * - **Primary action** (blue, right): Mute/Unmute channel .
4541 *
4642 * Each action is a self-executing [ChannelAction] that invokes its handler via
4743 * [LocalSwipeActionHandler].
@@ -59,7 +55,7 @@ public fun DefaultChannelSwipeActions(channelItem: ItemState.ChannelItemState) {
5955 if (moreHandler != null ) {
6056 SwipeActionItem (
6157 icon = painterResource(R .drawable.stream_compose_ic_more_options),
62- label = LocalContext .current.resources .getString(R .string.stream_compose_swipe_action_more),
58+ label = LocalResources .current.getString(R .string.stream_compose_swipe_action_more),
6359 onClick = {
6460 scope.launch { coordinator?.closeAll() }
6561 moreHandler(channel)
@@ -77,60 +73,38 @@ public fun DefaultChannelSwipeActions(channelItem: ItemState.ChannelItemState) {
7773 SwipeActionItem (
7874 icon = painterResource(primaryAction.icon),
7975 label = primaryAction.label,
80- onClick = { primaryAction.onAction() } ,
76+ onClick = primaryAction.onAction,
8177 style = SwipeActionStyle .Primary ,
8278 )
8379 }
8480}
8581
8682/* *
87- * Resolves and remembers the primary swipe action based on channel capabilities .
83+ * Resolves and remembers the primary swipe action (mute/unmute channel) .
8884 *
89- * Priority: Mute → Pin.
90- *
91- * Pin is always available (membership operation, no capability gate).
92- * Mute requires [ChannelCapabilities.MUTE_CHANNEL].
85+ * Requires [ChannelCapabilities.MUTE_CHANNEL] and `isMuteChannelVisible` in the theme.
9386 */
9487@Composable
9588private fun rememberPrimarySwipeAction (
9689 channel : Channel ,
9790 isMuted : Boolean ,
9891 handler : (ChannelAction ) -> Unit ,
99- ): ChannelAction {
92+ ): ChannelAction ? {
10093 val resources = LocalResources .current
10194 val handlerState = rememberUpdatedState(handler)
102- val isPinned = channel.isPinned()
103- val canMute = channel.ownCapabilities.contains(ChannelCapabilities .MUTE_CHANNEL )
95+ val canMute = ChatTheme .channelOptionsTheme.optionVisibility.isMuteChannelVisible &&
96+ channel.ownCapabilities.contains(ChannelCapabilities .MUTE_CHANNEL )
10497
105- return remember(channel.cid, isMuted, isPinned, canMute) {
98+ return remember(channel.cid, isMuted, canMute) {
99+ if (! canMute) return @remember null
106100 var resolved: ChannelAction ? = null
107101 val onAction: () -> Unit = { resolved?.let { handlerState.value(it) } }
108102
109- resolved = muteAction(channel, isMuted, canMute, resources, onAction)
110- ? : pinAction(channel, isPinned, resources, onAction)
103+ resolved = if (isMuted) {
104+ UnmuteChannel (channel, resources.getString(R .string.stream_compose_swipe_action_unmute), onAction)
105+ } else {
106+ MuteChannel (channel, resources.getString(R .string.stream_compose_swipe_action_mute), onAction)
107+ }
111108 resolved
112109 }
113110}
114-
115- private fun muteAction (
116- channel : Channel ,
117- isMuted : Boolean ,
118- canMute : Boolean ,
119- resources : Resources ,
120- onAction : () -> Unit ,
121- ): ChannelAction ? = when {
122- ! canMute -> null
123- isMuted -> UnmuteChannel (channel, resources.getString(R .string.stream_compose_swipe_action_unmute), onAction)
124- else -> MuteChannel (channel, resources.getString(R .string.stream_compose_swipe_action_mute), onAction)
125- }
126-
127- private fun pinAction (
128- channel : Channel ,
129- isPinned : Boolean ,
130- resources : Resources ,
131- onAction : () -> Unit ,
132- ): ChannelAction = if (isPinned) {
133- UnpinChannel (channel, resources.getString(R .string.stream_compose_swipe_action_unpin), onAction)
134- } else {
135- PinChannel (channel, resources.getString(R .string.stream_compose_swipe_action_pin), onAction)
136- }
0 commit comments