Skip to content

Commit fcb183b

Browse files
gpuntoVelikovPetar
andauthored
Add ability to pin DM channels (#6313)
Co-authored-by: Petar Velikov <petarvelikov95@gmail.com>
1 parent 3a5d88c commit fcb183b

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ private fun buildDmChannelActions(
181181
selectedChannel = selectedChannel,
182182
viewModel = viewModel,
183183
),
184+
buildDmPinAction(
185+
canPinChannel = optionVisibility.isPinChannelVisible,
186+
selectedChannel = selectedChannel,
187+
viewModel = viewModel,
188+
),
184189
buildDmArchiveAction(
185190
canArchiveChannel = optionVisibility.isArchiveChannelVisible,
186191
selectedChannel = selectedChannel,
@@ -321,7 +326,7 @@ private fun buildGroupChannelActions(
321326
selectedChannel = selectedChannel,
322327
viewModel = viewModel,
323328
),
324-
buildPinAction(
329+
buildGroupPinAction(
325330
canPinChannel = optionVisibility.isPinChannelVisible,
326331
selectedChannel = selectedChannel,
327332
viewModel = viewModel,
@@ -379,23 +384,47 @@ private fun buildGroupChannelActions(
379384
}
380385

381386
/**
382-
* Builds the pin action for the channel, based on the current state.
387+
* Builds the pin action for DM channels.
388+
*/
389+
@Composable
390+
private fun buildDmPinAction(
391+
canPinChannel: Boolean,
392+
selectedChannel: Channel,
393+
viewModel: ChannelListViewModel,
394+
): ChannelAction? = when (selectedChannel.isPinned().takeIf { canPinChannel }) {
395+
false -> PinChannel(
396+
channel = selectedChannel,
397+
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_chat),
398+
onAction = { viewModel.pinChannel(selectedChannel) },
399+
)
400+
401+
true -> UnpinChannel(
402+
channel = selectedChannel,
403+
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_chat),
404+
onAction = { viewModel.unpinChannel(selectedChannel) },
405+
)
406+
407+
null -> null
408+
}
409+
410+
/**
411+
* Builds the pin action for group channels.
383412
*/
384413
@Composable
385-
private fun buildPinAction(
414+
private fun buildGroupPinAction(
386415
canPinChannel: Boolean,
387416
selectedChannel: Channel,
388417
viewModel: ChannelListViewModel,
389418
): ChannelAction? = when (selectedChannel.isPinned().takeIf { canPinChannel }) {
390419
false -> PinChannel(
391420
channel = selectedChannel,
392-
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_channel),
421+
label = stringResource(id = R.string.stream_compose_selected_channel_menu_pin_group),
393422
onAction = { viewModel.pinChannel(selectedChannel) },
394423
)
395424

396425
true -> UnpinChannel(
397426
channel = selectedChannel,
398-
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_channel),
427+
label = stringResource(id = R.string.stream_compose_selected_channel_menu_unpin_group),
399428
onAction = { viewModel.unpinChannel(selectedChannel) },
400429
)
401430

stream-chat-android-compose/src/main/res/values/strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
<!-- Selected Channel Menu -->
4949
<string name="stream_compose_selected_channel_menu_view_info">View info</string>
5050
<string name="stream_compose_selected_channel_menu_leave_group">Leave group</string>
51-
<string name="stream_compose_selected_channel_menu_pin_channel">Pin Channel</string>
52-
<string name="stream_compose_selected_channel_menu_unpin_channel">Unpin Channel</string>
51+
<string name="stream_compose_selected_channel_menu_pin_chat">Pin Chat</string>
52+
<string name="stream_compose_selected_channel_menu_unpin_chat">Unpin Chat</string>
53+
<string name="stream_compose_selected_channel_menu_pin_group">Pin Group</string>
54+
<string name="stream_compose_selected_channel_menu_unpin_group">Unpin Group</string>
5355
<string name="stream_compose_selected_channel_menu_leave_group_confirmation_title">Leave group</string>
5456
<string name="stream_compose_selected_channel_menu_leave_group_confirmation_message">Do you want to leave the %1$s group?</string>
5557
<string name="stream_compose_selected_channel_menu_mute_group">Mute Group</string>

0 commit comments

Comments
 (0)