Skip to content

Commit b23b320

Browse files
committed
fix: edge cases and test
1 parent 3e7f077 commit b23b320

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package/src/components/ChannelPreview/hooks/__tests__/useChannelPreviewMuted.test.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ describe('useChannelPreviewMuted', () => {
2929
});
3030

3131
const mockChannel = {
32-
muteStatus: jest.fn().mockReturnValue(false),
32+
initialized: true,
33+
muteStatus: jest.fn().mockReturnValue({
34+
createdAt: Date.now(),
35+
expiresAt: Date.now() + 5000,
36+
muted: false,
37+
}),
3338
} as unknown as Channel<DefaultStreamChatGenerics>;
3439

3540
it('should return the correct mute status', () => {
3641
const { result } = renderHook(() => useIsChannelMuted(mockChannel));
37-
expect(result.current).toBe(false);
42+
expect(result.current.muted).toBe(false);
3843
});
3944

4045
it("should update the mute status when the notification.channel_mutes_updated event is emitted'", () => {

package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const useChannelPreviewData = <
1919
| MessageResponse<StreamChatGenerics>
2020
>(channel.state.messages[channel.state.messages.length - 1]);
2121
const [unread, setUnread] = useState(channel.countUnread());
22-
const muted = useIsChannelMuted(channel);
22+
const { muted } = useIsChannelMuted(channel);
2323

2424
/**
2525
* This effect listens for the `notification.mark_read` event and sets the unread count to 0

package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ export const useIsChannelMuted = <
1414
const { client } = useChatContext<StreamChatGenerics>();
1515
const initialized = channel?.initialized;
1616

17-
const [muted, setMuted] = useState(() => initialized && channel.muteStatus()?.muted);
17+
const [muted, setMuted] = useState(() => initialized && channel.muteStatus());
1818

1919
useEffect(() => {
2020
const handleEvent = () => {
21-
setMuted(initialized && channel.muteStatus()?.muted);
21+
setMuted(initialized && channel.muteStatus());
2222
};
2323

2424
client.on('notification.channel_mutes_updated', handleEvent);
2525
return () => client.off('notification.channel_mutes_updated', handleEvent);
2626
}, [channel, client, initialized, muted]);
2727

28-
return muted;
28+
return muted || { createdAt: null, expiresAt: null, muted: false };
2929
};

0 commit comments

Comments
 (0)