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