Skip to content

Commit cc8fc07

Browse files
committed
fix: muted channels not updating properly
1 parent 99e071d commit cc8fc07

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,25 @@ export const useIsChannelMuted = (channel: Channel) => {
1717

1818
useEffect(() => {
1919
const handleEvent = () => {
20+
const newMuteStatus = channel.muteStatus();
21+
if (
22+
newMuteStatus.muted === muted.muted &&
23+
newMuteStatus.createdAt?.getTime() === muted.createdAt?.getTime() &&
24+
newMuteStatus.expiresAt?.getTime() === muted.expiresAt?.getTime()
25+
) {
26+
return;
27+
}
28+
2029
setMuted(channel.muteStatus());
2130
};
2231

23-
client.on('notification.channel_mutes_updated', handleEvent);
24-
return () => client.off('notification.channel_mutes_updated', handleEvent);
32+
const listeners = [
33+
client.on('notification.channel_mutes_updated', handleEvent),
34+
client.on('health.check', handleEvent),
35+
];
36+
return () => {
37+
listeners.forEach((listener) => listener.unsubscribe());
38+
};
2539
}, [channel, client, muted]);
2640

2741
return muted ?? defaultMuteStatus;

0 commit comments

Comments
 (0)