import type { Channel } from 'stream-chat' /** * Restores pending messages into the channel's visible message list so they * appear as if they were already sent. * * Stream's pending-messages feature removes messages from the channel view * once client state is lost (e.g. page refresh). This function works around * that limitation by reading `channel.state.pending_messages` and * re-inserting them via `channel.state.addMessageSorted`. */ export function restorePendingMessages(channel: Channel) { const pendingMessages = channel.state.pending_messages if (!pendingMessages?.length) return for (const pending of pendingMessages) { channel.state.addMessageSorted(pending.message) } }