Path: blob/master/src/packages/frontend/editors/markdown-input/mentions.ts
5913 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}1415const seenFragmentIds = new Set<string>();1617export async function submit_mentions(18project_id: string,19path: string,20mentions: Mention[],21): Promise<void> {22const source = redux.getStore("account")?.get("account_id");23if (source == null) {24return;25}26for (const { account_id, description, fragment_id } of mentions) {27if (!isValidUUID(account_id)) {28// Ignore all language model mentions, they are processed by the chat actions in the frontend29continue;30}31if (fragment_id) {32if (seenFragmentIds.has(fragment_id)) {33continue;34}35seenFragmentIds.add(fragment_id);36}37try {38await webapp_client.query_client.query({39query: {40mentions: {41project_id,42path: original_path(path),43fragment_id,44target: account_id,45priority: 2,46description,47source,48},49},50});51} catch (err) {52// TODO: this is just naively assuming that no errors happen.53// What if there is a network blip?54// Then we would just loose the mention, which is no good. Do better.55console.warn("Failed to submit mention ", err);56}57}58}596061