Skip to content

Commit

Permalink
Merge pull request #2788 from GetStream/develop
Browse files Browse the repository at this point in the history
Next Release
  • Loading branch information
isekovanic authored Nov 15, 2024
2 parents 2c7e95a + 9b5b243 commit 2c686a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ describe('useChannelPreviewMuted', () => {
});

const mockChannel = {
muteStatus: jest.fn().mockReturnValue(false),
initialized: true,
muteStatus: jest.fn().mockReturnValue({
createdAt: Date.now(),
expiresAt: Date.now() + 5000,
muted: false,
}),
} as unknown as Channel<DefaultStreamChatGenerics>;

it('should return the correct mute status', () => {
const { result } = renderHook(() => useIsChannelMuted(mockChannel));
expect(result.current).toBe(false);
expect(result.current.muted).toBe(false);
});

it("should update the mute status when the notification.channel_mutes_updated event is emitted'", () => {
Expand Down
10 changes: 5 additions & 5 deletions package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export const useIsChannelMuted = <
channel: Channel<StreamChatGenerics>,
) => {
const { client } = useChatContext<StreamChatGenerics>();
const initialized = channel?.initialized;

const [muted, setMuted] = useState(channel.muteStatus());
const [muted, setMuted] = useState(() => initialized && channel.muteStatus());

useEffect(() => {
const handleEvent = () => {
setMuted(channel.muteStatus());
setMuted(initialized && channel.muteStatus());
};

client.on('notification.channel_mutes_updated', handleEvent);
return () => client.off('notification.channel_mutes_updated', handleEvent);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [muted]);
}, [channel, client, initialized, muted]);

return muted;
return muted || { createdAt: null, expiresAt: null, muted: false };
};
32 changes: 17 additions & 15 deletions package/src/components/MessageInput/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,21 +895,23 @@ const MessageInputWithContext = <
</View>
)}
{showPollCreationDialog ? (
<Modal
animationType='slide'
onRequestClose={closePollCreationDialog}
visible={showPollCreationDialog}
>
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaView style={{ backgroundColor: white, flex: 1 }}>
<CreatePoll
closePollCreationDialog={closePollCreationDialog}
CreatePollContent={CreatePollContent}
sendMessage={sendMessage}
/>
</SafeAreaView>
</GestureHandlerRootView>
</Modal>
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center' }}>
<Modal
animationType='slide'
onRequestClose={closePollCreationDialog}
visible={showPollCreationDialog}
>
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaView style={{ backgroundColor: white, flex: 1 }}>
<CreatePoll
closePollCreationDialog={closePollCreationDialog}
CreatePollContent={CreatePollContent}
sendMessage={sendMessage}
/>
</SafeAreaView>
</GestureHandlerRootView>
</Modal>
</View>
) : null}
</>
);
Expand Down

0 comments on commit 2c686a6

Please sign in to comment.