Skip to content

Commit deda536

Browse files
fix: allow user blocking only in DM-type channels (#3139)
### 🎯 Goal Context menu action `Block` in channel list item should only appear if the channel is of DM type.
1 parent 16af18d commit deda536

3 files changed

Lines changed: 743 additions & 98 deletions

File tree

src/components/ChannelListItem/ChannelListItemActionButtons.defaults.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const defaultComponents = {
153153
return (
154154
<ContextMenuButton
155155
aria-label={behaviorProps.title}
156+
data-testid='dropdown-action-archive'
156157
Icon={IconArchive}
157158
{...behaviorProps}
158159
>
@@ -176,6 +177,7 @@ const defaultComponents = {
176177
return (
177178
<ContextMenuButton
178179
aria-label={title}
180+
data-testid='dropdown-action-ban'
179181
disabled={inProgress}
180182
Icon={IconNoSign}
181183
onClick={async () => {
@@ -244,6 +246,7 @@ const defaultComponents = {
244246
return (
245247
<ContextMenuButton
246248
aria-label={title}
249+
data-testid='dropdown-action-leave'
247250
disabled={inProgress}
248251
Icon={IconLeave}
249252
onClick={async (e) => {
@@ -290,6 +293,7 @@ const defaultComponents = {
290293
return (
291294
<ContextMenuButton
292295
aria-label={behaviorProps.title}
296+
data-testid='dropdown-action-mute'
293297
Icon={IconMute}
294298
{...behaviorProps}
295299
>
@@ -314,6 +318,7 @@ const defaultComponents = {
314318
return (
315319
<ContextMenuButton
316320
aria-label={title}
321+
data-testid='dropdown-action-pin'
317322
disabled={inProgress}
318323
Icon={IconPin}
319324
onClick={async (e) => {
@@ -377,6 +382,7 @@ const defaultComponents = {
377382
appearance='ghost'
378383
aria-label={behaviorProps.title}
379384
circular
385+
data-testid='quick-action-archive'
380386
size='sm'
381387
variant='secondary'
382388
{...behaviorProps}
@@ -393,6 +399,7 @@ const defaultComponents = {
393399
appearance='ghost'
394400
aria-label={behaviorProps.title}
395401
circular
402+
data-testid='quick-action-mute'
396403
size='sm'
397404
variant='secondary'
398405
{...behaviorProps}
@@ -418,6 +425,7 @@ const defaultComponents = {
418425
aria-expanded={dialogIsOpen}
419426
aria-pressed={dialogIsOpen}
420427
circular
428+
data-testid='channel-list-item-dropdown-toggle'
421429
onClick={(e) => {
422430
e.stopPropagation();
423431

@@ -472,6 +480,7 @@ export const useBaseChannelActionSetFilter = (channelActionSet: ChannelActionIte
472480
const membership = useChannelMembershipState(channel);
473481
const memberCount = channel.data?.member_count ?? 0;
474482
const connectedUserIsMember = typeof membership.user !== 'undefined';
483+
const isDirectMessageChannel = connectedUserIsMember && memberCount === 2;
475484

476485
const ownCapabilities = channel.data?.own_capabilities;
477486

@@ -486,9 +495,7 @@ export const useBaseChannelActionSetFilter = (channelActionSet: ChannelActionIte
486495
return ownCapabilities?.includes('mute-channel');
487496
case 'ban':
488497
return (
489-
memberCount > 0 &&
490-
memberCount <= 2 &&
491-
ownCapabilities?.includes('ban-channel-members')
498+
isDirectMessageChannel && ownCapabilities?.includes('ban-channel-members')
492499
);
493500
case 'leave':
494501
return ownCapabilities?.includes('leave-channel');
@@ -500,5 +507,5 @@ export const useBaseChannelActionSetFilter = (channelActionSet: ChannelActionIte
500507
});
501508

502509
return filtered;
503-
}, [channelActionSet, memberCount, ownCapabilities, connectedUserIsMember]);
510+
}, [channelActionSet, connectedUserIsMember, ownCapabilities, isDirectMessageChannel]);
504511
};

src/components/ChannelListItem/ChannelListItemActionButtons.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface
4444
className={clsx('str-chat__channel-list-item__action-buttons', {
4545
'str-chat__channel-list-item__action-buttons--active': dialogIsOpen,
4646
})}
47+
data-testid='channel-list-item-action-buttons'
4748
>
4849
{quickDropdownToggleAction && dropdownActionSet.length > 0 && (
4950
<quickDropdownToggleAction.Component ref={setReferenceElement} />
@@ -53,6 +54,7 @@ export const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface
5354
))}
5455
<ContextMenuComponent
5556
className='str-chat__channel-list-item__action-buttons-context-menu'
57+
data-testid='channel-list-item-context-menu'
5658
dialogManagerId={dialogManager?.id}
5759
id={dialog.id}
5860
onClose={dialog?.close}

0 commit comments

Comments
 (0)