@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// Mention helpers shared by the composer suggestions and outgoing messages.
|
|
2
|
+
// Display names stay visible while typing; the wire format is applied on send.
|
|
3
|
+
import { t } from "./i18n.mjs";
|
|
4
|
+
|
|
5
|
+
export interface Participant {
|
|
6
|
+
id?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MentionItem {
|
|
11
|
+
name: string;
|
|
12
|
+
insert: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MentionTrigger {
|
|
17
|
+
start: number;
|
|
18
|
+
query: string;
|
|
19
|
+
cursor: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MentionRange {
|
|
23
|
+
start: number;
|
|
24
|
+
end: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Segment {
|
|
28
|
+
text: string;
|
|
29
|
+
code: boolean;
|
|
30
|
+
start: number;
|
|
31
|
+
end: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const escapeRegExp = (value: string) => String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35
|
+
|
|
36
|
+
export function mentionNames(participants: readonly Participant[] = []): string[] {
|
|
37
|
+
const names: string[] = [];
|
|
38
|
+
const seen = new Set(["all"]);
|
|
39
|
+
const list = Array.isArray(participants) ? participants : [];
|
|
40
|
+
for (const participant of list) {
|
|
41
|
+
const name = String(participant?.name ?? participant?.id ?? "").trim();
|
|
42
|
+
if (!name || seen.has(name.toLowerCase())) continue;
|
|
43
|
+
seen.add(name.toLowerCase());
|
|
44
|
+
names.push(name);
|
|
45
|
+
}
|
|
46
|
+
return names;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mentionItems(participants: readonly Participant[], query = ""): MentionItem[] {
|
|
50
|
+
const needle = String(query ?? "").toLowerCase();
|
|
51
|
+
const items: MentionItem[] = mentionNames(participants).map((name) => ({
|
|
52
|
+
name,
|
|
53
|
+
insert: `@${name}`,
|
|
54
|
+
label: name,
|
|
55
|
+
}));
|
|
56
|
+
items.push({ name: "all", insert: "@all", label: t("mentions.everyone") });
|
|
57
|
+
return items.filter((item) => {
|
|
58
|
+
const haystack = `${item.label} ${item.name}`.toLowerCase();
|
|
59
|
+
return !needle || haystack.includes(needle);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Locate the @token at the end of the draft, outside email-like tokens. */
|
|
64
|
+
export function mentionTrigger(text: string): MentionTrigger | null {
|
|
65
|
+
const source = String(text ?? "");
|
|
66
|
+
const match = source.match(/(^|[^\p{L}\p{N}_@])@([^\n@]{0,64})$/u);
|
|
67
|
+
if (!match) return null;
|
|
68
|
+
const query = match[2] ?? "";
|
|
69
|
+
return { start: source.length - query.length - 1, query, cursor: source.length };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function insertMention(draft: string, trigger: MentionTrigger | null, insert: string): string {
|
|
73
|
+
const source = String(draft ?? "");
|
|
74
|
+
const at = trigger ?? mentionTrigger(source);
|
|
75
|
+
if (!at) return source;
|
|
76
|
+
const before = source.slice(0, at.start);
|
|
77
|
+
const after = source.slice(at.cursor ?? source.length);
|
|
78
|
+
return `${before}${insert} ${after}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Find a closing backtick run of exactly `length`, never a longer run. */
|
|
82
|
+
function closingBackticks(source: string, from: number, end: number, length: number): number {
|
|
83
|
+
let i = from;
|
|
84
|
+
while (i < end) {
|
|
85
|
+
if (source.charAt(i) !== "`") {
|
|
86
|
+
i += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let run = 0;
|
|
90
|
+
while (i + run < end && source.charAt(i + run) === "`") run += 1;
|
|
91
|
+
if (run === length) return i;
|
|
92
|
+
i += run;
|
|
93
|
+
}
|
|
94
|
+
return -1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Split Markdown prose from fenced/indented code and inline code spans. */
|
|
98
|
+
function codeSegments(source: string): Segment[] {
|
|
99
|
+
const segments: Segment[] = [];
|
|
100
|
+
let proseStart = 0;
|
|
101
|
+
let lineStart = 0;
|
|
102
|
+
const push = (start: number, end: number, code: boolean) => {
|
|
103
|
+
if (end > start) segments.push({ text: source.slice(start, end), code, start, end });
|
|
104
|
+
};
|
|
105
|
+
while (lineStart < source.length) {
|
|
106
|
+
const lineEnd = source.indexOf("\n", lineStart);
|
|
107
|
+
const end = lineEnd < 0 ? source.length : lineEnd;
|
|
108
|
+
const line = source.slice(lineStart, end).replace(/\r$/, "");
|
|
109
|
+
const opener = /^([ \t]*)(`{3,}|~{3,})/.exec(line);
|
|
110
|
+
if (opener) {
|
|
111
|
+
if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
|
|
112
|
+
const fence = opener[2] ?? "";
|
|
113
|
+
const indent = (opener[1] ?? "").length;
|
|
114
|
+
let scan = lineEnd < 0 ? source.length : lineEnd + 1;
|
|
115
|
+
let closed = source.length;
|
|
116
|
+
while (scan < source.length) {
|
|
117
|
+
const nextEnd = source.indexOf("\n", scan);
|
|
118
|
+
const stop = nextEnd < 0 ? source.length : nextEnd;
|
|
119
|
+
const close = /^([ \t]*)(`{3,}|~{3,})[ \t]*$/.exec(source.slice(scan, stop).replace(/\r$/, ""));
|
|
120
|
+
const closeFence = close?.[2] ?? "";
|
|
121
|
+
if (close && closeFence.charAt(0) === fence.charAt(0) && closeFence.length >= fence.length
|
|
122
|
+
&& (close[1] ?? "").length <= indent + 3) {
|
|
123
|
+
closed = nextEnd < 0 ? source.length : nextEnd + 1;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
scan = nextEnd < 0 ? source.length : nextEnd + 1;
|
|
127
|
+
}
|
|
128
|
+
push(lineStart, closed, true);
|
|
129
|
+
proseStart = closed;
|
|
130
|
+
lineStart = closed;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// CommonMark indented code is also literal. Treat four spaces/tab as code
|
|
134
|
+
// rather than risking a mention rewrite inside it.
|
|
135
|
+
if (/^(?: {4,}|\t)/.test(line)) {
|
|
136
|
+
if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
|
|
137
|
+
let scan = lineStart;
|
|
138
|
+
let closed = source.length;
|
|
139
|
+
while (scan < source.length) {
|
|
140
|
+
const nextEnd = source.indexOf("\n", scan);
|
|
141
|
+
const stop = nextEnd < 0 ? source.length : nextEnd;
|
|
142
|
+
const current = source.slice(scan, stop).replace(/\r$/, "");
|
|
143
|
+
if (current.trim() && !/^(?: {4,}|\t)/.test(current)) {
|
|
144
|
+
closed = scan;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
scan = nextEnd < 0 ? source.length : nextEnd + 1;
|
|
148
|
+
}
|
|
149
|
+
push(lineStart, closed, true);
|
|
150
|
+
proseStart = closed;
|
|
151
|
+
lineStart = closed;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
lineStart = lineEnd < 0 ? source.length : lineEnd + 1;
|
|
155
|
+
}
|
|
156
|
+
splitInlineCode(source, proseStart, source.length, segments);
|
|
157
|
+
return segments;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function splitInlineCode(source: string, start: number, end: number, segments: Segment[]): void {
|
|
161
|
+
let prose = start;
|
|
162
|
+
let i = start;
|
|
163
|
+
while (i < end) {
|
|
164
|
+
if (source.charAt(i) !== "`") {
|
|
165
|
+
i += 1;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let run = 1;
|
|
169
|
+
while (i + run < end && source.charAt(i + run) === "`") run += 1;
|
|
170
|
+
const close = closingBackticks(source, i + run, end, run);
|
|
171
|
+
if (close < 0) {
|
|
172
|
+
i += run;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (i > prose) segments.push({ text: source.slice(prose, i), code: false, start: prose, end: i });
|
|
176
|
+
segments.push({ text: source.slice(i, close + run), code: true, start: i, end: close + run });
|
|
177
|
+
prose = close + run;
|
|
178
|
+
i = prose;
|
|
179
|
+
}
|
|
180
|
+
if (end > prose) segments.push({ text: source.slice(prose, end), code: false, start: prose, end });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function convertPlain(segment: string, names: readonly string[]): string {
|
|
184
|
+
if (!segment) return segment;
|
|
185
|
+
const candidates = ["all", ...names].sort((a, b) => b.length - a.length);
|
|
186
|
+
const pattern = new RegExp(
|
|
187
|
+
`(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
|
|
188
|
+
"gu",
|
|
189
|
+
);
|
|
190
|
+
return segment.replace(pattern, (_match: string, name: string) => `<at>@${name}</at>`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function convertProse(source: string, names: readonly string[]): string {
|
|
194
|
+
const tag = /<at>[\s\S]*?<\/at>/giu;
|
|
195
|
+
let output = "";
|
|
196
|
+
let last = 0;
|
|
197
|
+
for (const match of source.matchAll(tag)) {
|
|
198
|
+
output += convertPlain(source.slice(last, match.index), names);
|
|
199
|
+
output += match[0];
|
|
200
|
+
last = match.index + match[0].length;
|
|
201
|
+
}
|
|
202
|
+
return output + convertPlain(source.slice(last), names);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Convert known @names and @all to <at> tags, preserving code and existing tags. */
|
|
206
|
+
export function canonicalizeMentions(text: string, participants: readonly Participant[] = []): string {
|
|
207
|
+
const source = String(text ?? "");
|
|
208
|
+
const names = mentionNames(participants);
|
|
209
|
+
return codeSegments(source)
|
|
210
|
+
.map((segment) => (segment.code ? segment.text : convertProse(segment.text, names)))
|
|
211
|
+
.join("");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Character ranges for visible mention chips, excluding email-like tokens. */
|
|
215
|
+
export function mentionRanges(text: string, participants: readonly Participant[] = []): MentionRange[] {
|
|
216
|
+
const source = String(text ?? "");
|
|
217
|
+
const ranges: MentionRange[] = [];
|
|
218
|
+
const candidates = ["all", ...mentionNames(participants)].sort((a, b) => b.length - a.length);
|
|
219
|
+
const pattern = new RegExp(
|
|
220
|
+
`(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
|
|
221
|
+
"gu",
|
|
222
|
+
);
|
|
223
|
+
for (const segment of codeSegments(source)) {
|
|
224
|
+
if (segment.code) continue;
|
|
225
|
+
const tag = /<at>([\s\S]*?)<\/at>/giu;
|
|
226
|
+
let last = 0;
|
|
227
|
+
const plain: [number, number][] = [];
|
|
228
|
+
for (const match of segment.text.matchAll(tag)) {
|
|
229
|
+
const inner = match[1] ?? "";
|
|
230
|
+
const trimmed = inner.trim();
|
|
231
|
+
const at = trimmed.indexOf("@");
|
|
232
|
+
if (at >= 0) {
|
|
233
|
+
const innerStart = segment.start + match.index + 4 + (inner.length - inner.trimStart().length);
|
|
234
|
+
ranges.push({ start: innerStart + at, end: innerStart + trimmed.length });
|
|
235
|
+
}
|
|
236
|
+
plain.push([last, match.index]);
|
|
237
|
+
last = match.index + match[0].length;
|
|
238
|
+
}
|
|
239
|
+
plain.push([last, segment.text.length]);
|
|
240
|
+
for (const [start, end] of plain) {
|
|
241
|
+
const piece = segment.text.slice(start, end);
|
|
242
|
+
for (const match of piece.matchAll(pattern)) {
|
|
243
|
+
ranges.push({
|
|
244
|
+
start: segment.start + start + match.index,
|
|
245
|
+
end: segment.start + start + match.index + match[0].length,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return ranges.sort((a, b) => a.start - b.start);
|
|
251
|
+
}
|
package/src/tui/message-app.mjs
CHANGED
|
@@ -3,180 +3,188 @@
|
|
|
3
3
|
import { mergeMessages } from "./messages.mjs";
|
|
4
4
|
import { canonicalizeMentions } from "./mentions.mjs";
|
|
5
5
|
import { t } from "./i18n.mjs";
|
|
6
|
-
|
|
7
6
|
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
8
|
-
|
|
9
7
|
export function attachMessageActions(Class) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return palette;
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
startMessageRecall() {
|
|
31
|
-
return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
startMessageReveal() {
|
|
35
|
-
return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
startMessageReply() {
|
|
39
|
-
return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
startAskQuestion() {
|
|
43
|
-
return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
async submitMessagePrompt(prompt, value) {
|
|
47
|
-
const palette = this.state.palette;
|
|
48
|
-
const roomId = palette?.roomId || this.state.current?.id;
|
|
49
|
-
const participants = palette?.roomParticipants || this.state.current?.participants;
|
|
50
|
-
if (!palette || palette.mode !== "prompt") return;
|
|
51
|
-
if (!roomId) {
|
|
52
|
-
palette.error = t("info.joinFirst");
|
|
53
|
-
this.touch();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (prompt.action === "message-ask") {
|
|
57
|
-
const question = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
58
|
-
if (!question) {
|
|
59
|
-
palette.error = t("message.questionRequired");
|
|
60
|
-
this.touch();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
palette.searching = true;
|
|
64
|
-
palette.error = "";
|
|
65
|
-
this.touch();
|
|
66
|
-
try {
|
|
67
|
-
const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
|
|
68
|
-
if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
|
|
69
|
-
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
70
|
-
this.state.connection = "online";
|
|
71
|
-
this.closePalette();
|
|
72
|
-
this.setStatus(t("message.questionSent"), "success");
|
|
73
|
-
this.markRead();
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (this.state.palette === palette) {
|
|
76
|
-
palette.searching = false;
|
|
77
|
-
palette.error = errorText(error);
|
|
8
|
+
Object.assign(Class.prototype, {
|
|
9
|
+
messageActionPalette(title, label, action, data = {}) {
|
|
10
|
+
const palette = this.state.palette;
|
|
11
|
+
const current = this.state.current;
|
|
12
|
+
if (!palette || !current || !this.state.joined) {
|
|
13
|
+
this.state.palette = null;
|
|
14
|
+
this.setStatus(t("info.joinFirst"), "error");
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
palette.mode = "prompt";
|
|
18
|
+
palette.roomId = current.id;
|
|
19
|
+
palette.roomParticipants = [...(current.participants || [])];
|
|
20
|
+
palette.title = title;
|
|
21
|
+
palette.subtitle = `#${current.name}`;
|
|
22
|
+
palette.error = "";
|
|
23
|
+
palette.prompt = { label, value: "", action, data };
|
|
24
|
+
palette.hint = t("palette.enterNextHint");
|
|
78
25
|
this.touch();
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
26
|
+
return palette;
|
|
27
|
+
},
|
|
28
|
+
startMessageRecall() {
|
|
29
|
+
return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
|
|
30
|
+
},
|
|
31
|
+
startMessageReveal() {
|
|
32
|
+
return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
|
|
33
|
+
},
|
|
34
|
+
startMessageReply() {
|
|
35
|
+
return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
|
|
36
|
+
},
|
|
37
|
+
startAskQuestion() {
|
|
38
|
+
return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
|
|
39
|
+
},
|
|
40
|
+
async submitMessagePrompt(prompt, value) {
|
|
41
|
+
const palette = this.state.palette;
|
|
42
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
43
|
+
const participants = palette?.roomParticipants || this.state.current?.participants;
|
|
44
|
+
if (!palette || palette.mode !== "prompt")
|
|
45
|
+
return;
|
|
46
|
+
if (!roomId) {
|
|
47
|
+
palette.error = t("info.joinFirst");
|
|
48
|
+
this.touch();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (prompt.action === "message-ask") {
|
|
52
|
+
const question = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
53
|
+
if (!question) {
|
|
54
|
+
palette.error = t("message.questionRequired");
|
|
55
|
+
this.touch();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
palette.searching = true;
|
|
59
|
+
palette.error = "";
|
|
60
|
+
this.touch();
|
|
61
|
+
try {
|
|
62
|
+
const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
|
|
63
|
+
const messages = result?.messages;
|
|
64
|
+
if (Array.isArray(messages))
|
|
65
|
+
mergeMessages(this.state.messages, messages);
|
|
66
|
+
else if (result?.id)
|
|
67
|
+
mergeMessages(this.state.messages, [result]);
|
|
68
|
+
this.state.connection = "online";
|
|
69
|
+
this.closePalette();
|
|
70
|
+
this.setStatus(t("message.questionSent"), "success");
|
|
71
|
+
this.markRead();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (this.state.palette === palette) {
|
|
75
|
+
palette.searching = false;
|
|
76
|
+
palette.error = errorText(error);
|
|
77
|
+
this.touch();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const id = String(value ?? "").trim();
|
|
83
|
+
if (!id) {
|
|
84
|
+
palette.error = t("message.idRequired");
|
|
85
|
+
this.touch();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (prompt.action === "message-recall-id" || prompt.action === "message-reveal-id") {
|
|
89
|
+
const recall = prompt.action === "message-recall-id";
|
|
90
|
+
palette.mode = "confirm";
|
|
91
|
+
palette.previous = { mode: "prompt", hint: palette.hint };
|
|
92
|
+
palette.confirm = {
|
|
93
|
+
text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
|
|
94
|
+
action: recall ? "message-recall" : "message-reveal",
|
|
95
|
+
data: { id },
|
|
96
|
+
};
|
|
97
|
+
palette.hint = t("palette.confirmHint");
|
|
98
|
+
palette.error = "";
|
|
99
|
+
this.touch();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (prompt.action === "message-reply-id") {
|
|
103
|
+
palette.prompt = {
|
|
104
|
+
label: t("message.replyLabel", { id }),
|
|
105
|
+
value: "",
|
|
106
|
+
action: "message-reply-text",
|
|
107
|
+
data: { id },
|
|
108
|
+
};
|
|
109
|
+
palette.hint = t("message.replyHint");
|
|
110
|
+
palette.error = "";
|
|
111
|
+
this.touch();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (prompt.action === "message-reply-text") {
|
|
115
|
+
const text = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
116
|
+
if (!text) {
|
|
117
|
+
palette.error = t("message.replyRequired");
|
|
118
|
+
this.touch();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
palette.searching = true;
|
|
122
|
+
palette.error = "";
|
|
123
|
+
this.touch();
|
|
124
|
+
try {
|
|
125
|
+
const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
|
|
126
|
+
if (!this.isCurrent(roomId))
|
|
127
|
+
return;
|
|
128
|
+
const messages = result?.messages;
|
|
129
|
+
if (Array.isArray(messages))
|
|
130
|
+
mergeMessages(this.state.messages, messages);
|
|
131
|
+
else if (result?.id)
|
|
132
|
+
mergeMessages(this.state.messages, [result]);
|
|
133
|
+
this.state.connection = "online";
|
|
134
|
+
this.closePalette();
|
|
135
|
+
this.setStatus(t("message.replySent"), "success");
|
|
136
|
+
this.markRead();
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (this.state.palette === palette) {
|
|
140
|
+
palette.searching = false;
|
|
141
|
+
palette.error = errorText(error);
|
|
142
|
+
this.touch();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
async runMessageConfirm(confirm) {
|
|
148
|
+
const palette = this.state.palette;
|
|
149
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
150
|
+
if (!palette || !roomId)
|
|
151
|
+
return;
|
|
152
|
+
const id = confirm.data.id;
|
|
153
|
+
if (!id)
|
|
154
|
+
return;
|
|
155
|
+
palette.searching = true;
|
|
156
|
+
palette.error = "";
|
|
138
157
|
this.touch();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.touch();
|
|
173
|
-
} catch (error) {
|
|
174
|
-
if (this.state.palette === palette) {
|
|
175
|
-
palette.searching = false;
|
|
176
|
-
palette.error = errorText(error);
|
|
177
|
-
this.touch();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
}
|
|
158
|
+
try {
|
|
159
|
+
if (confirm.action === "message-recall") {
|
|
160
|
+
await this.api.recall(roomId, id, this.sessionID);
|
|
161
|
+
const target = this.state.messages.find((message) => message.id === id);
|
|
162
|
+
if (target)
|
|
163
|
+
target.recalledAt = Date.now();
|
|
164
|
+
this.closePalette();
|
|
165
|
+
this.setStatus(t("message.recalledStatus", { id }), "success");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const revealed = await this.api.reveal(roomId, id, this.sessionID);
|
|
169
|
+
palette.mode = "detail";
|
|
170
|
+
palette.title = t("message.revealed");
|
|
171
|
+
palette.confirm = null;
|
|
172
|
+
palette.detail = {
|
|
173
|
+
title: t("message.revealed"),
|
|
174
|
+
markdown: String(revealed?.text ?? t("message.empty")),
|
|
175
|
+
kind: "revealed-message",
|
|
176
|
+
};
|
|
177
|
+
palette.hint = t("palette.closeHint");
|
|
178
|
+
palette.searching = false;
|
|
179
|
+
this.touch();
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (this.state.palette === palette) {
|
|
183
|
+
palette.searching = false;
|
|
184
|
+
palette.error = errorText(error);
|
|
185
|
+
this.touch();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|