Path: blob/master/src/packages/frontend/chat/get-actions.ts
1496 views
/* Get the actions for a side chat. This will try to open the1chat as well and waits until the state is ready. */23import { delay } from "awaiting";45import type { ChatActions } from "@cocalc/frontend/chat/actions";6import { meta_file } from "@cocalc/util/misc";78export default async function getChatActions(9redux,10project_id: string,11path: string,12maxWaitSeconds: number = 10,13width: number = 0.714): Promise<ChatActions> {15const projectActions = redux.getProjectActions(project_id);16projectActions.open_chat({ path, width });17const start = Date.now();1819while (Date.now() - start <= 1000 * maxWaitSeconds) {20const chatActions = redux.getEditorActions(21project_id,22meta_file(path, "chat")23) as ChatActions;24if (chatActions?.syncdb?.get_state() == "ready") {25return chatActions;26}27await delay(200);28}29throw Error("unable to open chatroom");30}313233