Skip to content

Commit 767d194

Browse files
authored
fix: update channel state on user.deleted event (#1985)
1 parent 4886e55 commit 767d194

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/components/Channel/Channel.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ const ChannelInner = <
377377

378378
const markReadThrottled = throttle(markRead, 500, { leading: true, trailing: true });
379379

380-
const handleEvent = (event: Event<StreamChatGenerics>) => {
380+
const handleEvent = async (event: Event<StreamChatGenerics>) => {
381381
if (event.message) {
382382
dispatch({
383383
channel,
@@ -434,6 +434,18 @@ const ChannelInner = <
434434
}
435435
}
436436

437+
if (event.type === 'user.deleted') {
438+
const oldestID = channel.state?.messages?.[0]?.id;
439+
440+
/**
441+
* As the channel state is not normalized we re-fetch the channel data. Thus we avoid having to search for user references in the channel state.
442+
*/
443+
await channel.query({
444+
messages: { id_lt: oldestID, limit: DEFAULT_NEXT_CHANNEL_PAGE_SIZE },
445+
watchers: { limit: DEFAULT_NEXT_CHANNEL_PAGE_SIZE },
446+
});
447+
}
448+
437449
throttledCopyStateFromChannel();
438450
};
439451

0 commit comments

Comments
 (0)