CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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