Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/src/packages/frontend/client/messages.ts
Views: 821
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6This are two simple functions that you can use anywhere in code that make it easy to send7a message to any other user and also download all messages you have sent or received.8See @cocalc/util/db-schema/messages for definitions of parameters.910The interactive message UI interface uses a different way of getting messages11via synctables/changefeeds, so that it dynamically updates whenever anything12changes.1314Messages also trigger (throttled) emails to people with a verified email account.1516Ideas/Application for this:1718- make it easy for an instructor to send a message to everybody in their course.1920- make it easy for a student in a class to contact "course support", which will involve21some special not-yet-implemented metadata on a message to track support progress.2223- when some event happens, e.g., a computation completes, a message could be sent.2425*/2627import api from "./api";28import type { ApiMessagesGet, Message } from "@cocalc/util/db-schema/messages";2930export class Messages {31// Send a message to the given accounts. Returns the id number of the message, which can be used32// via reply_id to send followup messages in the same thread.33send = async (opts): Promise<number> => {34return await send(opts);35};3637get = async (opts): Promise<Message[]> => {38return await get(opts);39};40}4142export async function send({43to_ids,44subject,45body,46reply_id,47}: {48// if to_ids is not given, then message is sent *to the user* themselves. This can be useful49// for various sort of alerts that can get backed by batched emails (e.g., my computation is done).50to_ids?: string[];51subject: string;52body: string;53reply_id?: number;54}): Promise<number> {55const { id } = await api("/messages/send", {56to_ids,57subject,58body,59reply_id,60});61return id;62}6364export async function get(opts: ApiMessagesGet): Promise<Message[]> {65const { messages } = await api("/messages/get", opts);66return messages;67}686970