1/**
2 * Chat overlays (dialogs, media previews) are opened for one thread and must not
3 * outlive its route. Overlay modules register here when they load, so the route
4 * listener can drop them without importing the overlays themselves.
5 */
6const retainers: Array<(threadKey: string | null) => void> = [];
7
8export function registerThreadOverlay(retain: (threadKey: string | null) => void): void {
9 retainers.push(retain);
10}
11
12/** Drops every overlay opened for a thread other than `threadKey`. */
13export function retainThreadOverlaysForThread(threadKey: string | null): void {
14 for (const retain of retainers) retain(threadKey);
15}