Skip to content

Commit 5a9f785

Browse files
committed
fix: add back channel.deleted event
1 parent aa353f1 commit 5a9f785

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ const ChannelWithContext = <
644644
colors: { black },
645645
},
646646
} = useTheme();
647+
const [deleted, setDeleted] = useState<boolean>(false);
647648
const [editing, setEditing] = useState<MessageType<StreamChatGenerics> | undefined>(undefined);
648649
const [error, setError] = useState<Error | boolean>(false);
649650
const [lastRead, setLastRead] = useState<ChannelContextValue<StreamChatGenerics>['lastRead']>();
@@ -777,11 +778,23 @@ const ChannelWithContext = <
777778
return () => {
778779
copyChannelState.cancel();
779780
loadMoreThreadFinished.cancel();
780-
listener.unsubscribe();
781+
listener?.unsubscribe();
781782
};
782783
// eslint-disable-next-line react-hooks/exhaustive-deps
783784
}, [channel.cid, messageId, shouldSyncChannel]);
784785

786+
// subscribe to channel.deleted event
787+
useEffect(() => {
788+
const { unsubscribe } = client.on('channel.deleted', (event) => {
789+
if (event.cid === channel?.cid) {
790+
setDeleted(true);
791+
}
792+
});
793+
794+
return unsubscribe;
795+
// eslint-disable-next-line react-hooks/exhaustive-deps
796+
}, [channelId]);
797+
785798
/**
786799
* Subscription to the Notification mark_read event.
787800
*/
@@ -1815,6 +1828,9 @@ const ChannelWithContext = <
18151828
typing: channelState.typing ?? {},
18161829
});
18171830

1831+
// TODO: replace the null view with appropriate message. Currently this is waiting a design decision.
1832+
if (deleted) return null;
1833+
18181834
if (!channel || (error && channelMessagesState.messages?.length === 0)) {
18191835
return <LoadingErrorIndicator error={error} listType='message' retry={reloadChannel} />;
18201836
}

0 commit comments

Comments
 (0)