diff --git a/src/app/chat/[id]/page.tsx b/src/app/chat/[id]/page.tsx index 457f80d..e530030 100644 --- a/src/app/chat/[id]/page.tsx +++ b/src/app/chat/[id]/page.tsx @@ -53,6 +53,7 @@ export default function DMs() { app.privateMessages, { onIndicator: addIndicator, + setServer: () => targetNode.current?.loadInitialMessages(id), }, targetNode ); diff --git a/src/components/app/AppLayout.tsx b/src/components/app/AppLayout.tsx index fec5a8d..1180602 100644 --- a/src/components/app/AppLayout.tsx +++ b/src/components/app/AppLayout.tsx @@ -14,6 +14,7 @@ import SidebarChannels from "./SidebarChannels"; import DMItem from "./DMItem"; import { useEffectOnceWhenReady } from "@/hooks/use-once"; import { getNode, useNullNode } from "@/hooks/use-node"; +import { ClientMessage } from "@/types/protocol"; export default function AppLayout({ children, @@ -56,6 +57,8 @@ export default function AppLayout({ if (onNewMessage) onNewMessage(m); }, + setServer: () => + chatWith && app.node.current?.loadInitialMessages(chatWith), }, node ); diff --git a/src/lib/node.ts b/src/lib/node.ts index d5aadcd..b9ca04d 100644 --- a/src/lib/node.ts +++ b/src/lib/node.ts @@ -74,6 +74,20 @@ export class NodeClient { await this.readyPromise; } + loadInitialMessages(channelId: string) { + this.waitUntilReady().then(() => { + this.socket?.send( + JSON.stringify({ + type: "load_chunk", + params: { + channel_id: channelId, + chunk_id: 0, + }, + }) + ); + }); + } + private async handleMessage(e: MessageEvent, authToken: string) { // Voice packet if (e.data instanceof Blob) {