Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ private fun buildDmChannelActions(
selectedChannel = selectedChannel,
viewModel = viewModel,
),
buildDmPinAction(
canPinChannel = optionVisibility.isPinChannelVisible,
selectedChannel = selectedChannel,
viewModel = viewModel,
),
buildDmArchiveAction(
canArchiveChannel = optionVisibility.isArchiveChannelVisible,
selectedChannel = selectedChannel,
Expand Down Expand Up @@ -321,7 +326,7 @@ private fun buildGroupChannelActions(
selectedChannel = selectedChannel,
viewModel = viewModel,
),
buildPinAction(
buildGroupPinAction(
canPinChannel = optionVisibility.isPinChannelVisible,
selectedChannel = selectedChannel,
viewModel = viewModel,
Expand Down Expand Up @@ -379,23 +384,47 @@ private fun buildGroupChannelActions(
}

/**
* Builds the pin action for the channel, based on the current state.
* Builds the pin action for DM channels.
*/
@Composable
private fun buildDmPinAction(
canPinChannel: Boolean,
selectedChannel: Channel,
viewModel: ChannelListViewModel,
): ChannelAction? = when (selectedChannel.isPinned().takeIf { canPinChannel }) {
false -> PinChannel(
channel = selectedChannel,
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_chat),
onAction = { viewModel.pinChannel(selectedChannel) },
)

true -> UnpinChannel(
channel = selectedChannel,
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_chat),
onAction = { viewModel.unpinChannel(selectedChannel) },
)

null -> null
}

/**
* Builds the pin action for group channels.
*/
@Composable
private fun buildPinAction(
private fun buildGroupPinAction(
canPinChannel: Boolean,
selectedChannel: Channel,
viewModel: ChannelListViewModel,
): ChannelAction? = when (selectedChannel.isPinned().takeIf { canPinChannel }) {
false -> PinChannel(
channel = selectedChannel,
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_channel),
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_group),
onAction = { viewModel.pinChannel(selectedChannel) },
)

true -> UnpinChannel(
channel = selectedChannel,
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_channel),
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_group),
onAction = { viewModel.unpinChannel(selectedChannel) },
)

Expand Down
6 changes: 4 additions & 2 deletions stream-chat-android-compose/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
<!-- Selected Channel Menu -->
<string name="stream_compose_selected_channel_menu_view_info">View info</string>
<string name="stream_compose_selected_channel_menu_leave_group">Leave group</string>
<string name="stream_compose_selected_channel_menu_pin_channel">Pin Channel</string>
<string name="stream_compose_selected_channel_menu_unpin_channel">Unpin Channel</string>
<string name="stream_compose_selected_channel_menu_pin_chat">Pin Chat</string>
<string name="stream_compose_selected_channel_menu_unpin_chat">Unpin Chat</string>
<string name="stream_compose_selected_channel_menu_pin_group">Pin Group</string>
<string name="stream_compose_selected_channel_menu_unpin_group">Unpin Group</string>
<string name="stream_compose_selected_channel_menu_leave_group_confirmation_title">Leave group</string>
<string name="stream_compose_selected_channel_menu_leave_group_confirmation_message">Do you want to leave the %1$s group?</string>
<string name="stream_compose_selected_channel_menu_mute_group">Mute Group</string>
Expand Down
Loading