Skip to content

Commit 7e1f76f

Browse files
committed
fix: add proper way to check for mutes
1 parent 88a7f21 commit 7e1f76f

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

package/src/components/ChannelList/hooks/useChannelActionItems.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,6 @@ export const buildDefaultChannelActionItems: BuildDefaultChannelActionItems = (
8484
: undefined;
8585

8686
const actionItems: ChannelActionItem[] = [
87-
// isPinned
88-
// ? {
89-
// action: unpin,
90-
// Icon: <View />,
91-
// id: 'unpin',
92-
// label: '',
93-
// placement: 'both',
94-
// type: 'standard',
95-
// }
96-
// : {
97-
// action: pin,
98-
// Icon: <View />,
99-
// id: 'pin',
100-
// label: '',
101-
// placement: 'both',
102-
// type: 'standard',
103-
// },
10487
{
10588
action: isDirectChat
10689
? muteActive

package/src/components/Message/hooks/useMessageActionHandlers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Alert } from 'react-native';
22

3+
import { useUserMuteActive } from './useUserMuteActive';
4+
35
import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';
46
import type { ChatContextValue } from '../../../contexts/chatContext/ChatContext';
57
import { MessageComposerAPIContextValue } from '../../../contexts/messageComposerContext/MessageComposerAPIContext';
@@ -32,14 +34,12 @@ export const useMessageActionHandlers = ({
3234
const handleResendMessage = () => retrySendMessage(message);
3335
const translatedMessage = useTranslatedMessage(message);
3436

37+
const isMuted = useUserMuteActive(message.user);
38+
3539
const handleQuotedReplyMessage = () => {
3640
setQuotedMessage(message);
3741
};
3842

39-
const isMuted = (client.mutedUsers || []).some(
40-
(mute) => mute.user.id === client.userID && mute.target.id === message.user?.id,
41-
);
42-
4343
const handleCopyMessage = () => {
4444
if (!message.text) {
4545
return;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { UserResponse } from 'stream-chat';
2+
3+
import { useChannelContext, useChatContext } from '../../../contexts';
4+
import { useMutedUsers } from '../../ChannelList/hooks/useMutedUsers';
5+
6+
export const useUserMuteActive = (user: UserResponse | null | undefined) => {
7+
const { client } = useChatContext();
8+
const { channel } = useChannelContext();
9+
const mutedUsers = useMutedUsers(channel);
10+
11+
if (!user) {
12+
return false;
13+
}
14+
15+
return !!mutedUsers.find((mute) => mute.user.id === client.userID && user.id === mute.target.id);
16+
};

0 commit comments

Comments
 (0)