diff --git a/src/context/revoltjs/events.ts b/src/context/revoltjs/events.ts index 8e94c54e..7c18dae2 100644 --- a/src/context/revoltjs/events.ts +++ b/src/context/revoltjs/events.ts @@ -1,7 +1,10 @@ import { Client } from "revolt.js/dist"; +import { Server } from "revolt.js/dist/maps/Servers"; import { StateUpdater } from "preact/hooks"; +import { deleteRenderer } from "../../lib/renderer/Singleton"; + import Auth from "../../mobx/stores/Auth"; import { resetMemberSidebarFetched } from "../../components/navigation/right/MemberSidebar"; @@ -28,6 +31,18 @@ export function registerEvents( auth.logout(); setStatus(ClientStatus.READY); }, + + "channel/delete": (channel_id: string) => { + deleteRenderer(channel_id); + }, + + "server/delete": (_, server: Server) => { + if (server) { + for (const channel_id of server.channel_ids) { + deleteRenderer(channel_id); + } + } + }, }; if (import.meta.env.DEV) { diff --git a/src/lib/renderer/Singleton.ts b/src/lib/renderer/Singleton.ts index bf83bd2e..d0301466 100644 --- a/src/lib/renderer/Singleton.ts +++ b/src/lib/renderer/Singleton.ts @@ -222,3 +222,7 @@ export function getRenderer(channel: Channel) { return renderer; } + +export function deleteRenderer(channel_id: string) { + delete renderers[channel_id]; +}