Skip to content

Commit 79baddf

Browse files
committed
fix: hide mute and block action from member sheet
1 parent d923e1b commit 79baddf

2 files changed

Lines changed: 72 additions & 29 deletions

File tree

package/src/hooks/actions/__tests__/useChannelMemberActionItems.test.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ const createMemberMock = (userId = 'target-user-id'): ChannelMemberResponse =>
2525
user_id: userId,
2626
}) as ChannelMemberResponse;
2727

28-
const createChannelMock = (params?: { blockedUserIds?: string[] }): Channel => {
29-
const { blockedUserIds = [] } = params ?? {};
28+
const createChannelMock = (params?: { blockedUserIds?: string[]; userID?: string }): Channel => {
29+
const { blockedUserIds = [], userID = 'current-user-id' } = params ?? {};
3030
return {
3131
getClient: () => ({
3232
blockedUsers: {
3333
getLatestValue: () => ({ userIds: blockedUserIds }),
3434
subscribeWithSelector: () => () => {},
3535
},
36+
userID,
3637
}),
3738
} as unknown as Channel;
3839
};
@@ -70,6 +71,16 @@ describe('useChannelMemberActionItems', () => {
7071
expect(result.current.map((item) => item.label)).toEqual(['Mute User', 'Block User']);
7172
});
7273

74+
it('returns no action items when the member is the current user', () => {
75+
const currentUserChannel = createChannelMock({ userID: 'target-user-id' });
76+
77+
const { result } = renderHook(() =>
78+
useChannelMemberActionItems({ channel: currentUserChannel, member }),
79+
);
80+
81+
expect(result.current).toEqual([]);
82+
});
83+
7384
it('toggles muteUser to unmuteUser when the member is already muted', () => {
7485
jest
7586
.spyOn(useMutedUsersModule, 'useMutedUsers')
@@ -140,6 +151,7 @@ describe('useChannelMemberActionItems', () => {
140151
actions: userActions,
141152
channel,
142153
isBlocked: false,
154+
isCurrentUser: false,
143155
member,
144156
t: expect.any(Function),
145157
userMuteActive: false,
@@ -161,6 +173,7 @@ describe('buildDefaultChannelMemberActionItems', () => {
161173
actions,
162174
channel,
163175
isBlocked: false,
176+
isCurrentUser: false,
164177
member,
165178
t: ((value: string) => value) as TranslationContextValue['t'],
166179
userMuteActive: false,
@@ -172,12 +185,28 @@ describe('buildDefaultChannelMemberActionItems', () => {
172185
expect(items.map((item) => item.type)).toEqual(['standard', 'destructive']);
173186
});
174187

188+
it('returns no items when the member is the current user', () => {
189+
const actions = createUserActions();
190+
const items = buildDefaultChannelMemberActionItems({
191+
actions,
192+
channel,
193+
isBlocked: false,
194+
isCurrentUser: true,
195+
member,
196+
t: ((value: string) => value) as TranslationContextValue['t'],
197+
userMuteActive: false,
198+
});
199+
200+
expect(items).toEqual([]);
201+
});
202+
175203
it('returns unmute/unblock variants when toggles are active', () => {
176204
const actions = createUserActions();
177205
const items = buildDefaultChannelMemberActionItems({
178206
actions,
179207
channel,
180208
isBlocked: true,
209+
isCurrentUser: false,
181210
member,
182211
t: ((value: string) => value) as TranslationContextValue['t'],
183212
userMuteActive: true,
@@ -194,6 +223,7 @@ describe('buildDefaultChannelMemberActionItems', () => {
194223
actions,
195224
channel,
196225
isBlocked: false,
226+
isCurrentUser: false,
197227
member,
198228
t: ((value: string) => value) as TranslationContextValue['t'],
199229
userMuteActive: true,
@@ -209,6 +239,7 @@ describe('buildDefaultChannelMemberActionItems', () => {
209239
actions,
210240
channel,
211241
isBlocked: false,
242+
isCurrentUser: false,
212243
member,
213244
t: ((value: string) => value) as TranslationContextValue['t'],
214245
userMuteActive: false,
@@ -219,6 +250,7 @@ describe('buildDefaultChannelMemberActionItems', () => {
219250
actions,
220251
channel,
221252
isBlocked: false,
253+
isCurrentUser: false,
222254
member,
223255
t: ((value: string) => value) as TranslationContextValue['t'],
224256
userMuteActive: false,

package/src/hooks/actions/useChannelMemberActionItems.tsx

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ChannelMemberActionItemsParams = {
1717
actions: UserActions;
1818
channel: Channel;
1919
isBlocked: boolean;
20+
isCurrentUser: boolean;
2021
member: ChannelMemberResponse;
2122
t: TranslationContextValue['t'];
2223
userMuteActive: boolean;
@@ -43,36 +44,43 @@ export const buildDefaultChannelMemberActionItems: BuildDefaultChannelMemberActi
4344
const {
4445
actions: { blockUser, muteUser, unblockUser, unmuteUser },
4546
isBlocked,
47+
isCurrentUser,
4648
t,
4749
userMuteActive,
4850
} = channelMemberActionItemsParams;
4951

50-
const actionItems: ChannelMemberActionItem[] = [
51-
{
52-
action: userMuteActive ? unmuteUser : muteUser,
53-
Icon: (props) =>
54-
userMuteActive ? (
55-
<ChannelMemberActionsIcon Icon={Sound} {...props} />
56-
) : (
57-
<ChannelMemberActionsIcon
58-
Icon={Mute}
59-
{...props}
60-
fill={props.fill ?? props.stroke}
61-
stroke={undefined}
62-
/>
63-
),
64-
id: 'muteUser',
65-
label: userMuteActive ? t('Unmute User') : t('Mute User'),
66-
type: 'standard',
67-
},
68-
{
69-
action: isBlocked ? unblockUser : blockUser,
70-
Icon: (props) => <ChannelMemberActionsIcon Icon={BlockUser} {...props} />,
71-
id: 'block',
72-
label: isBlocked ? t('Unblock User') : t('Block User'),
73-
type: isBlocked ? 'standard' : 'destructive',
74-
},
75-
];
52+
const actionItems: ChannelMemberActionItem[] = [];
53+
54+
// Muting or blocking yourself is meaningless, so these actions are only
55+
// added for other members.
56+
if (!isCurrentUser) {
57+
actionItems.push(
58+
{
59+
action: userMuteActive ? unmuteUser : muteUser,
60+
Icon: (props) =>
61+
userMuteActive ? (
62+
<ChannelMemberActionsIcon Icon={Sound} {...props} />
63+
) : (
64+
<ChannelMemberActionsIcon
65+
Icon={Mute}
66+
{...props}
67+
fill={props.fill ?? props.stroke}
68+
stroke={undefined}
69+
/>
70+
),
71+
id: 'muteUser',
72+
label: userMuteActive ? t('Unmute User') : t('Mute User'),
73+
type: 'standard',
74+
},
75+
{
76+
action: isBlocked ? unblockUser : blockUser,
77+
Icon: (props) => <ChannelMemberActionsIcon Icon={BlockUser} {...props} />,
78+
id: 'block',
79+
label: isBlocked ? t('Unblock User') : t('Block User'),
80+
type: isBlocked ? 'standard' : 'destructive',
81+
},
82+
);
83+
}
7684

7785
return actionItems;
7886
};
@@ -112,16 +120,19 @@ export const useChannelMemberActionItems = ({
112120

113121
const isBlocked = blockedUserIds.includes(member.user?.id ?? '');
114122

123+
const isCurrentUser = member.user?.id === channel.getClient().userID;
124+
115125
const channelMemberActionItemsParams = useMemo<ChannelMemberActionItemsParams>(
116126
() => ({
117127
actions: userActions,
118128
channel,
119129
isBlocked,
130+
isCurrentUser,
120131
member,
121132
t,
122133
userMuteActive,
123134
}),
124-
[channel, isBlocked, member, t, userActions, userMuteActive],
135+
[channel, isBlocked, isCurrentUser, member, t, userActions, userMuteActive],
125136
);
126137

127138
const defaultItems = useMemo(

0 commit comments

Comments
 (0)