Skip to content

Commit 677ebe7

Browse files
VelikovPetarclaude
andauthored
Show both Leave and Delete options for group channels (#6416)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent c6788a9 commit 677ebe7

11 files changed

Lines changed: 44 additions & 45 deletions

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/channel/info/ChannelInfoOption.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ internal fun ChannelInfoOption(
8282
internal fun ChannelInfoOptionButton(
8383
@DrawableRes icon: Int,
8484
text: String,
85+
destructive: Boolean,
8586
onClick: () -> Unit,
8687
modifier: Modifier = Modifier,
8788
) {
@@ -92,11 +93,13 @@ internal fun ChannelInfoOptionButton(
9293
Icon(
9394
painter = painterResource(icon),
9495
contentDescription = null,
96+
tint = if (destructive) ChatTheme.colors.buttonDestructiveText else ChatTheme.colors.textSecondary,
9597
)
9698
Text(
9799
modifier = Modifier.weight(1f),
98100
text = text,
99101
style = ChatTheme.typography.bodyDefault,
102+
color = if (destructive) ChatTheme.colors.buttonDestructiveText else ChatTheme.colors.textPrimary,
100103
maxLines = 1,
101104
overflow = TextOverflow.Ellipsis,
102105
)
@@ -172,6 +175,7 @@ private fun ChannelInfoOptionButtonPreview() {
172175
ChannelInfoOptionButton(
173176
icon = R.drawable.stream_design_ic_delete,
174177
text = "Delete",
178+
destructive = true,
175179
onClick = {},
176180
)
177181
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/channel/info/ChannelInfoOptionItem.kt

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
package io.getstream.chat.android.compose.ui.channel.info
1818

19-
import androidx.compose.material3.LocalContentColor
2019
import androidx.compose.runtime.Composable
21-
import androidx.compose.runtime.CompositionLocalProvider
2220
import androidx.compose.runtime.getValue
2321
import androidx.compose.runtime.mutableStateOf
2422
import androidx.compose.runtime.remember
@@ -104,23 +102,22 @@ private fun ChannelInfoOptionContent(
104102
}
105103

106104
is ChannelInfoViewState.Content.Option.BlockUser -> {
107-
CompositionLocalProvider(LocalContentColor.provides(ChatTheme.colors.accentError)) {
108-
ChannelInfoOptionButton(
109-
icon = R.drawable.stream_design_ic_no_sign,
110-
text = if (option.isBlocked) {
111-
stringResource(UiCommonR.string.stream_ui_channel_info_option_unblock_user)
105+
ChannelInfoOptionButton(
106+
icon = R.drawable.stream_design_ic_no_sign,
107+
text = if (option.isBlocked) {
108+
stringResource(UiCommonR.string.stream_ui_channel_info_option_unblock_user)
109+
} else {
110+
stringResource(UiCommonR.string.stream_ui_channel_info_option_block_user)
111+
},
112+
destructive = false,
113+
onClick = {
114+
if (option.isBlocked) {
115+
onViewAction(ChannelInfoViewAction.UnblockUserClick)
112116
} else {
113-
stringResource(UiCommonR.string.stream_ui_channel_info_option_block_user)
114-
},
115-
onClick = {
116-
if (option.isBlocked) {
117-
onViewAction(ChannelInfoViewAction.UnblockUserClick)
118-
} else {
119-
onViewAction(ChannelInfoViewAction.BlockUserClick)
120-
}
121-
},
122-
)
123-
}
117+
onViewAction(ChannelInfoViewAction.BlockUserClick)
118+
}
119+
},
120+
)
124121
}
125122

126123
is ChannelInfoViewState.Content.Option.PinnedMessages -> {
@@ -148,31 +145,29 @@ private fun ChannelInfoOptionContent(
148145
}
149146

150147
is ChannelInfoViewState.Content.Option.LeaveChannel -> {
151-
CompositionLocalProvider(LocalContentColor.provides(ChatTheme.colors.accentError)) {
152-
ChannelInfoOptionButton(
153-
icon = R.drawable.stream_design_ic_leave,
154-
text = if (isGroupChannel) {
155-
stringResource(UiCommonR.string.stream_ui_channel_info_option_leave_group)
156-
} else {
157-
stringResource(UiCommonR.string.stream_ui_channel_info_option_leave_conversation)
158-
},
159-
onClick = { onViewAction(ChannelInfoViewAction.LeaveChannelClick) },
160-
)
161-
}
148+
ChannelInfoOptionButton(
149+
icon = R.drawable.stream_design_ic_leave,
150+
text = if (isGroupChannel) {
151+
stringResource(UiCommonR.string.stream_ui_channel_info_option_leave_group)
152+
} else {
153+
stringResource(UiCommonR.string.stream_ui_channel_info_option_leave_conversation)
154+
},
155+
destructive = true,
156+
onClick = { onViewAction(ChannelInfoViewAction.LeaveChannelClick) },
157+
)
162158
}
163159

164160
is ChannelInfoViewState.Content.Option.DeleteChannel -> {
165-
CompositionLocalProvider(LocalContentColor.provides(ChatTheme.colors.accentError)) {
166-
ChannelInfoOptionButton(
167-
icon = R.drawable.stream_design_ic_delete,
168-
text = if (isGroupChannel) {
169-
stringResource(UiCommonR.string.stream_ui_channel_info_option_delete_group)
170-
} else {
171-
stringResource(UiCommonR.string.stream_ui_channel_info_option_delete_conversation)
172-
},
173-
onClick = { onViewAction(ChannelInfoViewAction.DeleteChannelClick) },
174-
)
175-
}
161+
ChannelInfoOptionButton(
162+
icon = R.drawable.stream_design_ic_delete,
163+
text = if (isGroupChannel) {
164+
stringResource(UiCommonR.string.stream_ui_channel_info_option_delete_group)
165+
} else {
166+
stringResource(UiCommonR.string.stream_ui_channel_info_option_delete_conversation)
167+
},
168+
destructive = true,
169+
onClick = { onViewAction(ChannelInfoViewAction.DeleteChannelClick) },
170+
)
176171
}
177172
}
178173
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/channels/ChannelOptions.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ private fun buildGroupChannelActions(
326326
selectedChannel = selectedChannel,
327327
viewModel = viewModel,
328328
),
329-
// Owner pattern: if user can delete, show Delete Group (not Leave)
330-
// Member pattern: if user can leave but not delete, show Leave Group
331-
if (optionVisibility.isLeaveChannelVisible && canLeaveChannel && !canDeleteChannel) {
329+
if (optionVisibility.isLeaveChannelVisible && canLeaveChannel) {
332330
LeaveGroup(
333331
channel = selectedChannel,
334332
label = stringResource(id = R.string.stream_compose_selected_channel_menu_leave_group),
Loading
Loading
Loading

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/channel/info/ChannelInfoViewController.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,11 @@ private fun buildChannelOptionList(
545545
add(ChannelInfoViewState.Content.Option.PinnedMessages)
546546
add(ChannelInfoViewState.Content.Option.MediaAttachments)
547547
add(ChannelInfoViewState.Content.Option.FilesAttachments)
548+
if (channelData.ownCapabilities.contains(ChannelCapabilities.LEAVE_CHANNEL)) {
549+
add(ChannelInfoViewState.Content.Option.LeaveChannel)
550+
}
548551
if (channelData.ownCapabilities.contains(ChannelCapabilities.DELETE_CHANNEL)) {
549552
add(ChannelInfoViewState.Content.Option.DeleteChannel)
550-
} else if (channelData.ownCapabilities.contains(ChannelCapabilities.LEAVE_CHANNEL)) {
551-
add(ChannelInfoViewState.Content.Option.LeaveChannel)
552553
}
553554
}
554555
}

0 commit comments

Comments
 (0)