Path: blob/master/src/packages/frontend/editors/markdown-input/mentions.ts
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { redux } from "@cocalc/frontend/app-framework";6import { webapp_client } from "@cocalc/frontend/webapp-client";7import { isValidUUID, original_path } from "@cocalc/util/misc";89interface Mention {10account_id: string;11description: string;12fragment_id?: string;13}1415export async function submit_mentions(16project_id: string,17path: string,18mentions: Mention[],19): Promise<void> {20const source = redux.getStore("account")?.get("account_id");21if (source == null) {22return;23}24for (const { account_id, description, fragment_id } of mentions) {25if (!isValidUUID(account_id)) {26// Ignore all language model mentions, they are processed by the chat actions in the frontend27continue;28}29try {30await webapp_client.query_client.query({31query: {32mentions: {33project_id,34path: original_path(path),35fragment_id,36target: account_id,37priority: 2,38description,39source,40},41},42});43} catch (err) {44// TODO: this is just naively assuming that no errors happen.45// What if there is a network blip?46// Then we would just loose the mention, which is no good. Do better.47console.warn("Failed to submit mention ", err);48}49}50}515253