@celljs/ta-rooms 0.0.0-stage → 4.12.0
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/README.en.md +29 -0
- package/README.md +28 -2
- package/extension/index.mjs +362 -0
- package/host/index.mjs +966 -0
- package/package.json +54 -4
- package/web/index.js +3165 -0
package/web/index.js
ADDED
|
@@ -0,0 +1,3165 @@
|
|
|
1
|
+
// ../ta-relay/esm/common/relay-bytes.js
|
|
2
|
+
var RelayBytes;
|
|
3
|
+
(function(RelayBytes2) {
|
|
4
|
+
function random(length) {
|
|
5
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(length));
|
|
6
|
+
}
|
|
7
|
+
RelayBytes2.random = random;
|
|
8
|
+
function toBase64(bytes) {
|
|
9
|
+
let binary = "";
|
|
10
|
+
for (const byte of bytes) {
|
|
11
|
+
binary += String.fromCharCode(byte);
|
|
12
|
+
}
|
|
13
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
14
|
+
}
|
|
15
|
+
RelayBytes2.toBase64 = toBase64;
|
|
16
|
+
function fromBase64(text) {
|
|
17
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text)) {
|
|
18
|
+
throw new Error("Not base64url.");
|
|
19
|
+
}
|
|
20
|
+
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
|
|
21
|
+
const bytes = new Uint8Array(binary.length);
|
|
22
|
+
for (let i = 0;i < binary.length; i++) {
|
|
23
|
+
bytes[i] = binary.charCodeAt(i);
|
|
24
|
+
}
|
|
25
|
+
return bytes;
|
|
26
|
+
}
|
|
27
|
+
RelayBytes2.fromBase64 = fromBase64;
|
|
28
|
+
function concat(...parts) {
|
|
29
|
+
const bytes = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
|
|
30
|
+
let offset = 0;
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
bytes.set(part, offset);
|
|
33
|
+
offset += part.length;
|
|
34
|
+
}
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
RelayBytes2.concat = concat;
|
|
38
|
+
})(RelayBytes || (RelayBytes = {}));
|
|
39
|
+
|
|
40
|
+
// ../ta-relay/esm/common/relay-identity.js
|
|
41
|
+
var encoder = new TextEncoder;
|
|
42
|
+
var decoder = new TextDecoder;
|
|
43
|
+
var subtle = () => globalThis.crypto.subtle;
|
|
44
|
+
var SIGN = { name: "ECDSA", namedCurve: "P-256" };
|
|
45
|
+
var BOX = { name: "ECDH", namedCurve: "P-256" };
|
|
46
|
+
var SIGNATURE = { name: "ECDSA", hash: "SHA-256" };
|
|
47
|
+
var RelayKeys;
|
|
48
|
+
(function(RelayKeys2) {
|
|
49
|
+
async function hkdf(key, salt, info) {
|
|
50
|
+
const secret = await subtle().importKey("raw", key, "HKDF", false, ["deriveBits"]);
|
|
51
|
+
const bits = await subtle().deriveBits({ name: "HKDF", hash: "SHA-256", salt, info: encoder.encode(info) }, secret, 256);
|
|
52
|
+
return new Uint8Array(bits);
|
|
53
|
+
}
|
|
54
|
+
RelayKeys2.hkdf = hkdf;
|
|
55
|
+
async function sha256(bytes) {
|
|
56
|
+
const data = typeof bytes === "string" ? encoder.encode(bytes) : bytes;
|
|
57
|
+
return new Uint8Array(await subtle().digest("SHA-256", data));
|
|
58
|
+
}
|
|
59
|
+
RelayKeys2.sha256 = sha256;
|
|
60
|
+
async function hash(text) {
|
|
61
|
+
return RelayBytes.toBase64(await sha256(text));
|
|
62
|
+
}
|
|
63
|
+
RelayKeys2.hash = hash;
|
|
64
|
+
async function hmac(key, text) {
|
|
65
|
+
const imported = await subtle().importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
66
|
+
return RelayBytes.toBase64(new Uint8Array(await subtle().sign("HMAC", imported, encoder.encode(text))));
|
|
67
|
+
}
|
|
68
|
+
RelayKeys2.hmac = hmac;
|
|
69
|
+
function aesKey(key) {
|
|
70
|
+
return subtle().importKey("raw", key, "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
71
|
+
}
|
|
72
|
+
RelayKeys2.aesKey = aesKey;
|
|
73
|
+
async function seal(key, text) {
|
|
74
|
+
const iv = RelayBytes.random(12);
|
|
75
|
+
const sealed = await subtle().encrypt({ name: "AES-GCM", iv }, key, encoder.encode(text));
|
|
76
|
+
return RelayBytes.toBase64(RelayBytes.concat(iv, new Uint8Array(sealed)));
|
|
77
|
+
}
|
|
78
|
+
RelayKeys2.seal = seal;
|
|
79
|
+
async function open(key, sealed) {
|
|
80
|
+
const bytes = RelayBytes.fromBase64(sealed);
|
|
81
|
+
const opened = await subtle().decrypt({ name: "AES-GCM", iv: bytes.subarray(0, 12) }, key, bytes.subarray(12));
|
|
82
|
+
return decoder.decode(opened);
|
|
83
|
+
}
|
|
84
|
+
RelayKeys2.open = open;
|
|
85
|
+
})(RelayKeys || (RelayKeys = {}));
|
|
86
|
+
var RelayIdentityUtil;
|
|
87
|
+
(function(RelayIdentityUtil2) {
|
|
88
|
+
async function create(name, now = Date.now()) {
|
|
89
|
+
const sign2 = await subtle().generateKey(SIGN, true, ["sign", "verify"]);
|
|
90
|
+
const box = await subtle().generateKey(BOX, true, ["deriveBits"]);
|
|
91
|
+
const raw = async (key) => RelayBytes.toBase64(new Uint8Array(await subtle().exportKey("raw", key)));
|
|
92
|
+
const [signPublic, boxPublic] = await Promise.all([raw(sign2.publicKey), raw(box.publicKey)]);
|
|
93
|
+
return {
|
|
94
|
+
id: await id(signPublic, boxPublic),
|
|
95
|
+
name,
|
|
96
|
+
sign: signPublic,
|
|
97
|
+
box: boxPublic,
|
|
98
|
+
signKey: await subtle().exportKey("jwk", sign2.privateKey),
|
|
99
|
+
boxKey: await subtle().exportKey("jwk", box.privateKey),
|
|
100
|
+
createdAt: now
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
RelayIdentityUtil2.create = create;
|
|
104
|
+
async function id(sign2, box) {
|
|
105
|
+
const digest = await RelayKeys.sha256(RelayBytes.concat(RelayBytes.fromBase64(sign2), RelayBytes.fromBase64(box)));
|
|
106
|
+
return RelayBytes.toBase64(digest.subarray(0, 16));
|
|
107
|
+
}
|
|
108
|
+
RelayIdentityUtil2.id = id;
|
|
109
|
+
async function check(identity) {
|
|
110
|
+
try {
|
|
111
|
+
if (identity.id !== await id(identity.sign, identity.box)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
await Promise.all([importSign(identity.sign), importBox(identity.box)]);
|
|
115
|
+
return true;
|
|
116
|
+
} catch (_a) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
RelayIdentityUtil2.check = check;
|
|
121
|
+
function publicOf(identity) {
|
|
122
|
+
return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
|
|
123
|
+
}
|
|
124
|
+
RelayIdentityUtil2.publicOf = publicOf;
|
|
125
|
+
async function sign(identity, text) {
|
|
126
|
+
const key = await subtle().importKey("jwk", identity.signKey, SIGN, false, ["sign"]);
|
|
127
|
+
return RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
|
|
128
|
+
}
|
|
129
|
+
RelayIdentityUtil2.sign = sign;
|
|
130
|
+
async function verify(signPublic, text, signature) {
|
|
131
|
+
try {
|
|
132
|
+
return await subtle().verify(SIGNATURE, await importSign(signPublic), RelayBytes.fromBase64(signature), encoder.encode(text));
|
|
133
|
+
} catch (_a) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
RelayIdentityUtil2.verify = verify;
|
|
138
|
+
async function agree(identity, otherBox, salt, info) {
|
|
139
|
+
const own = await subtle().importKey("jwk", identity.boxKey, BOX, false, ["deriveBits"]);
|
|
140
|
+
const shared = await subtle().deriveBits({ name: "ECDH", public: await importBox(otherBox) }, own, 256);
|
|
141
|
+
return RelayKeys.hkdf(new Uint8Array(shared), encoder.encode(salt), info);
|
|
142
|
+
}
|
|
143
|
+
RelayIdentityUtil2.agree = agree;
|
|
144
|
+
function importSign(raw) {
|
|
145
|
+
return subtle().importKey("raw", RelayBytes.fromBase64(raw), SIGN, false, ["verify"]);
|
|
146
|
+
}
|
|
147
|
+
function importBox(raw) {
|
|
148
|
+
return subtle().importKey("raw", RelayBytes.fromBase64(raw), BOX, false, []);
|
|
149
|
+
}
|
|
150
|
+
})(RelayIdentityUtil || (RelayIdentityUtil = {}));
|
|
151
|
+
|
|
152
|
+
// ../ta-relay/esm/common/relay-protocol.js
|
|
153
|
+
var RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'";
|
|
154
|
+
var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
|
|
155
|
+
var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
|
|
156
|
+
var RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
|
|
157
|
+
var RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
|
|
158
|
+
var RELAY_ID = /^[A-Za-z0-9_-]{16,64}$/;
|
|
159
|
+
var RelayCloseCode;
|
|
160
|
+
(function(RelayCloseCode2) {
|
|
161
|
+
RelayCloseCode2[RelayCloseCode2["HOST_OFFLINE"] = 4404] = "HOST_OFFLINE";
|
|
162
|
+
RelayCloseCode2[RelayCloseCode2["REFUSED"] = 4401] = "REFUSED";
|
|
163
|
+
RelayCloseCode2[RelayCloseCode2["REPLACED"] = 4409] = "REPLACED";
|
|
164
|
+
RelayCloseCode2[RelayCloseCode2["CLOSED_BY_HOST"] = 4410] = "CLOSED_BY_HOST";
|
|
165
|
+
RelayCloseCode2[RelayCloseCode2["FULL"] = 4429] = "FULL";
|
|
166
|
+
RelayCloseCode2[RelayCloseCode2["TIMEOUT"] = 4408] = "TIMEOUT";
|
|
167
|
+
})(RelayCloseCode || (RelayCloseCode = {}));
|
|
168
|
+
var RELAY_ROOM_PATH = "/r";
|
|
169
|
+
var RELAY_HUB_MAX_VALUE = 96 * 1024;
|
|
170
|
+
var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
171
|
+
|
|
172
|
+
// ../ta-relay/esm/common/relay-hub-util.js
|
|
173
|
+
var RelayHubUtil;
|
|
174
|
+
(function(RelayHubUtil2) {
|
|
175
|
+
function link(link2) {
|
|
176
|
+
const fragment = new URLSearchParams({ v: "1", r: link2.room, i: link2.invite, o: link2.owner, n: link2.title, by: link2.by });
|
|
177
|
+
return `${link2.relay}${RELAY_ROOM_PATH}#${fragment}`;
|
|
178
|
+
}
|
|
179
|
+
RelayHubUtil2.link = link;
|
|
180
|
+
function is(text) {
|
|
181
|
+
try {
|
|
182
|
+
parse(text);
|
|
183
|
+
return true;
|
|
184
|
+
} catch (_a) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
RelayHubUtil2.is = is;
|
|
189
|
+
function parse(text) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
const url = new URL(text.trim());
|
|
192
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
193
|
+
const [room, invite, owner] = ["r", "i", "o"].map((name) => {
|
|
194
|
+
var _a2;
|
|
195
|
+
return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
|
|
196
|
+
});
|
|
197
|
+
if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_ROOM_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(room) || !/^[A-Za-z0-9_-]{43}$/.test(invite) || !/^[A-Za-z0-9_-]{22}$/.test(owner)) {
|
|
198
|
+
throw new Error("Not a link inviting into a room of Ta.");
|
|
199
|
+
}
|
|
200
|
+
return { relay: url.origin, room, invite, owner, title: ((_a = fragment.get("n")) !== null && _a !== undefined ? _a : "").slice(0, 200), by: ((_b = fragment.get("by")) !== null && _b !== undefined ? _b : "").slice(0, 100) };
|
|
201
|
+
}
|
|
202
|
+
RelayHubUtil2.parse = parse;
|
|
203
|
+
function randomId() {
|
|
204
|
+
return RelayBytes.toBase64(RelayBytes.random(16));
|
|
205
|
+
}
|
|
206
|
+
RelayHubUtil2.randomId = randomId;
|
|
207
|
+
function randomKey() {
|
|
208
|
+
return RelayBytes.toBase64(RelayBytes.random(32));
|
|
209
|
+
}
|
|
210
|
+
RelayHubUtil2.randomKey = randomKey;
|
|
211
|
+
async function keys(roomKey) {
|
|
212
|
+
const key = RelayBytes.fromBase64(roomKey);
|
|
213
|
+
const none = new Uint8Array(0);
|
|
214
|
+
return {
|
|
215
|
+
seal: await RelayKeys.aesKey(await RelayKeys.hkdf(key, none, "ta-room/1 seal")),
|
|
216
|
+
names: await RelayKeys.hkdf(key, none, "ta-room/1 key")
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
RelayHubUtil2.keys = keys;
|
|
220
|
+
async function keyId(keys2, name) {
|
|
221
|
+
return (await RelayKeys.hmac(keys2.names, name)).slice(0, 22);
|
|
222
|
+
}
|
|
223
|
+
RelayHubUtil2.keyId = keyId;
|
|
224
|
+
async function inviteProof(invite) {
|
|
225
|
+
return RelayBytes.toBase64(await RelayKeys.hkdf(RelayBytes.fromBase64(invite), new Uint8Array(0), "ta-room/1 ask auth"));
|
|
226
|
+
}
|
|
227
|
+
RelayHubUtil2.inviteProof = inviteProof;
|
|
228
|
+
async function inviteKey(invite) {
|
|
229
|
+
return RelayKeys.aesKey(await RelayKeys.hkdf(RelayBytes.fromBase64(invite), new Uint8Array(0), "ta-room/1 ask seal"));
|
|
230
|
+
}
|
|
231
|
+
RelayHubUtil2.inviteKey = inviteKey;
|
|
232
|
+
async function seal(key, identity, member, body, at = Date.now()) {
|
|
233
|
+
const p = JSON.stringify({ m: member, at, b: body });
|
|
234
|
+
return RelayKeys.seal(key, JSON.stringify({ p, s: await RelayIdentityUtil.sign(identity, p) }));
|
|
235
|
+
}
|
|
236
|
+
RelayHubUtil2.seal = seal;
|
|
237
|
+
async function open(key, sealed, signOf, options = {}) {
|
|
238
|
+
var _a;
|
|
239
|
+
try {
|
|
240
|
+
const envelope = JSON.parse(await RelayKeys.open(key, sealed));
|
|
241
|
+
const signed = JSON.parse(envelope.p);
|
|
242
|
+
const sign = typeof signed.m === "string" ? signOf(signed.m) : undefined;
|
|
243
|
+
if (!sign || !await RelayIdentityUtil.verify(sign, envelope.p, envelope.s)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (options.skewMs !== undefined && Math.abs(((_a = options.now) !== null && _a !== undefined ? _a : Date.now()) - Number(signed.at)) > options.skewMs) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
return signed;
|
|
250
|
+
} catch (_b) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
RelayHubUtil2.open = open;
|
|
255
|
+
async function sealAsk(invite, identity, member, at = Date.now(), guest = false) {
|
|
256
|
+
const body = { ...RelayIdentityUtil.publicOf(identity), member, at, ...guest ? { guest: true } : {} };
|
|
257
|
+
return seal(await inviteKey(invite), identity, member, body, at);
|
|
258
|
+
}
|
|
259
|
+
RelayHubUtil2.sealAsk = sealAsk;
|
|
260
|
+
async function openAsk(invite, sealed) {
|
|
261
|
+
try {
|
|
262
|
+
const envelope = JSON.parse(await RelayKeys.open(await inviteKey(invite), sealed));
|
|
263
|
+
const signed = JSON.parse(envelope.p);
|
|
264
|
+
const body = signed.b;
|
|
265
|
+
if (!body || signed.m !== body.member || !RELAY_ID.test(String(body.member)) || !await RelayIdentityUtil.check(body) || !await RelayIdentityUtil.verify(body.sign, envelope.p, envelope.s)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
...RelayIdentityUtil.publicOf(body),
|
|
270
|
+
name: String(body.name).slice(0, 100),
|
|
271
|
+
member: body.member,
|
|
272
|
+
at: Number(body.at),
|
|
273
|
+
...body.guest === true ? { guest: true } : {}
|
|
274
|
+
};
|
|
275
|
+
} catch (_a) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
RelayHubUtil2.openAsk = openAsk;
|
|
280
|
+
async function sealAnswer(owner, room, ask, body, invite) {
|
|
281
|
+
const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(owner, ask.box, room, "ta-room/1 answer"));
|
|
282
|
+
const d = await RelayKeys.seal(key, JSON.stringify(body));
|
|
283
|
+
const signed = `${room}
|
|
284
|
+
${ask.member}
|
|
285
|
+
${d}`;
|
|
286
|
+
const answer = JSON.stringify({ owner: RelayIdentityUtil.publicOf(owner), d, s: await RelayIdentityUtil.sign(owner, signed) });
|
|
287
|
+
return RelayKeys.seal(await inviteKey(invite), answer);
|
|
288
|
+
}
|
|
289
|
+
RelayHubUtil2.sealAnswer = sealAnswer;
|
|
290
|
+
async function openAnswer(identity, room, member, ownerId, answer, invite) {
|
|
291
|
+
try {
|
|
292
|
+
const { owner, d, s } = JSON.parse(await RelayKeys.open(await inviteKey(invite), answer));
|
|
293
|
+
if (owner.id !== ownerId || !await RelayIdentityUtil.check(owner) || !await RelayIdentityUtil.verify(owner.sign, `${room}
|
|
294
|
+
${member}
|
|
295
|
+
${d}`, s)) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(identity, owner.box, room, "ta-room/1 answer"));
|
|
299
|
+
const body = JSON.parse(await RelayKeys.open(key, d));
|
|
300
|
+
RelayBytes.fromBase64(body.key);
|
|
301
|
+
return { owner: { ...RelayIdentityUtil.publicOf(owner), name: String(owner.name).slice(0, 100) }, body };
|
|
302
|
+
} catch (_a) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
RelayHubUtil2.openAnswer = openAnswer;
|
|
307
|
+
})(RelayHubUtil || (RelayHubUtil = {}));
|
|
308
|
+
|
|
309
|
+
// ../ta-relay/esm/common/relay-room-chat.js
|
|
310
|
+
var RELAY_CHAT_KEY = "chat:";
|
|
311
|
+
var RELAY_CHAT_PART_BYTES = 8 * 1024;
|
|
312
|
+
var RELAY_CHAT_PARTS = 6;
|
|
313
|
+
var RELAY_CHAT_TEXT_MAX = 2000;
|
|
314
|
+
var TRIES = 6;
|
|
315
|
+
var RelayRoomChatUtil;
|
|
316
|
+
(function(RelayRoomChatUtil2) {
|
|
317
|
+
function key(member, part) {
|
|
318
|
+
return `${RELAY_CHAT_KEY}${member}:${part}`;
|
|
319
|
+
}
|
|
320
|
+
RelayRoomChatUtil2.key = key;
|
|
321
|
+
function parse(key2) {
|
|
322
|
+
const match = /^chat:([^:]+):(\d+)$/.exec(key2);
|
|
323
|
+
return match ? { member: match[1], part: Number(match[2]) } : undefined;
|
|
324
|
+
}
|
|
325
|
+
RelayRoomChatUtil2.parse = parse;
|
|
326
|
+
function lines(member, value, by) {
|
|
327
|
+
if (by !== member || !Array.isArray(value)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const lines2 = [];
|
|
331
|
+
for (const line of value) {
|
|
332
|
+
if (line && typeof line.id === "string" && typeof line.text === "string" && typeof line.at === "number") {
|
|
333
|
+
lines2.push({ id: line.id, from: member, name: typeof line.name === "string" ? line.name : "", text: line.text, at: line.at, ...extra(line) });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return lines2;
|
|
337
|
+
}
|
|
338
|
+
RelayRoomChatUtil2.lines = lines;
|
|
339
|
+
function extra(line) {
|
|
340
|
+
const to = Array.isArray(line.to) ? line.to.filter((each) => typeof each === "string").slice(0, 16) : [];
|
|
341
|
+
const agent = line.agent;
|
|
342
|
+
return {
|
|
343
|
+
...line.double === true ? { double: true } : {},
|
|
344
|
+
...agent && typeof agent.id === "string" && agent.id && typeof agent.name === "string" && line.double !== true ? { agent: { id: agent.id.slice(0, 64), name: agent.name.slice(0, 64) } } : {},
|
|
345
|
+
...to.length ? { to } : {},
|
|
346
|
+
...typeof line.re === "string" ? { re: line.re } : {}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
RelayRoomChatUtil2.extra = extra;
|
|
350
|
+
function stored(lines2) {
|
|
351
|
+
return lines2.map(({ from: _from, ...line }) => line);
|
|
352
|
+
}
|
|
353
|
+
RelayRoomChatUtil2.stored = stored;
|
|
354
|
+
function bytes(lines2) {
|
|
355
|
+
return new TextEncoder().encode(JSON.stringify(lines2)).length;
|
|
356
|
+
}
|
|
357
|
+
RelayRoomChatUtil2.bytes = bytes;
|
|
358
|
+
function id() {
|
|
359
|
+
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
360
|
+
}
|
|
361
|
+
RelayRoomChatUtil2.id = id;
|
|
362
|
+
})(RelayRoomChatUtil || (RelayRoomChatUtil = {}));
|
|
363
|
+
|
|
364
|
+
class RelayRoomChat {
|
|
365
|
+
constructor(rooms, room) {
|
|
366
|
+
this.rooms = rooms;
|
|
367
|
+
this.room = room;
|
|
368
|
+
this.parts = new Map;
|
|
369
|
+
this.listeners = new Set;
|
|
370
|
+
this.all = [];
|
|
371
|
+
}
|
|
372
|
+
get lines() {
|
|
373
|
+
return this.all;
|
|
374
|
+
}
|
|
375
|
+
subscribe(listener) {
|
|
376
|
+
this.listeners.add(listener);
|
|
377
|
+
return () => this.listeners.delete(listener);
|
|
378
|
+
}
|
|
379
|
+
async load() {
|
|
380
|
+
const state = await this.rooms.getState(this.room, RELAY_CHAT_KEY);
|
|
381
|
+
this.parts.clear();
|
|
382
|
+
for (const [key, value] of Object.entries(state)) {
|
|
383
|
+
this.put(key, value);
|
|
384
|
+
}
|
|
385
|
+
this.changed();
|
|
386
|
+
}
|
|
387
|
+
heard(key, value) {
|
|
388
|
+
if (!RelayRoomChatUtil.parse(key)) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
const known = this.parts.get(key);
|
|
392
|
+
if (known && known.version >= value.version) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
this.put(key, value);
|
|
396
|
+
this.changed();
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
async say(text, self, extra = {}) {
|
|
400
|
+
var _a;
|
|
401
|
+
var _b, _c;
|
|
402
|
+
const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
|
|
403
|
+
if (!said) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
for (let tries = 0;tries < TRIES; tries++) {
|
|
407
|
+
const latest = this.latest(self.member);
|
|
408
|
+
const last = latest === null || latest === undefined ? undefined : latest.lines[latest.lines.length - 1];
|
|
409
|
+
const at = Math.max(Date.now(), ((_b = last === null || last === undefined ? undefined : last.at) !== null && _b !== undefined ? _b : 0) + 1);
|
|
410
|
+
const line = {
|
|
411
|
+
id: RelayRoomChatUtil.id(),
|
|
412
|
+
from: self.member,
|
|
413
|
+
name: self.name,
|
|
414
|
+
text: said,
|
|
415
|
+
at,
|
|
416
|
+
...RelayRoomChatUtil.extra(extra)
|
|
417
|
+
};
|
|
418
|
+
const fits = latest && RelayRoomChatUtil.bytes(RelayRoomChatUtil.stored([...latest.lines, line])) <= RELAY_CHAT_PART_BYTES;
|
|
419
|
+
const part = !latest ? 0 : fits ? latest.part : latest.part + 1;
|
|
420
|
+
const lines = fits && latest ? [...latest.lines, line] : [line];
|
|
421
|
+
const key = RelayRoomChatUtil.key(self.member, part);
|
|
422
|
+
const value = RelayRoomChatUtil.stored(lines);
|
|
423
|
+
const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === undefined ? undefined : _a.version) !== null && _c !== undefined ? _c : 0);
|
|
424
|
+
if (result.ok) {
|
|
425
|
+
this.put(key, { value, version: result.version, by: self.member });
|
|
426
|
+
this.changed();
|
|
427
|
+
if (part >= RELAY_CHAT_PARTS) {
|
|
428
|
+
this.clear(RelayRoomChatUtil.key(self.member, part - RELAY_CHAT_PARTS));
|
|
429
|
+
}
|
|
430
|
+
return line;
|
|
431
|
+
}
|
|
432
|
+
await this.load();
|
|
433
|
+
}
|
|
434
|
+
throw new Error("The room is busy: say it again.");
|
|
435
|
+
}
|
|
436
|
+
async clear(key) {
|
|
437
|
+
await this.rooms.setState(this.room, key, null).catch(() => {
|
|
438
|
+
return;
|
|
439
|
+
});
|
|
440
|
+
if (this.parts.delete(key)) {
|
|
441
|
+
this.changed();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
latest(member) {
|
|
445
|
+
let latest;
|
|
446
|
+
for (const part of this.parts.values()) {
|
|
447
|
+
if (part.member === member && (!latest || part.part > latest.part)) {
|
|
448
|
+
latest = part;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return latest;
|
|
452
|
+
}
|
|
453
|
+
put(key, value) {
|
|
454
|
+
const parsed = RelayRoomChatUtil.parse(key);
|
|
455
|
+
const lines = parsed && value.value !== null ? RelayRoomChatUtil.lines(parsed.member, value.value, value.by) : undefined;
|
|
456
|
+
if (!parsed || !lines) {
|
|
457
|
+
this.parts.delete(key);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
this.parts.set(key, { ...parsed, lines, version: value.version });
|
|
461
|
+
}
|
|
462
|
+
changed() {
|
|
463
|
+
this.all = [...this.parts.values()].flatMap((part) => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
464
|
+
for (const listener of this.listeners) {
|
|
465
|
+
listener();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// web-src/double-protocol.ts
|
|
471
|
+
var ROOM_AGENTS_KEY = "agents:";
|
|
472
|
+
var RoomAgentsUtil;
|
|
473
|
+
((RoomAgentsUtil) => {
|
|
474
|
+
function key(member) {
|
|
475
|
+
return `${ROOM_AGENTS_KEY}${member}`;
|
|
476
|
+
}
|
|
477
|
+
RoomAgentsUtil.key = key;
|
|
478
|
+
function address(member, agent) {
|
|
479
|
+
return `${member}/${agent}`;
|
|
480
|
+
}
|
|
481
|
+
RoomAgentsUtil.address = address;
|
|
482
|
+
function list(member, value, by) {
|
|
483
|
+
if (by !== member || !Array.isArray(value)) {
|
|
484
|
+
return [];
|
|
485
|
+
}
|
|
486
|
+
return value.filter((agent) => agent && typeof agent.id === "string" && agent.id && typeof agent.name === "string").slice(0, 16).map((agent) => ({
|
|
487
|
+
id: agent.id,
|
|
488
|
+
name: agent.name,
|
|
489
|
+
...typeof agent.role === "string" && agent.role ? { role: agent.role } : {},
|
|
490
|
+
...Number.isInteger(agent.face) && agent.face >= 0 && agent.face < 64 ? { face: agent.face } : {}
|
|
491
|
+
}));
|
|
492
|
+
}
|
|
493
|
+
RoomAgentsUtil.list = list;
|
|
494
|
+
function of(state) {
|
|
495
|
+
return Object.entries(state).flatMap(([key2, value]) => {
|
|
496
|
+
if (!key2.startsWith(ROOM_AGENTS_KEY) || value.value === null) {
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
const member = key2.slice(ROOM_AGENTS_KEY.length);
|
|
500
|
+
return list(member, value.value, value.by).map((agent) => ({ ...agent, member }));
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
RoomAgentsUtil.of = of;
|
|
504
|
+
})(RoomAgentsUtil ||= {});
|
|
505
|
+
var ROOM_CAPABILITIES = ["files", "commands"];
|
|
506
|
+
var DoubleKeys;
|
|
507
|
+
((DoubleKeys) => {
|
|
508
|
+
DoubleKeys.QUIET = "doubles.quiet";
|
|
509
|
+
DoubleKeys.GRANTS = "doubles.grants";
|
|
510
|
+
DoubleKeys.ASKS = "doubles.asks";
|
|
511
|
+
DoubleKeys.LOG = "doubles.log";
|
|
512
|
+
DoubleKeys.SESSIONS = "doubles.sessions";
|
|
513
|
+
DoubleKeys.READ = "doubles.read";
|
|
514
|
+
})(DoubleKeys ||= {});
|
|
515
|
+
var GRANT_HOURS = [1, 24, 24 * 7];
|
|
516
|
+
|
|
517
|
+
// web-src/i18n.ts
|
|
518
|
+
var EN = {
|
|
519
|
+
roomsTitle: "Rooms",
|
|
520
|
+
add: "New",
|
|
521
|
+
me: "Your name in rooms",
|
|
522
|
+
meLine: "In rooms you are “{name}”",
|
|
523
|
+
rename: "Change",
|
|
524
|
+
renamePlaceholder: "What others see",
|
|
525
|
+
requests: "Asking to join",
|
|
526
|
+
requestLine: "wants to join “{title}”",
|
|
527
|
+
friendTag: "Ta friend",
|
|
528
|
+
newTag: "New",
|
|
529
|
+
guestTag: "Web guest",
|
|
530
|
+
requestGuest: "They ask from a browser, without Ta: let in, they only chat, and are not a Ta friend.",
|
|
531
|
+
accept: "Let in",
|
|
532
|
+
refuse: "Refuse",
|
|
533
|
+
requestBody: "{name} wants to join your room “{title}”.",
|
|
534
|
+
requestsBody: "{n} people ask to join your rooms.",
|
|
535
|
+
requestFriend: "You were in a room together before.",
|
|
536
|
+
requestNew: "You have not met in a room before: let in only someone you know.",
|
|
537
|
+
requestWhat: "Once in, they see the messages and the shared state of the room: in a game, where everyone is and what is built.",
|
|
538
|
+
later: "Later",
|
|
539
|
+
ownRoom: "Your room",
|
|
540
|
+
roomOf: "A room of {name}",
|
|
541
|
+
people: "{n} people · {online} online",
|
|
542
|
+
othersOnline: "{n} more online",
|
|
543
|
+
nobodyOnline: "Nobody else online",
|
|
544
|
+
said: "{name}: {text}",
|
|
545
|
+
yesterday: "Yesterday",
|
|
546
|
+
waiting: "Waiting for {name} to let you in",
|
|
547
|
+
refused: "{name} did not let you in",
|
|
548
|
+
closed: "Closed by its owner",
|
|
549
|
+
removed: "You were taken out",
|
|
550
|
+
inviteGone: "The invitation no longer works",
|
|
551
|
+
connecting: "Connecting…",
|
|
552
|
+
invite: "Invite",
|
|
553
|
+
inviteLine: "A link or a QR code; you let them in",
|
|
554
|
+
inviteTitle: "Invite into “{title}”",
|
|
555
|
+
inviteHint: "Send the link: opened in a browser, it asks to chat as a web guest; in the Ta app (scan or paste), to join with Ta. You let in who asks; the link works for 7 days, and a new one stops it.",
|
|
556
|
+
newLink: "New link",
|
|
557
|
+
making: "Making the link…",
|
|
558
|
+
copy: "Copy link",
|
|
559
|
+
copied: "Copied",
|
|
560
|
+
send: "Send…",
|
|
561
|
+
qr: "QR code of the invitation",
|
|
562
|
+
members: "Members",
|
|
563
|
+
memberCount: "{n} members",
|
|
564
|
+
onlineCount: "{n} online",
|
|
565
|
+
membersTitle: "Members of the room",
|
|
566
|
+
membersCount: "{n} members · {online} online",
|
|
567
|
+
noRoomOpen: "Open a room to see who is in it",
|
|
568
|
+
you: "You",
|
|
569
|
+
owner: "Owner",
|
|
570
|
+
online: "Online",
|
|
571
|
+
offline: "Offline",
|
|
572
|
+
remove: "Take out",
|
|
573
|
+
removeTitle: "Take {name} out of “{title}”?",
|
|
574
|
+
removeHint: "They are disconnected at once, and come back only by a new invitation.",
|
|
575
|
+
leave: "Leave the room",
|
|
576
|
+
leaveTitle: "Leave “{title}”?",
|
|
577
|
+
leaveHint: "You come back only by a new invitation.",
|
|
578
|
+
close: "Close the room",
|
|
579
|
+
closeTitle: "Close “{title}” for everyone?",
|
|
580
|
+
closeHint: "Everyone is taken out, and the relay deletes all the room kept.",
|
|
581
|
+
forget: "Remove",
|
|
582
|
+
friends: "Ta friends",
|
|
583
|
+
friendLine: "In {rooms}",
|
|
584
|
+
removeFriend: "Remove",
|
|
585
|
+
removeFriendTitle: "Remove {name} from your Ta friends?",
|
|
586
|
+
removeFriendHint: "The rooms you share stay as they are.",
|
|
587
|
+
emptyTitle: "No rooms yet",
|
|
588
|
+
emptyHint: "No rooms yet. Make one with + and invite friends to chat, or open a link someone sent you to ask to join theirs.",
|
|
589
|
+
pickRoom: "Pick a room to chat in",
|
|
590
|
+
joinTitle: "Join “{title}”?",
|
|
591
|
+
joinBody: "A room of {by}. They let you in first, and your name “{name}” goes to them.",
|
|
592
|
+
joinAction: "Ask to join",
|
|
593
|
+
joinByLink: "Join by a link",
|
|
594
|
+
joinByLinkPlaceholder: "Paste the link of the invitation",
|
|
595
|
+
scan: "Scan a code",
|
|
596
|
+
scanHint: "Scan the QR code of an invitation",
|
|
597
|
+
notInvite: "That is not a link that invites into a room.",
|
|
598
|
+
asked: "Asked {by}: you are in once they let you in.",
|
|
599
|
+
admitted: "You are in “{title}”.",
|
|
600
|
+
refusedNotice: "{by} did not let you into “{title}”.",
|
|
601
|
+
removedNotice: "You were taken out of “{title}”.",
|
|
602
|
+
closedNotice: "“{title}” was closed by its owner.",
|
|
603
|
+
oldApp: "Update the Ta app to use rooms.",
|
|
604
|
+
room: "Room",
|
|
605
|
+
newRoom: "New room",
|
|
606
|
+
newRoomPlaceholder: "Its name, which those you invite see",
|
|
607
|
+
roomOfName: "{name}’s room",
|
|
608
|
+
back: "Back",
|
|
609
|
+
openPage: "Open {name}",
|
|
610
|
+
pageLine: "A room of {name}: play in it together",
|
|
611
|
+
chatEmpty: "Nothing said yet. Only those in the room read it: the relay keeps it sealed.",
|
|
612
|
+
chatPlaceholder: "Message",
|
|
613
|
+
showOnHome: "Show rooms on the double's home",
|
|
614
|
+
showOnHomeHint: "With rooms, the double's home has a Rooms section, beside members and channels."
|
|
615
|
+
};
|
|
616
|
+
var ZH = {
|
|
617
|
+
roomsTitle: "房间",
|
|
618
|
+
add: "新建",
|
|
619
|
+
me: "我在房间里的名字",
|
|
620
|
+
meLine: "你在房间里叫「{name}」",
|
|
621
|
+
rename: "修改",
|
|
622
|
+
renamePlaceholder: "别人看到的名字",
|
|
623
|
+
requests: "加入申请",
|
|
624
|
+
requestLine: "想加入「{title}」",
|
|
625
|
+
friendTag: "Ta 好友",
|
|
626
|
+
newTag: "新朋友",
|
|
627
|
+
guestTag: "网页访客",
|
|
628
|
+
requestGuest: "对方是用浏览器申请的,没有装 Ta:进来后只能聊天,也不会成为 Ta 好友。",
|
|
629
|
+
accept: "同意",
|
|
630
|
+
refuse: "拒绝",
|
|
631
|
+
requestBody: "「{name}」想加入你的房间「{title}」。",
|
|
632
|
+
requestsBody: "有 {n} 人申请加入你的房间。",
|
|
633
|
+
requestFriend: "你们之前在同一个房间待过。",
|
|
634
|
+
requestNew: "你们还没在房间里见过:只让认识的人进来。",
|
|
635
|
+
requestWhat: "进来后,对方能看到房间里的消息和共享的内容;在游戏里就是大家的位置和搭的东西。",
|
|
636
|
+
later: "稍后",
|
|
637
|
+
ownRoom: "我建的房间",
|
|
638
|
+
roomOf: "{name}的房间",
|
|
639
|
+
people: "{n} 人 · {online} 人在线",
|
|
640
|
+
othersOnline: "另有 {n} 人在线",
|
|
641
|
+
nobodyOnline: "其他人都不在线",
|
|
642
|
+
said: "{name}:{text}",
|
|
643
|
+
yesterday: "昨天",
|
|
644
|
+
waiting: "等{name}同意",
|
|
645
|
+
refused: "{name}没有同意",
|
|
646
|
+
closed: "房主已解散",
|
|
647
|
+
removed: "你已被移出",
|
|
648
|
+
inviteGone: "邀请已失效",
|
|
649
|
+
connecting: "连接中…",
|
|
650
|
+
invite: "邀请",
|
|
651
|
+
inviteLine: "发链接或二维码,由你同意进入",
|
|
652
|
+
inviteTitle: "邀请加入「{title}」",
|
|
653
|
+
inviteHint: "把链接发给对方:在浏览器里打开,可以作为网页访客申请聊天;在 Ta 应用里扫码或粘贴,就用 Ta 加入。都要你同意;链接 7 天内有效,换新链接后旧的作废。",
|
|
654
|
+
newLink: "换一个链接",
|
|
655
|
+
making: "正在生成链接…",
|
|
656
|
+
copy: "复制链接",
|
|
657
|
+
copied: "已复制",
|
|
658
|
+
send: "发送…",
|
|
659
|
+
qr: "邀请二维码",
|
|
660
|
+
members: "成员",
|
|
661
|
+
memberCount: "{n} 位成员",
|
|
662
|
+
onlineCount: "{n} 人在线",
|
|
663
|
+
membersTitle: "房间成员",
|
|
664
|
+
membersCount: "{n} 位成员 · {online} 人在线",
|
|
665
|
+
noRoomOpen: "打开一个房间,这里显示它的成员",
|
|
666
|
+
you: "我",
|
|
667
|
+
owner: "房主",
|
|
668
|
+
online: "在线",
|
|
669
|
+
offline: "离线",
|
|
670
|
+
remove: "移出",
|
|
671
|
+
removeTitle: "把「{name}」移出「{title}」?",
|
|
672
|
+
removeHint: "对方会立刻断开,只有新的邀请才能再进来。",
|
|
673
|
+
leave: "退出房间",
|
|
674
|
+
leaveTitle: "退出「{title}」?",
|
|
675
|
+
leaveHint: "退出后要有新的邀请才能再进来。",
|
|
676
|
+
close: "解散房间",
|
|
677
|
+
closeTitle: "解散「{title}」?",
|
|
678
|
+
closeHint: "所有人都会被移出,中继会删除房间保存的全部内容。",
|
|
679
|
+
forget: "删除",
|
|
680
|
+
friends: "Ta 好友",
|
|
681
|
+
friendLine: "一起在:{rooms}",
|
|
682
|
+
removeFriend: "删除",
|
|
683
|
+
removeFriendTitle: "把「{name}」从 Ta 好友里删除?",
|
|
684
|
+
removeFriendHint: "一起所在的房间不受影响。",
|
|
685
|
+
emptyTitle: "还没有房间",
|
|
686
|
+
emptyHint: "还没有房间。点右上角 + 新建一个,邀请朋友来聊天;别人发来的邀请链接,点开就能申请加入。",
|
|
687
|
+
pickRoom: "选一个房间开始聊天",
|
|
688
|
+
joinTitle: "加入「{title}」?",
|
|
689
|
+
joinBody: "这是{by}的房间。房主同意后你才能进去,你的名字「{name}」会发给对方。",
|
|
690
|
+
joinAction: "申请加入",
|
|
691
|
+
joinByLink: "用邀请链接加入",
|
|
692
|
+
joinByLinkPlaceholder: "粘贴别人发来的邀请链接",
|
|
693
|
+
scan: "扫一扫",
|
|
694
|
+
scanHint: "扫描房间的邀请二维码",
|
|
695
|
+
notInvite: "这不是房间的邀请链接。",
|
|
696
|
+
asked: "已向{by}发出申请,对方同意后就能进入。",
|
|
697
|
+
admitted: "已加入「{title}」。",
|
|
698
|
+
refusedNotice: "{by}没有同意你加入「{title}」。",
|
|
699
|
+
removedNotice: "你已被移出「{title}」。",
|
|
700
|
+
closedNotice: "「{title}」已被房主解散。",
|
|
701
|
+
oldApp: "请更新 Ta 应用后再使用房间。",
|
|
702
|
+
room: "房间",
|
|
703
|
+
newRoom: "新建房间",
|
|
704
|
+
newRoomPlaceholder: "房间名,受邀的人能看到",
|
|
705
|
+
roomOfName: "{name}的房间",
|
|
706
|
+
back: "返回",
|
|
707
|
+
openPage: "打开{name}",
|
|
708
|
+
pageLine: "{name}的房间,大家可以一起玩",
|
|
709
|
+
chatEmpty: "还没有人说话。只有房间里的人能看到,中继保存的是密文。",
|
|
710
|
+
chatPlaceholder: "发消息",
|
|
711
|
+
showOnHome: "在分身首页显示房间",
|
|
712
|
+
showOnHomeHint: "有房间时,分身首页多一个“房间”分类,和成员、频道放在一起。"
|
|
713
|
+
};
|
|
714
|
+
var RoomWords;
|
|
715
|
+
((RoomWords) => {
|
|
716
|
+
function of(language) {
|
|
717
|
+
return language === "zh-CN" ? ZH : EN;
|
|
718
|
+
}
|
|
719
|
+
RoomWords.of = of;
|
|
720
|
+
function format(text, values) {
|
|
721
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
|
|
722
|
+
}
|
|
723
|
+
RoomWords.format = format;
|
|
724
|
+
})(RoomWords ||= {});
|
|
725
|
+
|
|
726
|
+
// web-src/react.ts
|
|
727
|
+
var React;
|
|
728
|
+
function bind(react) {
|
|
729
|
+
React = react;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// web-src/page.tsx
|
|
733
|
+
var ROOMS_KIND = "ta-rooms";
|
|
734
|
+
var ROOMS_VIEW = "@celljs/ta-rooms/rooms";
|
|
735
|
+
var MEMBERS_VIEW = "@celljs/ta-rooms/members";
|
|
736
|
+
var CHAT_STATE = ["chat:", ROOM_AGENTS_KEY];
|
|
737
|
+
var SEEN_KEY = "seen";
|
|
738
|
+
var pi;
|
|
739
|
+
function bindPage(api) {
|
|
740
|
+
pi = api;
|
|
741
|
+
}
|
|
742
|
+
function t(key, values = {}) {
|
|
743
|
+
return RoomWords.format(RoomWords.of(pi.ui.language)[key], values);
|
|
744
|
+
}
|
|
745
|
+
function icon(name) {
|
|
746
|
+
return pi.ui.icons[name] ?? pi.ui.icons.Users ?? pi.ui.icons.Circle;
|
|
747
|
+
}
|
|
748
|
+
function message(error) {
|
|
749
|
+
return error instanceof Error ? error.message : String(error);
|
|
750
|
+
}
|
|
751
|
+
function rooms() {
|
|
752
|
+
return pi.rooms;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
class RoomBook {
|
|
756
|
+
state = { requests: [], seen: {} };
|
|
757
|
+
listeners = new Set;
|
|
758
|
+
chats = new Map;
|
|
759
|
+
agentStates = new Map;
|
|
760
|
+
agentLists = new Map;
|
|
761
|
+
joiningLists = new Map;
|
|
762
|
+
timer;
|
|
763
|
+
loading;
|
|
764
|
+
again = false;
|
|
765
|
+
seenRead = false;
|
|
766
|
+
onChange;
|
|
767
|
+
get() {
|
|
768
|
+
return this.state;
|
|
769
|
+
}
|
|
770
|
+
subscribe(listener) {
|
|
771
|
+
this.listeners.add(listener);
|
|
772
|
+
return () => this.listeners.delete(listener);
|
|
773
|
+
}
|
|
774
|
+
load() {
|
|
775
|
+
if (this.loading) {
|
|
776
|
+
this.again = true;
|
|
777
|
+
return this.loading;
|
|
778
|
+
}
|
|
779
|
+
const server = rooms();
|
|
780
|
+
if (!server) {
|
|
781
|
+
this.set({ rooms: [], friends: [] });
|
|
782
|
+
return Promise.resolve();
|
|
783
|
+
}
|
|
784
|
+
this.readSeen();
|
|
785
|
+
this.loading = Promise.all([
|
|
786
|
+
server.getIdentity().catch(() => this.state.identity),
|
|
787
|
+
server.listRooms().catch(() => this.state.rooms ?? []),
|
|
788
|
+
server.listRequests().catch(() => this.state.requests),
|
|
789
|
+
server.listFriends().catch(() => this.state.friends ?? [])
|
|
790
|
+
]).then(([identity, list, requests, friends]) => this.read({ ...this.state, identity, rooms: list, requests, friends })).finally(() => {
|
|
791
|
+
this.loading = undefined;
|
|
792
|
+
if (this.again) {
|
|
793
|
+
this.again = false;
|
|
794
|
+
this.load();
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
return this.loading;
|
|
798
|
+
}
|
|
799
|
+
reload() {
|
|
800
|
+
clearTimeout(this.timer);
|
|
801
|
+
this.timer = setTimeout(() => {
|
|
802
|
+
this.load();
|
|
803
|
+
for (const chat of this.chats.values()) {
|
|
804
|
+
chat.load().catch(() => {
|
|
805
|
+
return;
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
for (const room of this.agentStates.keys()) {
|
|
809
|
+
this.readAgents(room);
|
|
810
|
+
}
|
|
811
|
+
}, 300);
|
|
812
|
+
}
|
|
813
|
+
set(partial) {
|
|
814
|
+
this.state = { ...this.state, ...partial };
|
|
815
|
+
for (const listener of this.listeners) {
|
|
816
|
+
listener();
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
chat(room) {
|
|
820
|
+
const server = rooms();
|
|
821
|
+
if (!server) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
let chat = this.chats.get(room);
|
|
825
|
+
if (!chat) {
|
|
826
|
+
chat = new RelayRoomChat(server, room);
|
|
827
|
+
this.chats.set(room, chat);
|
|
828
|
+
chat.load().catch(() => {
|
|
829
|
+
return;
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
return chat;
|
|
833
|
+
}
|
|
834
|
+
agents(room) {
|
|
835
|
+
if (!this.agentStates.has(room)) {
|
|
836
|
+
this.agentStates.set(room, {});
|
|
837
|
+
this.readAgents(room);
|
|
838
|
+
}
|
|
839
|
+
return this.agentLists.get(room) ?? NO_AGENTS;
|
|
840
|
+
}
|
|
841
|
+
joining(room) {
|
|
842
|
+
return this.joiningLists.get(room) ?? NO_JOINING;
|
|
843
|
+
}
|
|
844
|
+
setJoining(room, agent, on) {
|
|
845
|
+
const others = this.joining(room).filter((each) => each.id !== agent.id);
|
|
846
|
+
this.joiningLists.set(room, on ? [...others, agent] : others);
|
|
847
|
+
this.set({});
|
|
848
|
+
}
|
|
849
|
+
putMine(room, member, agents) {
|
|
850
|
+
const known = this.agentStates.get(room);
|
|
851
|
+
if (!known) {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
const key = RoomAgentsUtil.key(member);
|
|
855
|
+
this.putAgents(room, { ...known, [key]: { value: agents, by: member, version: known[key]?.version ?? 0 } });
|
|
856
|
+
}
|
|
857
|
+
heard(event) {
|
|
858
|
+
if (event.type !== "state") {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.chats.get(event.room)?.heard(event.key, event);
|
|
862
|
+
const known = this.agentStates.get(event.room);
|
|
863
|
+
if (known && event.key.startsWith(ROOM_AGENTS_KEY) && (known[event.key]?.version ?? 0) < event.version) {
|
|
864
|
+
this.putAgents(event.room, { ...known, [event.key]: event });
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
readAgents(room) {
|
|
868
|
+
rooms()?.getState(room, ROOM_AGENTS_KEY).then((state) => this.putAgents(room, state)).catch(() => {
|
|
869
|
+
return;
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
putAgents(room, state) {
|
|
873
|
+
this.agentStates.set(room, state);
|
|
874
|
+
this.agentLists.set(room, RoomAgentsUtil.of(state));
|
|
875
|
+
this.set({});
|
|
876
|
+
}
|
|
877
|
+
see(room, at) {
|
|
878
|
+
if ((this.state.seen[room] ?? 0) >= at) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const seen = { ...this.state.seen, [room]: at };
|
|
882
|
+
this.set({ seen });
|
|
883
|
+
pi.storage?.set(SEEN_KEY, seen).catch(() => {
|
|
884
|
+
return;
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
readSeen() {
|
|
888
|
+
if (this.seenRead || !pi.storage) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
this.seenRead = true;
|
|
892
|
+
pi.storage.get(SEEN_KEY).then((seen) => {
|
|
893
|
+
if (seen && typeof seen === "object") {
|
|
894
|
+
this.set({ seen: { ...seen, ...this.state.seen } });
|
|
895
|
+
}
|
|
896
|
+
}).catch(() => {
|
|
897
|
+
return;
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
read(next) {
|
|
901
|
+
const before = new Map((this.state.rooms ?? []).map((room) => [room.id, room]));
|
|
902
|
+
const known = this.state.rooms !== undefined;
|
|
903
|
+
this.set(next);
|
|
904
|
+
const changes = (next.rooms ?? []).filter((room) => !known || before.get(room.id)?.status !== room.status).map((room) => ({ before: before.get(room.id), room }));
|
|
905
|
+
if (known && changes.length) {
|
|
906
|
+
this.onChange?.(changes);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
var book = new RoomBook;
|
|
911
|
+
function useBook() {
|
|
912
|
+
const state = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get());
|
|
913
|
+
React.useEffect(() => {
|
|
914
|
+
book.load();
|
|
915
|
+
}, []);
|
|
916
|
+
return state;
|
|
917
|
+
}
|
|
918
|
+
var NO_LINES = [];
|
|
919
|
+
var NO_AGENTS = [];
|
|
920
|
+
var NO_JOINING = [];
|
|
921
|
+
var NO_STOP = () => {
|
|
922
|
+
return;
|
|
923
|
+
};
|
|
924
|
+
function useLines(room) {
|
|
925
|
+
const chat = room.status === "member" ? book.chat(room.id) : undefined;
|
|
926
|
+
return React.useSyncExternalStore((listener) => chat?.subscribe(listener) ?? NO_STOP, () => chat?.lines ?? NO_LINES);
|
|
927
|
+
}
|
|
928
|
+
function useAgents(room) {
|
|
929
|
+
const member = room.status === "member";
|
|
930
|
+
return React.useSyncExternalStore((listener) => book.subscribe(listener), () => member ? book.agents(room.id) : NO_AGENTS);
|
|
931
|
+
}
|
|
932
|
+
function useJoining(room) {
|
|
933
|
+
return React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.joining(room.id));
|
|
934
|
+
}
|
|
935
|
+
function unseen(room, lines, seen) {
|
|
936
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
937
|
+
const since = seen[room.id] ?? room.joinedAt ?? room.createdAt;
|
|
938
|
+
const last = lines[lines.length - 1];
|
|
939
|
+
return !!last && last.at > since && last.from !== self;
|
|
940
|
+
}
|
|
941
|
+
function openRoom(id, direct = false) {
|
|
942
|
+
book.set({ opened: id, direct });
|
|
943
|
+
pi.ui.showView(ROOMS_VIEW);
|
|
944
|
+
}
|
|
945
|
+
function useOpened() {
|
|
946
|
+
const { rooms: list, opened } = useBook();
|
|
947
|
+
return opened ? list?.find((room) => room.id === opened && room.status === "member") : undefined;
|
|
948
|
+
}
|
|
949
|
+
function useCompact() {
|
|
950
|
+
return (pi.ui.useDevice?.().layout ?? "expanded") === "compact";
|
|
951
|
+
}
|
|
952
|
+
function usePageOf(room) {
|
|
953
|
+
const pages = pi.ui.usePages?.() ?? [];
|
|
954
|
+
const view = room.view;
|
|
955
|
+
if (!view || view === ROOMS_VIEW) {
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
return pages.find((page) => page.id === view) ?? pages.find((page) => page.onOpen && view.startsWith(`${page.id}/`));
|
|
959
|
+
}
|
|
960
|
+
function statusLine(room) {
|
|
961
|
+
switch (room.status) {
|
|
962
|
+
case "waiting":
|
|
963
|
+
return t("waiting", { name: room.ownerName });
|
|
964
|
+
case "refused":
|
|
965
|
+
return t("refused", { name: room.ownerName });
|
|
966
|
+
case "gone":
|
|
967
|
+
return room.reason === "removed" ? t("removed") : room.reason === "invite" ? t("inviteGone") : t("closed");
|
|
968
|
+
}
|
|
969
|
+
if (!room.connected) {
|
|
970
|
+
return t("connecting");
|
|
971
|
+
}
|
|
972
|
+
const online = room.members.filter((member) => member.online).length;
|
|
973
|
+
return t("people", { n: room.members.length, online });
|
|
974
|
+
}
|
|
975
|
+
function when(at, now = Date.now()) {
|
|
976
|
+
const date = new Date(at);
|
|
977
|
+
const today = new Date(now);
|
|
978
|
+
today.setHours(0, 0, 0, 0);
|
|
979
|
+
const day = 24 * 60 * 60 * 1000;
|
|
980
|
+
const language = pi.ui.language;
|
|
981
|
+
if (at >= today.getTime()) {
|
|
982
|
+
return date.toLocaleTimeString(language, { hour: "2-digit", minute: "2-digit" });
|
|
983
|
+
}
|
|
984
|
+
if (at >= today.getTime() - day) {
|
|
985
|
+
return t("yesterday");
|
|
986
|
+
}
|
|
987
|
+
if (at >= today.getTime() - 6 * day) {
|
|
988
|
+
return date.toLocaleDateString(language, { weekday: "short" });
|
|
989
|
+
}
|
|
990
|
+
return date.toLocaleDateString(language, { month: "numeric", day: "numeric", ...date.getFullYear() !== today.getFullYear() ? { year: "2-digit" } : {} });
|
|
991
|
+
}
|
|
992
|
+
function tint(id) {
|
|
993
|
+
let hash = 0;
|
|
994
|
+
for (const char of id) {
|
|
995
|
+
hash = hash * 31 + char.charCodeAt(0) | 0;
|
|
996
|
+
}
|
|
997
|
+
return Math.abs(hash) % 9;
|
|
998
|
+
}
|
|
999
|
+
function initial(name) {
|
|
1000
|
+
return Array.from(name.trim())[0]?.toUpperCase() ?? "?";
|
|
1001
|
+
}
|
|
1002
|
+
function Face({ id, name, size = 34, online, face }) {
|
|
1003
|
+
if (pi.ui.Face) {
|
|
1004
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
1005
|
+
seed: id,
|
|
1006
|
+
face,
|
|
1007
|
+
size,
|
|
1008
|
+
online
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
const n = tint(id);
|
|
1012
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
1013
|
+
className: "trm-face",
|
|
1014
|
+
"aria-hidden": "true",
|
|
1015
|
+
style: { width: size, height: size, fontSize: Math.round(size * 0.42), background: `var(--ta-tint-${n})`, color: `var(--ta-tint-ink-${n})` }
|
|
1016
|
+
}, initial(name), online !== undefined && /* @__PURE__ */ React.createElement("i", {
|
|
1017
|
+
className: online ? "trm-on" : "trm-off"
|
|
1018
|
+
}));
|
|
1019
|
+
}
|
|
1020
|
+
function faceMembers(room, agents = []) {
|
|
1021
|
+
const others = room.members.filter((member) => !member.self).sort((a, b) => Number(b.owner) - Number(a.owner));
|
|
1022
|
+
const all = [...others, ...agents, ...room.members.filter((member) => member.self)];
|
|
1023
|
+
return all.length ? all : [{ id: room.owner ? room.id : room.ownerName || room.id, name: room.ownerName || room.title }];
|
|
1024
|
+
}
|
|
1025
|
+
function RoomFace({ room, size = 40, unread }) {
|
|
1026
|
+
const page = usePageOf(room);
|
|
1027
|
+
const Mark = page?.icon;
|
|
1028
|
+
const members = faceMembers(room, useAgents(room));
|
|
1029
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
1030
|
+
className: "trm-room-face",
|
|
1031
|
+
style: { width: size, height: size },
|
|
1032
|
+
"aria-hidden": "true"
|
|
1033
|
+
}, pi.ui.GroupFace ? /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
|
|
1034
|
+
members: members.map((member) => ({ seed: member.id, face: member.face })),
|
|
1035
|
+
size
|
|
1036
|
+
}) : /* @__PURE__ */ React.createElement(Face, {
|
|
1037
|
+
id: members[0]?.id ?? room.id,
|
|
1038
|
+
name: members[0]?.name ?? room.title,
|
|
1039
|
+
face: members[0]?.face,
|
|
1040
|
+
size
|
|
1041
|
+
}), Mark && /* @__PURE__ */ React.createElement("span", {
|
|
1042
|
+
className: "trm-room-face-mark"
|
|
1043
|
+
}, /* @__PURE__ */ React.createElement(Mark, {
|
|
1044
|
+
size: 11,
|
|
1045
|
+
strokeWidth: 2.4
|
|
1046
|
+
})), unread && /* @__PURE__ */ React.createElement("i", {
|
|
1047
|
+
className: "trm-unread"
|
|
1048
|
+
}));
|
|
1049
|
+
}
|
|
1050
|
+
function MemberFaces({ room, onClick, shown }) {
|
|
1051
|
+
const agents = useAgents(room);
|
|
1052
|
+
const members = [
|
|
1053
|
+
...[...room.members].sort((a, b) => Number(b.owner) - Number(a.owner)).map((member) => ({ key: member.member, id: member.id, name: member.name, face: undefined })),
|
|
1054
|
+
...agents.map((agent) => ({ key: `${agent.member}/${agent.id}`, id: agent.id, name: agent.name, face: agent.face }))
|
|
1055
|
+
];
|
|
1056
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
1057
|
+
type: "button",
|
|
1058
|
+
className: `trm-faces${shown ? " trm-on-icon" : ""}`,
|
|
1059
|
+
title: t("members"),
|
|
1060
|
+
"aria-label": t("members"),
|
|
1061
|
+
"aria-pressed": shown,
|
|
1062
|
+
onClick
|
|
1063
|
+
}, members.slice(0, 5).map((member) => /* @__PURE__ */ React.createElement("span", {
|
|
1064
|
+
key: member.key,
|
|
1065
|
+
className: "trm-faces-one"
|
|
1066
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1067
|
+
id: member.id,
|
|
1068
|
+
name: member.name,
|
|
1069
|
+
face: member.face,
|
|
1070
|
+
size: 24
|
|
1071
|
+
}))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
|
|
1072
|
+
className: "trm-faces-more"
|
|
1073
|
+
}, "+", members.length - 5));
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// web-src/dialogs.tsx
|
|
1077
|
+
function show(component) {
|
|
1078
|
+
if (!pi.ui.custom) {
|
|
1079
|
+
pi.ui.notify(t("oldApp"), "warning");
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
return pi.ui.custom(component);
|
|
1083
|
+
}
|
|
1084
|
+
function RequestRow({ request }) {
|
|
1085
|
+
const [busy, run] = (pi.ui.useBusy ?? (() => [false, async (action) => action()]))();
|
|
1086
|
+
const answer = (accept) => void run(async () => {
|
|
1087
|
+
try {
|
|
1088
|
+
await rooms()?.answer(request.room, request.ask, accept);
|
|
1089
|
+
} catch (error) {
|
|
1090
|
+
pi.ui.notify(message(error), "error");
|
|
1091
|
+
}
|
|
1092
|
+
await book.load();
|
|
1093
|
+
});
|
|
1094
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1095
|
+
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
1096
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1097
|
+
id: request.id,
|
|
1098
|
+
name: request.name
|
|
1099
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
1100
|
+
className: "trm-row-text"
|
|
1101
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1102
|
+
className: "trm-row-title"
|
|
1103
|
+
}, request.name, /* @__PURE__ */ React.createElement("span", {
|
|
1104
|
+
className: `trm-tag${request.friend ? " trm-tag-friend" : ""}`
|
|
1105
|
+
}, request.guest ? t("guestTag") : request.friend ? t("friendTag") : t("newTag"))), /* @__PURE__ */ React.createElement("span", {
|
|
1106
|
+
className: "trm-row-line"
|
|
1107
|
+
}, t("requestLine", { title: request.title }))), /* @__PURE__ */ React.createElement("div", {
|
|
1108
|
+
className: "trm-answers"
|
|
1109
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1110
|
+
type: "button",
|
|
1111
|
+
className: "ta-button",
|
|
1112
|
+
disabled: busy,
|
|
1113
|
+
onClick: () => answer(false)
|
|
1114
|
+
}, t("refuse")), /* @__PURE__ */ React.createElement("button", {
|
|
1115
|
+
type: "button",
|
|
1116
|
+
className: "ta-button ta-primary",
|
|
1117
|
+
disabled: busy,
|
|
1118
|
+
onClick: () => answer(true)
|
|
1119
|
+
}, t("accept"))));
|
|
1120
|
+
}
|
|
1121
|
+
function RequestsDialog({ close }) {
|
|
1122
|
+
const { requests } = useBook();
|
|
1123
|
+
const seen = React.useRef(false);
|
|
1124
|
+
React.useEffect(() => {
|
|
1125
|
+
if (requests.length) {
|
|
1126
|
+
seen.current = true;
|
|
1127
|
+
} else if (seen.current) {
|
|
1128
|
+
close();
|
|
1129
|
+
}
|
|
1130
|
+
}, [requests.length, close]);
|
|
1131
|
+
const first = requests[0];
|
|
1132
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
1133
|
+
title: t("requests"),
|
|
1134
|
+
onClose: close
|
|
1135
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1136
|
+
className: "trm-dialog"
|
|
1137
|
+
}, first && /* @__PURE__ */ React.createElement("p", {
|
|
1138
|
+
className: "trm-lead"
|
|
1139
|
+
}, requests.length === 1 ? t("requestBody", { name: first.name, title: first.title }) : t("requestsBody", { n: requests.length })), /* @__PURE__ */ React.createElement("ul", {
|
|
1140
|
+
className: "trm-rows"
|
|
1141
|
+
}, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
|
|
1142
|
+
key: `${request.room}:${request.ask}`,
|
|
1143
|
+
request
|
|
1144
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
1145
|
+
className: "trm-note"
|
|
1146
|
+
}, [
|
|
1147
|
+
requests.some((request) => !request.friend) ? t("requestNew") : requests.length ? t("requestFriend") : "",
|
|
1148
|
+
requests.some((request) => request.guest) ? t("requestGuest") : "",
|
|
1149
|
+
t("requestWhat")
|
|
1150
|
+
].filter(Boolean).join(pi.ui.language === "zh-CN" ? "" : " ")), /* @__PURE__ */ React.createElement("div", {
|
|
1151
|
+
className: "trm-actions"
|
|
1152
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1153
|
+
type: "button",
|
|
1154
|
+
className: "ta-button",
|
|
1155
|
+
onClick: close
|
|
1156
|
+
}, t("later")))));
|
|
1157
|
+
}
|
|
1158
|
+
var requestsOpen;
|
|
1159
|
+
function openRequests() {
|
|
1160
|
+
if (requestsOpen) {
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
const close = show(({ close: close2 }) => /* @__PURE__ */ React.createElement(RequestsDialog, {
|
|
1164
|
+
close: () => {
|
|
1165
|
+
requestsOpen = undefined;
|
|
1166
|
+
close2();
|
|
1167
|
+
}
|
|
1168
|
+
}));
|
|
1169
|
+
requestsOpen = close;
|
|
1170
|
+
}
|
|
1171
|
+
function JoinDialog({ link, text, close }) {
|
|
1172
|
+
const { identity } = useBook();
|
|
1173
|
+
const [busy, setBusy] = React.useState(false);
|
|
1174
|
+
const [error, setError] = React.useState();
|
|
1175
|
+
const join = async () => {
|
|
1176
|
+
setBusy(true);
|
|
1177
|
+
setError(undefined);
|
|
1178
|
+
try {
|
|
1179
|
+
const room = await rooms()?.join(text);
|
|
1180
|
+
await book.load();
|
|
1181
|
+
close();
|
|
1182
|
+
if (room?.status === "member") {
|
|
1183
|
+
if (room.view) {
|
|
1184
|
+
pi.ui.showView(room.view);
|
|
1185
|
+
} else {
|
|
1186
|
+
openRoom(room.id);
|
|
1187
|
+
}
|
|
1188
|
+
} else {
|
|
1189
|
+
pi.ui.notify(t("asked", { by: link.by || "…" }));
|
|
1190
|
+
}
|
|
1191
|
+
} catch (failure) {
|
|
1192
|
+
setError(message(failure));
|
|
1193
|
+
setBusy(false);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
1197
|
+
title: t("joinTitle", { title: link.title || t("room") }),
|
|
1198
|
+
onClose: close
|
|
1199
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1200
|
+
className: "trm-dialog"
|
|
1201
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1202
|
+
className: "trm-join"
|
|
1203
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1204
|
+
id: link.owner,
|
|
1205
|
+
name: link.by || "?",
|
|
1206
|
+
size: 44
|
|
1207
|
+
}), /* @__PURE__ */ React.createElement("p", {
|
|
1208
|
+
className: "trm-lead"
|
|
1209
|
+
}, t("joinBody", { by: link.by || "…", name: identity?.name ?? "…" }))), error && /* @__PURE__ */ React.createElement("p", {
|
|
1210
|
+
className: "trm-error"
|
|
1211
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
1212
|
+
className: "trm-actions"
|
|
1213
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1214
|
+
type: "button",
|
|
1215
|
+
className: "ta-button",
|
|
1216
|
+
onClick: close
|
|
1217
|
+
}, t("later")), /* @__PURE__ */ React.createElement("button", {
|
|
1218
|
+
type: "button",
|
|
1219
|
+
className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
|
|
1220
|
+
disabled: busy,
|
|
1221
|
+
onClick: () => void join()
|
|
1222
|
+
}, t("joinAction")))));
|
|
1223
|
+
}
|
|
1224
|
+
function InviteDialog({ room, close }) {
|
|
1225
|
+
const [link, setLink] = React.useState();
|
|
1226
|
+
const [error, setError] = React.useState();
|
|
1227
|
+
const [copied, setCopied] = React.useState(false);
|
|
1228
|
+
const make = React.useCallback((renew) => {
|
|
1229
|
+
setError(undefined);
|
|
1230
|
+
setCopied(false);
|
|
1231
|
+
rooms()?.invite(room.id, renew ? { renew } : undefined).then((made) => setLink(made.link)).catch((failure) => setError(message(failure)));
|
|
1232
|
+
}, [room.id]);
|
|
1233
|
+
React.useEffect(() => make(false), [make]);
|
|
1234
|
+
const canSend = typeof navigator !== "undefined" && typeof navigator.share === "function";
|
|
1235
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
1236
|
+
title: t("inviteTitle", { title: room.title }),
|
|
1237
|
+
onClose: close
|
|
1238
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1239
|
+
className: "trm-dialog trm-invite"
|
|
1240
|
+
}, link ? /* @__PURE__ */ React.createElement(React.Fragment, null, pi.ui.QrCode && /* @__PURE__ */ React.createElement("div", {
|
|
1241
|
+
className: "trm-qr"
|
|
1242
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.QrCode, {
|
|
1243
|
+
text: link,
|
|
1244
|
+
label: t("qr")
|
|
1245
|
+
})), /* @__PURE__ */ React.createElement("p", {
|
|
1246
|
+
className: "trm-hint"
|
|
1247
|
+
}, t("inviteHint")), /* @__PURE__ */ React.createElement("div", {
|
|
1248
|
+
className: "trm-link-box"
|
|
1249
|
+
}, link), /* @__PURE__ */ React.createElement("div", {
|
|
1250
|
+
className: "trm-actions trm-center"
|
|
1251
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1252
|
+
type: "button",
|
|
1253
|
+
className: "ta-button ta-primary",
|
|
1254
|
+
onClick: () => void navigator.clipboard?.writeText(link).then(() => setCopied(true))
|
|
1255
|
+
}, copied ? t("copied") : t("copy")), canSend && /* @__PURE__ */ React.createElement("button", {
|
|
1256
|
+
type: "button",
|
|
1257
|
+
className: "ta-button",
|
|
1258
|
+
onClick: () => void navigator.share({ title: room.title, url: link }).catch(() => {
|
|
1259
|
+
return;
|
|
1260
|
+
})
|
|
1261
|
+
}, t("send")), /* @__PURE__ */ React.createElement("button", {
|
|
1262
|
+
type: "button",
|
|
1263
|
+
className: "ta-button",
|
|
1264
|
+
onClick: () => make(true)
|
|
1265
|
+
}, t("newLink")))) : error ? /* @__PURE__ */ React.createElement("p", {
|
|
1266
|
+
className: "trm-error"
|
|
1267
|
+
}, error) : /* @__PURE__ */ React.createElement("p", {
|
|
1268
|
+
className: "trm-hint"
|
|
1269
|
+
}, t("making"))));
|
|
1270
|
+
}
|
|
1271
|
+
function openInvite(room) {
|
|
1272
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(InviteDialog, {
|
|
1273
|
+
room,
|
|
1274
|
+
close
|
|
1275
|
+
}));
|
|
1276
|
+
}
|
|
1277
|
+
function openJoin(text) {
|
|
1278
|
+
const link = RelayHubUtil.parse(text);
|
|
1279
|
+
const known = book.get().rooms?.find((room) => room.id === link.room && room.status === "member");
|
|
1280
|
+
if (known) {
|
|
1281
|
+
if (known.view) {
|
|
1282
|
+
pi.ui.showView(known.view);
|
|
1283
|
+
} else {
|
|
1284
|
+
openRoom(known.id);
|
|
1285
|
+
}
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
1289
|
+
link,
|
|
1290
|
+
text,
|
|
1291
|
+
close
|
|
1292
|
+
}));
|
|
1293
|
+
}
|
|
1294
|
+
async function createRoom() {
|
|
1295
|
+
const name = book.get().identity?.name;
|
|
1296
|
+
const title = await pi.ui.input(t("newRoom"), t("newRoomPlaceholder"), { value: name ? t("roomOfName", { name }) : "" });
|
|
1297
|
+
if (!title?.trim()) {
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
try {
|
|
1301
|
+
const room = await rooms()?.createRoom({ kind: ROOMS_KIND, title: title.trim() });
|
|
1302
|
+
if (room) {
|
|
1303
|
+
await book.load();
|
|
1304
|
+
openRoom(room.id);
|
|
1305
|
+
openInvite(room);
|
|
1306
|
+
}
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
pi.ui.notify(message(error), "error");
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
async function pasteLink() {
|
|
1312
|
+
const text = (await pi.ui.input(t("joinByLink"), t("joinByLinkPlaceholder")))?.trim();
|
|
1313
|
+
if (!text) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
if (!RelayHubUtil.is(text)) {
|
|
1317
|
+
pi.ui.notify(t("notInvite"), "warning");
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
openJoin(text);
|
|
1321
|
+
}
|
|
1322
|
+
async function scanLink() {
|
|
1323
|
+
const text = (await pi.ui.scanCode?.(t("scanHint")))?.trim();
|
|
1324
|
+
if (!text) {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
if (!RelayHubUtil.is(text)) {
|
|
1328
|
+
pi.ui.notify(t("notInvite"), "warning");
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
openJoin(text);
|
|
1332
|
+
}
|
|
1333
|
+
async function rename() {
|
|
1334
|
+
const identity = book.get().identity;
|
|
1335
|
+
const name = await pi.ui.input(t("me"), t("renamePlaceholder"), { value: identity?.name ?? "" });
|
|
1336
|
+
if (name?.trim() && name.trim() !== identity?.name) {
|
|
1337
|
+
try {
|
|
1338
|
+
book.set({ identity: await rooms()?.setName(name.trim()) });
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
pi.ui.notify(message(error), "error");
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// web-src/double-i18n.ts
|
|
1346
|
+
var EN2 = {
|
|
1347
|
+
doubleOf: "{name}'s double",
|
|
1348
|
+
myDouble: "Your double",
|
|
1349
|
+
doubleTag: "Double",
|
|
1350
|
+
mentionLabel: "Ask a double",
|
|
1351
|
+
mentionDetail: "Ask their double",
|
|
1352
|
+
answersHere: "Your double answers here",
|
|
1353
|
+
answersHint: "When someone asks it with @, your double answers in this room. It only chats and reads the room, unless you let it do more for someone.",
|
|
1354
|
+
permissions: "Let the double work for them",
|
|
1355
|
+
grantTitle: "Let your double work for {name}",
|
|
1356
|
+
grantLead: "When {name} asks your double in a room, it may also do this on your computer:",
|
|
1357
|
+
files: "Read and change files",
|
|
1358
|
+
filesHint: "Only inside the directory below.",
|
|
1359
|
+
commands: "Run commands",
|
|
1360
|
+
commandsHint: "In that directory, though a command can reach beyond it: only for someone you trust.",
|
|
1361
|
+
directory: "Directory",
|
|
1362
|
+
pick: "Choose",
|
|
1363
|
+
duration: "For",
|
|
1364
|
+
hours1: "1 hour",
|
|
1365
|
+
hours24: "1 day",
|
|
1366
|
+
hours168: "7 days",
|
|
1367
|
+
allow: "Allow",
|
|
1368
|
+
cancel: "Cancel",
|
|
1369
|
+
refuse: "Refuse",
|
|
1370
|
+
later: "Later",
|
|
1371
|
+
grantNote: "You can take it back at any time, and all your double does for them is logged.",
|
|
1372
|
+
asksTitle: "Your double asks",
|
|
1373
|
+
askLine: "{name} in “{title}”: {reason}",
|
|
1374
|
+
askLead: "{name} asked your double for something in “{title}”:",
|
|
1375
|
+
review: "Review",
|
|
1376
|
+
askWants: "For it, your double needs to {what} on your computer.",
|
|
1377
|
+
wantsFiles: "read and change files",
|
|
1378
|
+
wantsCommands: "run commands",
|
|
1379
|
+
may: "Your double may {what} · {left} left",
|
|
1380
|
+
mayFiles: "files",
|
|
1381
|
+
mayCommands: "commands",
|
|
1382
|
+
left: "{n} h",
|
|
1383
|
+
leftMinutes: "{n} min",
|
|
1384
|
+
leftDays: "{n} d",
|
|
1385
|
+
revoke: "Take back",
|
|
1386
|
+
revokeAll: "Stop all for {name}",
|
|
1387
|
+
revokeAllTitle: "Stop all your double does for {name}?",
|
|
1388
|
+
revokeAllHint: "The permissions and the asks of {name} go, and what your double does for them now stops.",
|
|
1389
|
+
stop: "Stop",
|
|
1390
|
+
logTitle: "What your double did",
|
|
1391
|
+
logEmpty: "Nothing yet",
|
|
1392
|
+
logEmptyHint: "What your double does for others in rooms is listed here",
|
|
1393
|
+
asked: "{name} asked",
|
|
1394
|
+
answered: "Answered",
|
|
1395
|
+
failed: "Failed",
|
|
1396
|
+
limited: "Skipped: too many this hour",
|
|
1397
|
+
tools: "{n} tool calls",
|
|
1398
|
+
clearLog: "Clear",
|
|
1399
|
+
grants: "Permissions",
|
|
1400
|
+
noGrants: "Your double only chats for others",
|
|
1401
|
+
log: "What your double did",
|
|
1402
|
+
noPermission: "Not yet set",
|
|
1403
|
+
oldServer: "Update Ta on the computer to use doubles in rooms.",
|
|
1404
|
+
agentTag: "Agent",
|
|
1405
|
+
myAgent: "Your agent",
|
|
1406
|
+
agentOf: "{name}'s agent",
|
|
1407
|
+
agentsTitle: "Agents",
|
|
1408
|
+
inviteAgent: "Invite an agent",
|
|
1409
|
+
inviteAgentLine: "One of your agents helps in the room",
|
|
1410
|
+
pickAgentTitle: "Invite an agent to “{title}”",
|
|
1411
|
+
pickAgentLead: "Anyone in the room asks it with @. When you ask, it works for you as usual, with its tools in its directory; when others ask, it only chats, as your double, unless you let it do more for them.",
|
|
1412
|
+
noAgents: "No agents yet",
|
|
1413
|
+
noAgentsHint: "Make one in the side bar of your double first.",
|
|
1414
|
+
inRoom: "In the room",
|
|
1415
|
+
joining: "Joining…",
|
|
1416
|
+
joiningRoom: "{name} is joining the room…",
|
|
1417
|
+
inviteFailed: "Could not invite {name}: {error}",
|
|
1418
|
+
dismiss: "Ask to leave",
|
|
1419
|
+
dismissTitle: "Ask {name} to leave “{title}”?",
|
|
1420
|
+
dismissHint: "It says goodbye in the room and answers nothing there any more.",
|
|
1421
|
+
tryAlone: "Invite one of your agents: you can try the room on your own.",
|
|
1422
|
+
agentAsked: "{name} asked {agent}"
|
|
1423
|
+
};
|
|
1424
|
+
var ZH2 = {
|
|
1425
|
+
doubleOf: "{name}的分身",
|
|
1426
|
+
myDouble: "我的分身",
|
|
1427
|
+
doubleTag: "分身",
|
|
1428
|
+
mentionLabel: "问分身",
|
|
1429
|
+
mentionDetail: "问 TA 的分身",
|
|
1430
|
+
answersHere: "我的分身在这里回答",
|
|
1431
|
+
answersHint: "有人 @ 你的分身时,它会在这个房间里回答。默认只能聊天和读房间里的内容,你允许后才能替某人做更多事。",
|
|
1432
|
+
permissions: "授权分身替 TA 做事",
|
|
1433
|
+
grantTitle: "让分身替{name}做事",
|
|
1434
|
+
grantLead: "{name}在房间里问你的分身时,它还可以在你的电脑上:",
|
|
1435
|
+
files: "读写文件",
|
|
1436
|
+
filesHint: "只限下面这个目录。",
|
|
1437
|
+
commands: "运行命令",
|
|
1438
|
+
commandsHint: "在这个目录里运行,但命令本身能碰到目录之外:只给信任的人。",
|
|
1439
|
+
directory: "目录",
|
|
1440
|
+
pick: "选择",
|
|
1441
|
+
duration: "有效期",
|
|
1442
|
+
hours1: "1 小时",
|
|
1443
|
+
hours24: "1 天",
|
|
1444
|
+
hours168: "7 天",
|
|
1445
|
+
allow: "允许",
|
|
1446
|
+
cancel: "取消",
|
|
1447
|
+
refuse: "拒绝",
|
|
1448
|
+
later: "稍后",
|
|
1449
|
+
grantNote: "可以随时收回;分身替对方做的每件事都有记录。",
|
|
1450
|
+
asksTitle: "分身请你授权",
|
|
1451
|
+
askLine: "{name}在「{title}」里:{reason}",
|
|
1452
|
+
askLead: "{name}在「{title}」里请你的分身帮忙:",
|
|
1453
|
+
review: "处理",
|
|
1454
|
+
askWants: "分身需要在你的电脑上{what}。",
|
|
1455
|
+
wantsFiles: "读写文件",
|
|
1456
|
+
wantsCommands: "运行命令",
|
|
1457
|
+
may: "分身可以{what} · 还剩 {left}",
|
|
1458
|
+
mayFiles: "读写文件",
|
|
1459
|
+
mayCommands: "运行命令",
|
|
1460
|
+
left: "{n} 小时",
|
|
1461
|
+
leftMinutes: "{n} 分钟",
|
|
1462
|
+
leftDays: "{n} 天",
|
|
1463
|
+
revoke: "收回",
|
|
1464
|
+
revokeAll: "停掉{name}的全部授权",
|
|
1465
|
+
revokeAllTitle: "停掉分身为{name}做的一切?",
|
|
1466
|
+
revokeAllHint: "{name}的授权和待处理的请求都会删除,分身正在替 TA 做的事也会停下。",
|
|
1467
|
+
stop: "停掉",
|
|
1468
|
+
logTitle: "分身记录",
|
|
1469
|
+
logEmpty: "还没有记录",
|
|
1470
|
+
logEmptyHint: "分身在房间里替别人做的事会列在这里",
|
|
1471
|
+
asked: "{name}问",
|
|
1472
|
+
answered: "已回答",
|
|
1473
|
+
failed: "失败",
|
|
1474
|
+
limited: "跳过:这一小时回答太多",
|
|
1475
|
+
tools: "用了 {n} 次工具",
|
|
1476
|
+
clearLog: "清空",
|
|
1477
|
+
grants: "授权",
|
|
1478
|
+
noGrants: "分身只替别人聊天",
|
|
1479
|
+
log: "分身记录",
|
|
1480
|
+
noPermission: "还没有授权",
|
|
1481
|
+
oldServer: "请先更新电脑上的 Ta,再在房间里使用分身。",
|
|
1482
|
+
agentTag: "智能体",
|
|
1483
|
+
myAgent: "我的智能体",
|
|
1484
|
+
agentOf: "{name}的智能体",
|
|
1485
|
+
agentsTitle: "智能体",
|
|
1486
|
+
inviteAgent: "邀请智能体",
|
|
1487
|
+
inviteAgentLine: "让你的智能体在房间里帮忙",
|
|
1488
|
+
pickAgentTitle: "邀请智能体进「{title}」",
|
|
1489
|
+
pickAgentLead: "房间里的人 @ 它就能找它帮忙。你自己问它时,它像平常一样在自己的目录里用工具做事;别人问它时,和分身一样只能聊天,除非你授权。",
|
|
1490
|
+
noAgents: "还没有智能体",
|
|
1491
|
+
noAgentsHint: "先在分身侧栏新建一个智能体。",
|
|
1492
|
+
inRoom: "已在房间里",
|
|
1493
|
+
joining: "正在加入…",
|
|
1494
|
+
joiningRoom: "{name}正在加入房间…",
|
|
1495
|
+
inviteFailed: "没能邀请{name}:{error}",
|
|
1496
|
+
dismiss: "请出房间",
|
|
1497
|
+
dismissTitle: "让{name}离开「{title}」?",
|
|
1498
|
+
dismissHint: "它会在房间里道别,之后不再回答这里的问题。",
|
|
1499
|
+
tryAlone: "邀请一个你的智能体进来,一个人也能试试房间。",
|
|
1500
|
+
agentAsked: "{name}问{agent}"
|
|
1501
|
+
};
|
|
1502
|
+
var DoubleWordsUtil;
|
|
1503
|
+
((DoubleWordsUtil) => {
|
|
1504
|
+
function of(language) {
|
|
1505
|
+
return language === "zh-CN" ? ZH2 : EN2;
|
|
1506
|
+
}
|
|
1507
|
+
DoubleWordsUtil.of = of;
|
|
1508
|
+
})(DoubleWordsUtil ||= {});
|
|
1509
|
+
function dt(key, values = {}) {
|
|
1510
|
+
return DoubleWordsUtil.of(pi.ui.language)[key].replace(/\{(\w+)\}/g, (whole, name) => (name in values) ? String(values[name]) : whole);
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// web-src/doubles-store.ts
|
|
1514
|
+
var KEYS = [DoubleKeys.QUIET, DoubleKeys.GRANTS, DoubleKeys.ASKS, DoubleKeys.LOG];
|
|
1515
|
+
|
|
1516
|
+
class DoublesStore {
|
|
1517
|
+
state = { quiet: {}, grants: [], asks: [], log: [] };
|
|
1518
|
+
listeners = new Set;
|
|
1519
|
+
started = false;
|
|
1520
|
+
onAsk;
|
|
1521
|
+
get() {
|
|
1522
|
+
return this.state;
|
|
1523
|
+
}
|
|
1524
|
+
subscribe(listener) {
|
|
1525
|
+
this.listeners.add(listener);
|
|
1526
|
+
return () => this.listeners.delete(listener);
|
|
1527
|
+
}
|
|
1528
|
+
start() {
|
|
1529
|
+
if (this.started || !pi.storage) {
|
|
1530
|
+
return () => {
|
|
1531
|
+
return;
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
this.started = true;
|
|
1535
|
+
const stop = pi.storage.onChange((keys) => {
|
|
1536
|
+
const changed = keys.filter((key) => KEYS.includes(key));
|
|
1537
|
+
if (changed.length) {
|
|
1538
|
+
this.read(changed);
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
this.read(KEYS);
|
|
1542
|
+
return () => {
|
|
1543
|
+
stop();
|
|
1544
|
+
this.started = false;
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
async read(keys) {
|
|
1548
|
+
const values = await Promise.all(keys.map((key) => pi.storage.get(key).catch(() => {
|
|
1549
|
+
return;
|
|
1550
|
+
})));
|
|
1551
|
+
const next = { ...this.state };
|
|
1552
|
+
keys.forEach((key, index) => {
|
|
1553
|
+
const value = values[index];
|
|
1554
|
+
if (key === DoubleKeys.QUIET) {
|
|
1555
|
+
next.quiet = value && typeof value === "object" ? value : {};
|
|
1556
|
+
} else if (key === DoubleKeys.GRANTS) {
|
|
1557
|
+
next.grants = Array.isArray(value) ? value : [];
|
|
1558
|
+
} else if (key === DoubleKeys.ASKS) {
|
|
1559
|
+
next.asks = Array.isArray(value) ? value : [];
|
|
1560
|
+
} else if (key === DoubleKeys.LOG) {
|
|
1561
|
+
next.log = Array.isArray(value) ? value : [];
|
|
1562
|
+
}
|
|
1563
|
+
});
|
|
1564
|
+
const known = new Set(this.state.asks.map((ask) => ask.id));
|
|
1565
|
+
const fresh = keys.includes(DoubleKeys.ASKS) ? next.asks.filter((ask) => !known.has(ask.id)) : [];
|
|
1566
|
+
this.state = next;
|
|
1567
|
+
for (const listener of this.listeners) {
|
|
1568
|
+
listener();
|
|
1569
|
+
}
|
|
1570
|
+
if (fresh.length) {
|
|
1571
|
+
this.onAsk?.(fresh);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
var doubles = new DoublesStore;
|
|
1576
|
+
function useDoubles() {
|
|
1577
|
+
return React.useSyncExternalStore((listener) => doubles.subscribe(listener), () => doubles.get());
|
|
1578
|
+
}
|
|
1579
|
+
async function callDoubles(request) {
|
|
1580
|
+
try {
|
|
1581
|
+
return await pi.callHost("doubles", request);
|
|
1582
|
+
} catch (error) {
|
|
1583
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1584
|
+
throw new Error(/no method|no host/i.test(text) ? dt("oldServer") : text);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function mentionName(name) {
|
|
1588
|
+
return dt("doubleOf", { name });
|
|
1589
|
+
}
|
|
1590
|
+
function askable(room) {
|
|
1591
|
+
return room.members.filter((member) => !member.self && !member.guest);
|
|
1592
|
+
}
|
|
1593
|
+
function names(text, name) {
|
|
1594
|
+
const quoted = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1595
|
+
return new RegExp(`@${quoted}(?![\\p{L}\\p{N}_])`, "u").test(text);
|
|
1596
|
+
}
|
|
1597
|
+
function addressed(text, room, agents = []) {
|
|
1598
|
+
return [
|
|
1599
|
+
...askable(room).filter((member) => text.includes(`@${mentionName(member.name)}`)).map((member) => member.member),
|
|
1600
|
+
...agents.filter((agent) => names(text, agent.name)).map((agent) => RoomAgentsUtil.address(agent.member, agent.id))
|
|
1601
|
+
];
|
|
1602
|
+
}
|
|
1603
|
+
function grantsOf(grants, friend, now = Date.now()) {
|
|
1604
|
+
return grants.filter((grant) => grant.friend === friend && grant.expiresAt > now);
|
|
1605
|
+
}
|
|
1606
|
+
function left(until, now = Date.now()) {
|
|
1607
|
+
const minutes = Math.max(1, Math.round((until - now) / 60000));
|
|
1608
|
+
if (minutes < 60) {
|
|
1609
|
+
return dt("leftMinutes", { n: minutes });
|
|
1610
|
+
}
|
|
1611
|
+
const hours = Math.round(minutes / 60);
|
|
1612
|
+
return hours < 48 ? dt("left", { n: hours }) : dt("leftDays", { n: Math.round(hours / 24) });
|
|
1613
|
+
}
|
|
1614
|
+
function capabilityName(capability) {
|
|
1615
|
+
return capability === "files" ? dt("mayFiles") : dt("mayCommands");
|
|
1616
|
+
}
|
|
1617
|
+
function mayLine(grants) {
|
|
1618
|
+
if (grants.length === 0) {
|
|
1619
|
+
return "";
|
|
1620
|
+
}
|
|
1621
|
+
const what = [...new Set(grants.map((grant) => grant.capability))].sort().map(capabilityName);
|
|
1622
|
+
return dt("may", { what: what.join(pi.ui.language === "zh-CN" ? "、" : ", "), left: left(Math.min(...grants.map((grant) => grant.expiresAt))) });
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// web-src/doubles-view.tsx
|
|
1626
|
+
var DOUBLES_VIEW = "@celljs/ta-rooms/doubles";
|
|
1627
|
+
function useBusy() {
|
|
1628
|
+
const fallback = React.useState(false);
|
|
1629
|
+
const busy = pi.ui.useBusy?.();
|
|
1630
|
+
if (busy) {
|
|
1631
|
+
return busy;
|
|
1632
|
+
}
|
|
1633
|
+
const [on, set] = fallback;
|
|
1634
|
+
return [
|
|
1635
|
+
on,
|
|
1636
|
+
async (action) => {
|
|
1637
|
+
set(true);
|
|
1638
|
+
try {
|
|
1639
|
+
await action();
|
|
1640
|
+
} finally {
|
|
1641
|
+
set(false);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
];
|
|
1645
|
+
}
|
|
1646
|
+
function hoursLabel(hours) {
|
|
1647
|
+
return hours === 1 ? dt("hours1") : hours === 24 ? dt("hours24") : dt("hours168");
|
|
1648
|
+
}
|
|
1649
|
+
function GrantDialog({ friend, name, ask, close }) {
|
|
1650
|
+
const cwd = pi.ui.useCwd();
|
|
1651
|
+
const [directory, setDirectory] = React.useState(cwd);
|
|
1652
|
+
const [picking, setPicking] = React.useState(false);
|
|
1653
|
+
const [hours, setHours] = React.useState(1);
|
|
1654
|
+
const [chosen, setChosen] = React.useState(ask ? [ask.capability] : ["files"]);
|
|
1655
|
+
const [error, setError] = React.useState();
|
|
1656
|
+
const [busy, run] = useBusy();
|
|
1657
|
+
const Folder = icon("Folder");
|
|
1658
|
+
const answer = (accept) => void run(async () => {
|
|
1659
|
+
setError(undefined);
|
|
1660
|
+
try {
|
|
1661
|
+
if (ask) {
|
|
1662
|
+
await callDoubles({ kind: "answer", ask: ask.id, accept, cwd: directory, hours });
|
|
1663
|
+
} else if (accept) {
|
|
1664
|
+
await callDoubles({ kind: "grant", friend, name, capabilities: chosen, cwd: directory, hours });
|
|
1665
|
+
}
|
|
1666
|
+
close();
|
|
1667
|
+
} catch (failure) {
|
|
1668
|
+
setError(message(failure));
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
const toggle = (capability, on) => setChosen((list) => on ? [...new Set([...list, capability])] : list.filter((each) => each !== capability));
|
|
1672
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
1673
|
+
title: ask ? dt("asksTitle") : dt("grantTitle", { name }),
|
|
1674
|
+
onClose: close
|
|
1675
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1676
|
+
className: "trm-dialog"
|
|
1677
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1678
|
+
className: "trm-grant-who"
|
|
1679
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1680
|
+
id: friend,
|
|
1681
|
+
name,
|
|
1682
|
+
size: 36
|
|
1683
|
+
}), /* @__PURE__ */ React.createElement("p", {
|
|
1684
|
+
className: "trm-lead"
|
|
1685
|
+
}, ask ? dt("askLead", { name, title: ask.title }) : dt("grantLead", { name }))), ask && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("blockquote", {
|
|
1686
|
+
className: "trm-grant-reason"
|
|
1687
|
+
}, ask.reason), /* @__PURE__ */ React.createElement("p", {
|
|
1688
|
+
className: "trm-lead"
|
|
1689
|
+
}, dt("askWants", { name, what: ask.capability === "files" ? dt("wantsFiles") : dt("wantsCommands") }))), !ask && /* @__PURE__ */ React.createElement("ul", {
|
|
1690
|
+
className: "trm-grant-list"
|
|
1691
|
+
}, ROOM_CAPABILITIES.map((capability) => /* @__PURE__ */ React.createElement("li", {
|
|
1692
|
+
key: capability,
|
|
1693
|
+
className: "trm-grant-item"
|
|
1694
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1695
|
+
className: "trm-grant-text"
|
|
1696
|
+
}, /* @__PURE__ */ React.createElement("span", null, capability === "files" ? dt("files") : dt("commands")), /* @__PURE__ */ React.createElement("span", {
|
|
1697
|
+
className: "trm-note"
|
|
1698
|
+
}, capability === "files" ? dt("filesHint") : dt("commandsHint"))), /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
1699
|
+
checked: chosen.includes(capability),
|
|
1700
|
+
label: capability === "files" ? dt("files") : dt("commands"),
|
|
1701
|
+
onChange: (on) => toggle(capability, on)
|
|
1702
|
+
})))), ask?.capability === "commands" && /* @__PURE__ */ React.createElement("p", {
|
|
1703
|
+
className: "trm-note"
|
|
1704
|
+
}, dt("commandsHint")), /* @__PURE__ */ React.createElement("div", {
|
|
1705
|
+
className: "trm-grant-field"
|
|
1706
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1707
|
+
className: "trm-grant-label"
|
|
1708
|
+
}, dt("directory")), /* @__PURE__ */ React.createElement("button", {
|
|
1709
|
+
type: "button",
|
|
1710
|
+
className: "trm-grant-dir",
|
|
1711
|
+
onClick: () => setPicking(true),
|
|
1712
|
+
title: directory
|
|
1713
|
+
}, /* @__PURE__ */ React.createElement(Folder, {
|
|
1714
|
+
size: 15
|
|
1715
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1716
|
+
className: "trm-ellipsis"
|
|
1717
|
+
}, directory || dt("pick")))), /* @__PURE__ */ React.createElement("div", {
|
|
1718
|
+
className: "trm-grant-field"
|
|
1719
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1720
|
+
className: "trm-grant-label"
|
|
1721
|
+
}, dt("duration")), /* @__PURE__ */ React.createElement("span", {
|
|
1722
|
+
className: "trm-chips"
|
|
1723
|
+
}, GRANT_HOURS.map((each) => /* @__PURE__ */ React.createElement("button", {
|
|
1724
|
+
key: each,
|
|
1725
|
+
type: "button",
|
|
1726
|
+
"aria-pressed": hours === each,
|
|
1727
|
+
className: `trm-chip${hours === each ? " trm-chip-on" : ""}`,
|
|
1728
|
+
onClick: () => setHours(each)
|
|
1729
|
+
}, hoursLabel(each))))), /* @__PURE__ */ React.createElement("p", {
|
|
1730
|
+
className: "trm-note"
|
|
1731
|
+
}, dt("grantNote")), error && /* @__PURE__ */ React.createElement("p", {
|
|
1732
|
+
className: "trm-error"
|
|
1733
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
1734
|
+
className: "trm-actions"
|
|
1735
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1736
|
+
type: "button",
|
|
1737
|
+
className: "ta-button",
|
|
1738
|
+
disabled: busy,
|
|
1739
|
+
onClick: () => ask ? answer(false) : close()
|
|
1740
|
+
}, ask ? dt("refuse") : dt("cancel")), ask && /* @__PURE__ */ React.createElement("button", {
|
|
1741
|
+
type: "button",
|
|
1742
|
+
className: "ta-button",
|
|
1743
|
+
disabled: busy,
|
|
1744
|
+
onClick: close
|
|
1745
|
+
}, dt("later")), /* @__PURE__ */ React.createElement("button", {
|
|
1746
|
+
type: "button",
|
|
1747
|
+
className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
|
|
1748
|
+
disabled: busy || !directory || chosen.length === 0,
|
|
1749
|
+
onClick: () => answer(true)
|
|
1750
|
+
}, dt("allow")))), picking && pi.ui.FolderPicker && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
1751
|
+
initial: directory,
|
|
1752
|
+
onPick: (path) => {
|
|
1753
|
+
setDirectory(path);
|
|
1754
|
+
setPicking(false);
|
|
1755
|
+
},
|
|
1756
|
+
onClose: () => setPicking(false)
|
|
1757
|
+
}));
|
|
1758
|
+
}
|
|
1759
|
+
function openGrant(member) {
|
|
1760
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(GrantDialog, {
|
|
1761
|
+
friend: member.id,
|
|
1762
|
+
name: member.name,
|
|
1763
|
+
close
|
|
1764
|
+
}));
|
|
1765
|
+
}
|
|
1766
|
+
var asking;
|
|
1767
|
+
function openAsk(ask) {
|
|
1768
|
+
if (asking) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
asking = ask.id;
|
|
1772
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(GrantDialog, {
|
|
1773
|
+
friend: ask.friend,
|
|
1774
|
+
name: ask.name,
|
|
1775
|
+
ask,
|
|
1776
|
+
close: () => {
|
|
1777
|
+
asking = undefined;
|
|
1778
|
+
close();
|
|
1779
|
+
}
|
|
1780
|
+
}));
|
|
1781
|
+
}
|
|
1782
|
+
function AskRow({ ask }) {
|
|
1783
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1784
|
+
className: "trm-row"
|
|
1785
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1786
|
+
id: ask.friend,
|
|
1787
|
+
name: ask.name
|
|
1788
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
1789
|
+
className: "trm-row-text"
|
|
1790
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1791
|
+
className: "trm-row-title"
|
|
1792
|
+
}, ask.name, /* @__PURE__ */ React.createElement("span", {
|
|
1793
|
+
className: "trm-tag"
|
|
1794
|
+
}, capabilityName(ask.capability))), /* @__PURE__ */ React.createElement("span", {
|
|
1795
|
+
className: "trm-row-line"
|
|
1796
|
+
}, dt("askLine", { name: ask.name, title: ask.title, reason: ask.reason }))), /* @__PURE__ */ React.createElement("div", {
|
|
1797
|
+
className: "trm-answers"
|
|
1798
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1799
|
+
type: "button",
|
|
1800
|
+
className: "ta-button ta-primary",
|
|
1801
|
+
onClick: () => openAsk(ask)
|
|
1802
|
+
}, dt("review"))));
|
|
1803
|
+
}
|
|
1804
|
+
function DoubleSwitch({ room }) {
|
|
1805
|
+
const { quiet } = useDoubles();
|
|
1806
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1807
|
+
className: "trm-double-switch"
|
|
1808
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1809
|
+
className: "trm-grant-text"
|
|
1810
|
+
}, /* @__PURE__ */ React.createElement("span", null, dt("answersHere")), /* @__PURE__ */ React.createElement("span", {
|
|
1811
|
+
className: "trm-note"
|
|
1812
|
+
}, dt("answersHint"))), /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
1813
|
+
checked: !quiet[room.id],
|
|
1814
|
+
label: dt("answersHere"),
|
|
1815
|
+
onChange: (on) => callDoubles({ kind: "quiet", room: room.id, quiet: !on }).catch((error) => pi.ui.notify(message(error), "error"))
|
|
1816
|
+
}));
|
|
1817
|
+
}
|
|
1818
|
+
function useMayLine(member) {
|
|
1819
|
+
const { grants } = useDoubles();
|
|
1820
|
+
return member.self || member.guest ? "" : mayLine(grantsOf(grants, member.id));
|
|
1821
|
+
}
|
|
1822
|
+
async function revokeAll(friend, name) {
|
|
1823
|
+
if (await pi.ui.confirm(dt("revokeAllTitle", { name }), dt("revokeAllHint", { name }), { confirmLabel: dt("stop"), danger: true })) {
|
|
1824
|
+
await callDoubles({ kind: "revokeAll", friend }).catch((error) => pi.ui.notify(message(error), "error"));
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
function GrantRow({ grant }) {
|
|
1828
|
+
const [busy, run] = useBusy();
|
|
1829
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1830
|
+
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
1831
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1832
|
+
id: grant.friend,
|
|
1833
|
+
name: grant.name,
|
|
1834
|
+
size: 30
|
|
1835
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
1836
|
+
className: "trm-row-text"
|
|
1837
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1838
|
+
className: "trm-row-title"
|
|
1839
|
+
}, grant.name, /* @__PURE__ */ React.createElement("span", {
|
|
1840
|
+
className: "trm-tag"
|
|
1841
|
+
}, capabilityName(grant.capability))), /* @__PURE__ */ React.createElement("span", {
|
|
1842
|
+
className: "trm-row-line trm-ellipsis",
|
|
1843
|
+
title: grant.cwd
|
|
1844
|
+
}, grant.cwd, " · ", left(grant.expiresAt))), /* @__PURE__ */ React.createElement("button", {
|
|
1845
|
+
type: "button",
|
|
1846
|
+
className: "ta-button",
|
|
1847
|
+
disabled: busy,
|
|
1848
|
+
onClick: () => void run(() => callDoubles({ kind: "revoke", grant: grant.id }).catch((error) => pi.ui.notify(message(error), "error")))
|
|
1849
|
+
}, dt("revoke")));
|
|
1850
|
+
}
|
|
1851
|
+
function LogRow({ entry }) {
|
|
1852
|
+
const outcome = entry.outcome === "answered" ? dt("answered") : entry.outcome === "failed" ? dt("failed") : dt("limited");
|
|
1853
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1854
|
+
className: "trm-log"
|
|
1855
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1856
|
+
className: "trm-log-head"
|
|
1857
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1858
|
+
id: entry.friend,
|
|
1859
|
+
name: entry.name,
|
|
1860
|
+
size: 22
|
|
1861
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1862
|
+
className: "trm-log-who trm-ellipsis"
|
|
1863
|
+
}, entry.agent ? dt("agentAsked", { name: entry.name, agent: entry.agent }) : dt("asked", { name: entry.name }), " · ", entry.title), /* @__PURE__ */ React.createElement("span", {
|
|
1864
|
+
className: "trm-log-time"
|
|
1865
|
+
}, when(entry.at))), /* @__PURE__ */ React.createElement("div", {
|
|
1866
|
+
className: "trm-log-asked"
|
|
1867
|
+
}, entry.asked), entry.answer && /* @__PURE__ */ React.createElement("div", {
|
|
1868
|
+
className: "trm-log-answer"
|
|
1869
|
+
}, entry.answer), /* @__PURE__ */ React.createElement("div", {
|
|
1870
|
+
className: `trm-log-meta${entry.outcome === "answered" ? "" : " trm-log-bad"}`
|
|
1871
|
+
}, [
|
|
1872
|
+
outcome,
|
|
1873
|
+
...entry.capabilities.length ? [entry.capabilities.map(capabilityName).join(" · ")] : [],
|
|
1874
|
+
...entry.tools.length ? [dt("tools", { n: entry.tools.length })] : [],
|
|
1875
|
+
...entry.error ? [entry.error] : []
|
|
1876
|
+
].join(" · ")));
|
|
1877
|
+
}
|
|
1878
|
+
function DoublesView() {
|
|
1879
|
+
const { grants, asks, log } = useDoubles();
|
|
1880
|
+
const now = Date.now();
|
|
1881
|
+
const live = grants.filter((grant) => grant.expiresAt > now);
|
|
1882
|
+
const friends = [...new Map(live.map((grant) => [grant.friend, grant.name])).entries()];
|
|
1883
|
+
const recent = [...log].reverse();
|
|
1884
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1885
|
+
className: "trm-panel"
|
|
1886
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1887
|
+
className: "trm-panel-scroll"
|
|
1888
|
+
}, asks.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
1889
|
+
className: "trm-panel-label"
|
|
1890
|
+
}, dt("asksTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
1891
|
+
className: "trm-rows"
|
|
1892
|
+
}, asks.map((ask) => /* @__PURE__ */ React.createElement(AskRow, {
|
|
1893
|
+
key: ask.id,
|
|
1894
|
+
ask
|
|
1895
|
+
})))), /* @__PURE__ */ React.createElement("div", {
|
|
1896
|
+
className: "trm-panel-label"
|
|
1897
|
+
}, dt("grants")), live.length === 0 ? /* @__PURE__ */ React.createElement("p", {
|
|
1898
|
+
className: "trm-note trm-panel-note"
|
|
1899
|
+
}, dt("noGrants")) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("ul", {
|
|
1900
|
+
className: "trm-rows"
|
|
1901
|
+
}, live.map((grant) => /* @__PURE__ */ React.createElement(GrantRow, {
|
|
1902
|
+
key: grant.id,
|
|
1903
|
+
grant
|
|
1904
|
+
}))), friends.map(([friend, name]) => /* @__PURE__ */ React.createElement("button", {
|
|
1905
|
+
key: friend,
|
|
1906
|
+
type: "button",
|
|
1907
|
+
className: "trm-link trm-danger trm-panel-note",
|
|
1908
|
+
onClick: () => void revokeAll(friend, name)
|
|
1909
|
+
}, dt("revokeAll", { name })))), /* @__PURE__ */ React.createElement("div", {
|
|
1910
|
+
className: "trm-panel-label trm-log-label"
|
|
1911
|
+
}, /* @__PURE__ */ React.createElement("span", null, dt("logTitle")), recent.length > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
1912
|
+
type: "button",
|
|
1913
|
+
className: "trm-link",
|
|
1914
|
+
onClick: () => void callDoubles({ kind: "clearLog" }).catch((error) => pi.ui.notify(message(error), "error"))
|
|
1915
|
+
}, dt("clearLog"))), recent.length === 0 ? /* @__PURE__ */ React.createElement("div", {
|
|
1916
|
+
className: "trm-log-empty"
|
|
1917
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
1918
|
+
title: dt("logEmpty"),
|
|
1919
|
+
hint: dt("logEmptyHint"),
|
|
1920
|
+
compact: true
|
|
1921
|
+
})) : /* @__PURE__ */ React.createElement("ul", {
|
|
1922
|
+
className: "trm-logs"
|
|
1923
|
+
}, recent.map((entry) => /* @__PURE__ */ React.createElement(LogRow, {
|
|
1924
|
+
key: entry.id,
|
|
1925
|
+
entry
|
|
1926
|
+
})))));
|
|
1927
|
+
}
|
|
1928
|
+
function listenAsks() {
|
|
1929
|
+
doubles.onAsk = (asks) => {
|
|
1930
|
+
const latest = asks[asks.length - 1];
|
|
1931
|
+
if (latest) {
|
|
1932
|
+
openAsk(latest);
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
const stop = doubles.start();
|
|
1936
|
+
return () => {
|
|
1937
|
+
doubles.onAsk = undefined;
|
|
1938
|
+
stop();
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// web-src/room-view.tsx
|
|
1943
|
+
var RUN_MS = 5 * 60 * 1000;
|
|
1944
|
+
var PAUSE_MS = 15 * 60 * 1000;
|
|
1945
|
+
async function confirmThen(title, hint, label, action) {
|
|
1946
|
+
if (!await pi.ui.confirm(title, hint, { confirmLabel: label, danger: true })) {
|
|
1947
|
+
return false;
|
|
1948
|
+
}
|
|
1949
|
+
try {
|
|
1950
|
+
await action();
|
|
1951
|
+
} catch (error) {
|
|
1952
|
+
pi.ui.notify(message(error), "error");
|
|
1953
|
+
}
|
|
1954
|
+
await book.load();
|
|
1955
|
+
return true;
|
|
1956
|
+
}
|
|
1957
|
+
function leaveRoom(room) {
|
|
1958
|
+
if (room.status !== "member") {
|
|
1959
|
+
return (rooms()?.leave(room.id) ?? Promise.resolve()).then(() => book.load()).then(() => true);
|
|
1960
|
+
}
|
|
1961
|
+
return confirmThen(room.owner ? t("closeTitle", { title: room.title }) : t("leaveTitle", { title: room.title }), room.owner ? t("closeHint") : t("leaveHint"), room.owner ? t("close") : t("leave"), async () => rooms()?.leave(room.id));
|
|
1962
|
+
}
|
|
1963
|
+
function speaker(line) {
|
|
1964
|
+
return `${line.from}:${line.double ? "d" : ""}:${line.agent?.id ?? ""}`;
|
|
1965
|
+
}
|
|
1966
|
+
function time(at) {
|
|
1967
|
+
const date = new Date(at);
|
|
1968
|
+
const clock = date.toLocaleTimeString(pi.ui.language, { hour: "2-digit", minute: "2-digit" });
|
|
1969
|
+
return date.toDateString() === new Date().toDateString() ? clock : `${date.toLocaleDateString(pi.ui.language, { month: "numeric", day: "numeric" })} ${clock}`;
|
|
1970
|
+
}
|
|
1971
|
+
function RoomHead({ room }) {
|
|
1972
|
+
const shown = !!pi.ui.useView?.(MEMBERS_VIEW)?.shown;
|
|
1973
|
+
const page = usePageOf(room);
|
|
1974
|
+
const online = room.members.filter((member) => member.online).length;
|
|
1975
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1976
|
+
className: "trm-room-head"
|
|
1977
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1978
|
+
className: "trm-room-head-title"
|
|
1979
|
+
}, /* @__PURE__ */ React.createElement("strong", {
|
|
1980
|
+
className: "trm-ellipsis"
|
|
1981
|
+
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
1982
|
+
className: "trm-room-head-count"
|
|
1983
|
+
}, t("memberCount", { n: room.members.length })), /* @__PURE__ */ React.createElement("span", {
|
|
1984
|
+
className: `trm-room-head-sub${room.connected ? "" : " trm-quiet"}`
|
|
1985
|
+
}, !room.connected ? t("connecting") : page ? page.title : t("onlineCount", { n: online }))), /* @__PURE__ */ React.createElement(MemberFaces, {
|
|
1986
|
+
room,
|
|
1987
|
+
shown,
|
|
1988
|
+
onClick: () => void pi.ui.showView(MEMBERS_VIEW)
|
|
1989
|
+
}));
|
|
1990
|
+
}
|
|
1991
|
+
function PageLine({ room }) {
|
|
1992
|
+
const page = usePageOf(room);
|
|
1993
|
+
if (!page || !room.view) {
|
|
1994
|
+
return null;
|
|
1995
|
+
}
|
|
1996
|
+
const Icon = page.icon ?? icon("ExternalLink");
|
|
1997
|
+
const Chevron = icon("ChevronRight");
|
|
1998
|
+
const view = room.view;
|
|
1999
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
2000
|
+
type: "button",
|
|
2001
|
+
className: "trm-page-line",
|
|
2002
|
+
onClick: () => void pi.ui.showView(view)
|
|
2003
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2004
|
+
className: "trm-page-line-icon"
|
|
2005
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
2006
|
+
size: 15
|
|
2007
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
2008
|
+
className: "trm-page-line-text"
|
|
2009
|
+
}, t("pageLine", { name: page.title })), /* @__PURE__ */ React.createElement("span", {
|
|
2010
|
+
className: "trm-page-line-open"
|
|
2011
|
+
}, t("openPage", { name: page.title }), /* @__PURE__ */ React.createElement(Chevron, {
|
|
2012
|
+
size: 14
|
|
2013
|
+
})));
|
|
2014
|
+
}
|
|
2015
|
+
function RoomView({ room, head, onBack }) {
|
|
2016
|
+
const Back = icon("ArrowLeft");
|
|
2017
|
+
const chat = book.chat(room.id);
|
|
2018
|
+
const lines = useLines(room);
|
|
2019
|
+
const agents = useAgents(room);
|
|
2020
|
+
const joining = useJoining(room);
|
|
2021
|
+
const list = React.useRef(null);
|
|
2022
|
+
const stuck = React.useRef(true);
|
|
2023
|
+
const self = room.members.find((member) => member.self);
|
|
2024
|
+
const personOf = (line) => room.members.find((member) => member.member === line.from)?.name ?? line.name;
|
|
2025
|
+
const nameOf = (line) => line.agent ? line.agent.name : !line.double ? personOf(line) : line.from === self?.member ? dt("myDouble") : dt("doubleOf", { name: personOf(line) });
|
|
2026
|
+
const tagOf = (line) => line.agent ? agentOwner(room, { member: line.from }) : line.double ? dt("doubleTag") : "";
|
|
2027
|
+
const mentions = React.useMemo(() => [...agentMentions(room, agents), ...askable(room).map((member) => ({ name: mentionName(member.name), detail: dt("mentionDetail") }))], [room, agents]);
|
|
2028
|
+
React.useLayoutEffect(() => {
|
|
2029
|
+
const element = list.current;
|
|
2030
|
+
if (element && stuck.current) {
|
|
2031
|
+
element.scrollTop = element.scrollHeight;
|
|
2032
|
+
}
|
|
2033
|
+
}, [lines, joining]);
|
|
2034
|
+
React.useEffect(() => {
|
|
2035
|
+
if (pi.ui.Stack) {
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
2038
|
+
return pi.onRoomEvent?.((event) => book.heard(event), { messages: true });
|
|
2039
|
+
}, []);
|
|
2040
|
+
React.useEffect(() => {
|
|
2041
|
+
const last = lines[lines.length - 1];
|
|
2042
|
+
if (last) {
|
|
2043
|
+
book.see(room.id, last.at);
|
|
2044
|
+
}
|
|
2045
|
+
}, [lines, room.id]);
|
|
2046
|
+
const say = async (text) => {
|
|
2047
|
+
if (!self || !chat) {
|
|
2048
|
+
throw new Error(t("connecting"));
|
|
2049
|
+
}
|
|
2050
|
+
stuck.current = true;
|
|
2051
|
+
const to = addressed(text, room, agents);
|
|
2052
|
+
await chat.say(text, self, to.length ? { to } : {});
|
|
2053
|
+
};
|
|
2054
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2055
|
+
className: "trm-room-page"
|
|
2056
|
+
}, head && /* @__PURE__ */ React.createElement("div", {
|
|
2057
|
+
className: "trm-room-bar"
|
|
2058
|
+
}, onBack && /* @__PURE__ */ React.createElement("button", {
|
|
2059
|
+
type: "button",
|
|
2060
|
+
className: "trm-icon",
|
|
2061
|
+
title: t("back"),
|
|
2062
|
+
"aria-label": t("back"),
|
|
2063
|
+
onClick: onBack
|
|
2064
|
+
}, /* @__PURE__ */ React.createElement(Back, {
|
|
2065
|
+
size: 18
|
|
2066
|
+
})), /* @__PURE__ */ React.createElement(RoomHead, {
|
|
2067
|
+
room
|
|
2068
|
+
})), /* @__PURE__ */ React.createElement(PageLine, {
|
|
2069
|
+
room
|
|
2070
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2071
|
+
className: "trm-chat ta-conversation",
|
|
2072
|
+
ref: list,
|
|
2073
|
+
onScroll: (event) => {
|
|
2074
|
+
const element = event.currentTarget;
|
|
2075
|
+
stuck.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
|
|
2076
|
+
}
|
|
2077
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2078
|
+
className: "trm-chat-col"
|
|
2079
|
+
}, lines.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
2080
|
+
className: "trm-chat-empty"
|
|
2081
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
2082
|
+
room,
|
|
2083
|
+
size: 56
|
|
2084
|
+
}), /* @__PURE__ */ React.createElement("strong", null, room.title), /* @__PURE__ */ React.createElement("span", null, room.owner ? t("ownRoom") : t("roomOf", { name: room.ownerName })), /* @__PURE__ */ React.createElement("span", {
|
|
2085
|
+
className: "trm-chat-hint"
|
|
2086
|
+
}, t("chatEmpty")), agents.length === 0 && joining.length === 0 && room.members.length < 2 && /* @__PURE__ */ React.createElement("button", {
|
|
2087
|
+
type: "button",
|
|
2088
|
+
className: "ta-button trm-try-alone",
|
|
2089
|
+
onClick: () => openAgentPicker(room)
|
|
2090
|
+
}, dt("inviteAgent"))), lines.map((line, index) => {
|
|
2091
|
+
const before = lines[index - 1];
|
|
2092
|
+
const separator = !before || line.at - before.at > PAUSE_MS;
|
|
2093
|
+
const first = separator || speaker(before) !== speaker(line) || line.at - before.at > RUN_MS;
|
|
2094
|
+
const other = room.members.find((member) => member.member === line.from);
|
|
2095
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
2096
|
+
key: line.id
|
|
2097
|
+
}, separator && /* @__PURE__ */ React.createElement("div", {
|
|
2098
|
+
className: "trm-chat-time"
|
|
2099
|
+
}, time(line.at)), line.from === self?.member && !line.double && !line.agent ? /* @__PURE__ */ React.createElement("div", {
|
|
2100
|
+
className: "ta-message ta-user trm-mine",
|
|
2101
|
+
title: time(line.at)
|
|
2102
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2103
|
+
className: "ta-bubble"
|
|
2104
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
2105
|
+
text: line.text
|
|
2106
|
+
}))) : /* @__PURE__ */ React.createElement("div", {
|
|
2107
|
+
className: `trm-msg${first ? " trm-first" : ""}${line.double ? " trm-double" : ""}${line.agent ? " trm-agent" : ""}`
|
|
2108
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2109
|
+
className: "trm-msg-face"
|
|
2110
|
+
}, first && /* @__PURE__ */ React.createElement(Face, {
|
|
2111
|
+
id: line.agent?.id ?? other?.id ?? line.from,
|
|
2112
|
+
name: nameOf(line),
|
|
2113
|
+
face: line.agent && agents.find((agent) => agent.id === line.agent?.id && agent.member === line.from)?.face,
|
|
2114
|
+
size: 28
|
|
2115
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
2116
|
+
className: "trm-msg-col"
|
|
2117
|
+
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
2118
|
+
className: "trm-msg-name"
|
|
2119
|
+
}, nameOf(line), tagOf(line) && /* @__PURE__ */ React.createElement("span", {
|
|
2120
|
+
className: `trm-tag ${line.agent ? "trm-tag-agent" : "trm-tag-double"}`
|
|
2121
|
+
}, tagOf(line))), /* @__PURE__ */ React.createElement("div", {
|
|
2122
|
+
className: "trm-msg-bubble",
|
|
2123
|
+
title: time(line.at)
|
|
2124
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
2125
|
+
text: line.text
|
|
2126
|
+
})))));
|
|
2127
|
+
}), joining.map((agent) => /* @__PURE__ */ React.createElement("div", {
|
|
2128
|
+
key: agent.id,
|
|
2129
|
+
className: "trm-chat-joining",
|
|
2130
|
+
role: "status"
|
|
2131
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2132
|
+
className: "ta-spinner"
|
|
2133
|
+
}), dt("joiningRoom", { name: agent.name }))))), /* @__PURE__ */ React.createElement("div", {
|
|
2134
|
+
className: "trm-chat-bottom"
|
|
2135
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Composer, {
|
|
2136
|
+
placeholder: t("chatPlaceholder"),
|
|
2137
|
+
onSend: say,
|
|
2138
|
+
mentions,
|
|
2139
|
+
mentionLabel: dt("mentionLabel")
|
|
2140
|
+
})));
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// web-src/agents-view.tsx
|
|
2144
|
+
function agentOwner(room, agent) {
|
|
2145
|
+
const owner = room.members.find((member) => member.member === agent.member);
|
|
2146
|
+
return owner?.self ? dt("myAgent") : dt("agentOf", { name: owner?.name ?? "" });
|
|
2147
|
+
}
|
|
2148
|
+
function agentMentions(room, agents) {
|
|
2149
|
+
return agents.map((agent) => ({ name: agent.name, detail: agentOwner(room, agent) }));
|
|
2150
|
+
}
|
|
2151
|
+
function inviteAgent(room, agent) {
|
|
2152
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
2153
|
+
const joining = { id: agent.id, name: agent.name, ...typeof agent.face === "number" ? { face: agent.face } : {} };
|
|
2154
|
+
const chat = book.chat(room.id);
|
|
2155
|
+
const before = new Set(chat?.lines.map((line) => line.id));
|
|
2156
|
+
book.setJoining(room.id, joining, true);
|
|
2157
|
+
callDoubles({ kind: "invite", room: room.id, agent: agent.id }).then(async (list) => {
|
|
2158
|
+
if (self && Array.isArray(list)) {
|
|
2159
|
+
book.putMine(room.id, self, list);
|
|
2160
|
+
}
|
|
2161
|
+
if (chat) {
|
|
2162
|
+
await saidHello(chat, (line) => !before.has(line.id) && line.agent?.id === agent.id && line.from === self);
|
|
2163
|
+
}
|
|
2164
|
+
}).catch((failure) => pi.ui.notify(dt("inviteFailed", { name: agent.name, error: message(failure) }), "error")).finally(() => book.setJoining(room.id, joining, false));
|
|
2165
|
+
}
|
|
2166
|
+
var HELLO_MS = 1e4;
|
|
2167
|
+
function saidHello(chat, hello) {
|
|
2168
|
+
return new Promise((resolve) => {
|
|
2169
|
+
const check = () => {
|
|
2170
|
+
if (chat.lines.some(hello)) {
|
|
2171
|
+
done();
|
|
2172
|
+
}
|
|
2173
|
+
};
|
|
2174
|
+
const stop = chat.subscribe(check);
|
|
2175
|
+
const timer = setTimeout(() => done(), HELLO_MS);
|
|
2176
|
+
const done = () => {
|
|
2177
|
+
stop();
|
|
2178
|
+
clearTimeout(timer);
|
|
2179
|
+
resolve();
|
|
2180
|
+
};
|
|
2181
|
+
check();
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
function AgentPicker({ room, close }) {
|
|
2185
|
+
const [agents, setAgents] = React.useState();
|
|
2186
|
+
const [error, setError] = React.useState();
|
|
2187
|
+
const inRoom = useAgents(room);
|
|
2188
|
+
const joining = useJoining(room);
|
|
2189
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
2190
|
+
React.useEffect(() => {
|
|
2191
|
+
callDoubles({ kind: "agents" }).then((list) => setAgents(Array.isArray(list) ? list : []), (failure) => setError(message(failure)));
|
|
2192
|
+
}, []);
|
|
2193
|
+
const invite = (agent) => {
|
|
2194
|
+
inviteAgent(room, agent);
|
|
2195
|
+
close();
|
|
2196
|
+
};
|
|
2197
|
+
const Plus = icon("Plus");
|
|
2198
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
2199
|
+
title: dt("pickAgentTitle", { title: room.title }),
|
|
2200
|
+
onClose: close
|
|
2201
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2202
|
+
className: "trm-dialog"
|
|
2203
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
2204
|
+
className: "trm-note"
|
|
2205
|
+
}, dt("pickAgentLead")), !agents && !error && pi.ui.Skeleton && /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
2206
|
+
rows: 3
|
|
2207
|
+
}), agents?.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2208
|
+
title: dt("noAgents"),
|
|
2209
|
+
hint: dt("noAgentsHint"),
|
|
2210
|
+
compact: true
|
|
2211
|
+
}), agents && agents.length > 0 && /* @__PURE__ */ React.createElement("ul", {
|
|
2212
|
+
className: "trm-rows trm-agent-pick"
|
|
2213
|
+
}, agents.map((agent) => {
|
|
2214
|
+
const joined = inRoom.some((each) => each.id === agent.id && each.member === self);
|
|
2215
|
+
const coming = joining.some((each) => each.id === agent.id);
|
|
2216
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2217
|
+
key: agent.id
|
|
2218
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2219
|
+
type: "button",
|
|
2220
|
+
className: "trm-member",
|
|
2221
|
+
disabled: joined || coming,
|
|
2222
|
+
onClick: () => invite(agent)
|
|
2223
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2224
|
+
id: agent.id,
|
|
2225
|
+
name: agent.name,
|
|
2226
|
+
face: agent.face,
|
|
2227
|
+
size: 34
|
|
2228
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2229
|
+
className: "trm-member-text"
|
|
2230
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2231
|
+
className: "trm-member-name trm-ellipsis"
|
|
2232
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
2233
|
+
className: "trm-member-detail trm-ellipsis"
|
|
2234
|
+
}, joined ? dt("inRoom") : coming ? dt("joining") : agent.role)), coming ? /* @__PURE__ */ React.createElement("span", {
|
|
2235
|
+
className: "ta-spinner"
|
|
2236
|
+
}) : !joined && /* @__PURE__ */ React.createElement(Plus, {
|
|
2237
|
+
size: 16
|
|
2238
|
+
})));
|
|
2239
|
+
})), error && /* @__PURE__ */ React.createElement("p", {
|
|
2240
|
+
className: "trm-error"
|
|
2241
|
+
}, error)));
|
|
2242
|
+
}
|
|
2243
|
+
function openAgentPicker(room) {
|
|
2244
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(AgentPicker, {
|
|
2245
|
+
room,
|
|
2246
|
+
close
|
|
2247
|
+
}));
|
|
2248
|
+
}
|
|
2249
|
+
function JoiningRow({ agent }) {
|
|
2250
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2251
|
+
className: "trm-member",
|
|
2252
|
+
"aria-busy": "true"
|
|
2253
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2254
|
+
id: agent.id,
|
|
2255
|
+
name: agent.name,
|
|
2256
|
+
face: agent.face,
|
|
2257
|
+
size: 34
|
|
2258
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2259
|
+
className: "trm-member-text"
|
|
2260
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2261
|
+
className: "trm-member-name trm-ellipsis"
|
|
2262
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
2263
|
+
className: "trm-member-detail trm-ellipsis"
|
|
2264
|
+
}, dt("joining"))), /* @__PURE__ */ React.createElement("span", {
|
|
2265
|
+
className: "ta-spinner trm-member-action"
|
|
2266
|
+
}));
|
|
2267
|
+
}
|
|
2268
|
+
function AgentRow({ room, agent }) {
|
|
2269
|
+
const Remove = icon("X");
|
|
2270
|
+
const mine = room.members.find((member) => member.self)?.member === agent.member;
|
|
2271
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2272
|
+
className: "trm-member"
|
|
2273
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2274
|
+
id: agent.id,
|
|
2275
|
+
name: agent.name,
|
|
2276
|
+
face: agent.face,
|
|
2277
|
+
size: 34
|
|
2278
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2279
|
+
className: "trm-member-text"
|
|
2280
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2281
|
+
className: "trm-member-name"
|
|
2282
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2283
|
+
className: "trm-ellipsis"
|
|
2284
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
2285
|
+
className: "trm-tag trm-tag-agent"
|
|
2286
|
+
}, agentOwner(room, agent))), agent.role && /* @__PURE__ */ React.createElement("span", {
|
|
2287
|
+
className: "trm-member-detail trm-ellipsis"
|
|
2288
|
+
}, agent.role)), mine && /* @__PURE__ */ React.createElement("button", {
|
|
2289
|
+
type: "button",
|
|
2290
|
+
className: "trm-icon trm-danger trm-member-action",
|
|
2291
|
+
title: dt("dismiss"),
|
|
2292
|
+
"aria-label": dt("dismiss"),
|
|
2293
|
+
onClick: () => void confirmThen(dt("dismissTitle", { name: agent.name, title: room.title }), dt("dismissHint"), dt("dismiss"), () => callDoubles({ kind: "dismiss", room: room.id, agent: agent.id })).then(() => book.agents(room.id))
|
|
2294
|
+
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
2295
|
+
size: 15
|
|
2296
|
+
})));
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
// web-src/members-view.tsx
|
|
2300
|
+
function MemberRow({ room, member }) {
|
|
2301
|
+
const Remove = icon("X");
|
|
2302
|
+
const Key = pi.ui.icons.KeyRound ?? icon("Bot");
|
|
2303
|
+
const may = useMayLine(member);
|
|
2304
|
+
const tags = [member.self ? t("you") : "", member.owner ? t("owner") : "", member.guest ? t("guestTag") : ""].filter(Boolean);
|
|
2305
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2306
|
+
className: "trm-member"
|
|
2307
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2308
|
+
id: member.id,
|
|
2309
|
+
name: member.name,
|
|
2310
|
+
size: 34,
|
|
2311
|
+
online: member.online
|
|
2312
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2313
|
+
className: "trm-member-text"
|
|
2314
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2315
|
+
className: "trm-member-name"
|
|
2316
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2317
|
+
className: "trm-ellipsis"
|
|
2318
|
+
}, member.name), tags.map((tag) => /* @__PURE__ */ React.createElement("span", {
|
|
2319
|
+
key: tag,
|
|
2320
|
+
className: "trm-tag"
|
|
2321
|
+
}, tag))), /* @__PURE__ */ React.createElement("span", {
|
|
2322
|
+
className: `trm-member-detail${member.online ? " trm-live" : ""}`
|
|
2323
|
+
}, member.online ? t("online") : t("offline")), may && /* @__PURE__ */ React.createElement("span", {
|
|
2324
|
+
className: "trm-member-detail trm-member-may trm-ellipsis"
|
|
2325
|
+
}, may)), !member.self && !member.guest && /* @__PURE__ */ React.createElement("button", {
|
|
2326
|
+
type: "button",
|
|
2327
|
+
className: `trm-icon trm-member-action${may ? " trm-on-icon" : ""}`,
|
|
2328
|
+
title: dt("permissions"),
|
|
2329
|
+
"aria-label": dt("permissions"),
|
|
2330
|
+
onClick: () => openGrant(member)
|
|
2331
|
+
}, /* @__PURE__ */ React.createElement(Key, {
|
|
2332
|
+
size: 15
|
|
2333
|
+
})), room.owner && !member.self && /* @__PURE__ */ React.createElement("button", {
|
|
2334
|
+
type: "button",
|
|
2335
|
+
className: "trm-icon trm-danger trm-member-action",
|
|
2336
|
+
title: t("remove"),
|
|
2337
|
+
"aria-label": t("remove"),
|
|
2338
|
+
onClick: () => void confirmThen(t("removeTitle", { name: member.name, title: room.title }), t("removeHint"), t("remove"), async () => rooms()?.removeMember(room.id, member.member))
|
|
2339
|
+
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
2340
|
+
size: 15
|
|
2341
|
+
})));
|
|
2342
|
+
}
|
|
2343
|
+
function SettingRow({ label, value, onClick }) {
|
|
2344
|
+
const Chevron = icon("ChevronRight");
|
|
2345
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
2346
|
+
type: "button",
|
|
2347
|
+
className: "trm-setting",
|
|
2348
|
+
onClick
|
|
2349
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2350
|
+
className: "trm-setting-label"
|
|
2351
|
+
}, label), value && /* @__PURE__ */ React.createElement("span", {
|
|
2352
|
+
className: "trm-setting-value trm-ellipsis"
|
|
2353
|
+
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
2354
|
+
size: 15
|
|
2355
|
+
}));
|
|
2356
|
+
}
|
|
2357
|
+
function MembersView() {
|
|
2358
|
+
const { identity } = useBook();
|
|
2359
|
+
const room = useOpened();
|
|
2360
|
+
const page = usePageOf(room ?? { view: undefined });
|
|
2361
|
+
const agents = useAgents(room ?? { status: "gone" });
|
|
2362
|
+
const joining = useJoining(room ?? { id: "", status: "gone", members: [] });
|
|
2363
|
+
if (!room) {
|
|
2364
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2365
|
+
className: "trm-panel"
|
|
2366
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2367
|
+
title: t("noRoomOpen")
|
|
2368
|
+
}));
|
|
2369
|
+
}
|
|
2370
|
+
const Plus = icon("Plus");
|
|
2371
|
+
const Bot = icon("Bot");
|
|
2372
|
+
const online = room.members.filter((member) => member.online).length;
|
|
2373
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
2374
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2375
|
+
className: "trm-panel"
|
|
2376
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2377
|
+
className: "trm-panel-scroll"
|
|
2378
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2379
|
+
className: "trm-panel-top"
|
|
2380
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
2381
|
+
room,
|
|
2382
|
+
size: 44
|
|
2383
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2384
|
+
className: "trm-panel-title"
|
|
2385
|
+
}, /* @__PURE__ */ React.createElement("strong", {
|
|
2386
|
+
className: "trm-ellipsis"
|
|
2387
|
+
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
2388
|
+
className: "trm-ellipsis"
|
|
2389
|
+
}, room.owner ? t("ownRoom") : t("roomOf", { name: room.ownerName })))), /* @__PURE__ */ React.createElement("div", {
|
|
2390
|
+
className: "trm-panel-label"
|
|
2391
|
+
}, t("membersCount", { n: room.members.length, online })), /* @__PURE__ */ React.createElement("ul", {
|
|
2392
|
+
className: "trm-panel-members"
|
|
2393
|
+
}, room.owner && /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
2394
|
+
type: "button",
|
|
2395
|
+
className: "trm-member trm-member-add",
|
|
2396
|
+
onClick: () => openInvite(room)
|
|
2397
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2398
|
+
className: "trm-member-plus"
|
|
2399
|
+
}, /* @__PURE__ */ React.createElement(Plus, {
|
|
2400
|
+
size: 16
|
|
2401
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
2402
|
+
className: "trm-member-text"
|
|
2403
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2404
|
+
className: "trm-member-name"
|
|
2405
|
+
}, t("invite")), /* @__PURE__ */ React.createElement("span", {
|
|
2406
|
+
className: "trm-member-detail"
|
|
2407
|
+
}, t("inviteLine"))))), room.members.map((member) => /* @__PURE__ */ React.createElement(MemberRow, {
|
|
2408
|
+
key: member.member,
|
|
2409
|
+
room,
|
|
2410
|
+
member
|
|
2411
|
+
}))), /* @__PURE__ */ React.createElement("div", {
|
|
2412
|
+
className: "trm-panel-label"
|
|
2413
|
+
}, agents.length ? `${dt("agentsTitle")} · ${agents.length}` : dt("agentsTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
2414
|
+
className: "trm-panel-members"
|
|
2415
|
+
}, /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
2416
|
+
type: "button",
|
|
2417
|
+
className: "trm-member trm-member-add",
|
|
2418
|
+
onClick: () => openAgentPicker(room)
|
|
2419
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2420
|
+
className: "trm-member-plus"
|
|
2421
|
+
}, /* @__PURE__ */ React.createElement(Bot, {
|
|
2422
|
+
size: 16
|
|
2423
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
2424
|
+
className: "trm-member-text"
|
|
2425
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2426
|
+
className: "trm-member-name"
|
|
2427
|
+
}, dt("inviteAgent")), /* @__PURE__ */ React.createElement("span", {
|
|
2428
|
+
className: "trm-member-detail"
|
|
2429
|
+
}, dt("inviteAgentLine"))))), agents.map((agent) => /* @__PURE__ */ React.createElement(AgentRow, {
|
|
2430
|
+
key: `${agent.member}/${agent.id}`,
|
|
2431
|
+
room,
|
|
2432
|
+
agent
|
|
2433
|
+
})), joining.filter((agent) => !agents.some((each) => each.id === agent.id && each.member === self)).map((agent) => /* @__PURE__ */ React.createElement(JoiningRow, {
|
|
2434
|
+
key: `joining/${agent.id}`,
|
|
2435
|
+
agent
|
|
2436
|
+
}))), /* @__PURE__ */ React.createElement("div", {
|
|
2437
|
+
className: "trm-panel-sep"
|
|
2438
|
+
}), /* @__PURE__ */ React.createElement(DoubleSwitch, {
|
|
2439
|
+
room
|
|
2440
|
+
}), /* @__PURE__ */ React.createElement(SettingRow, {
|
|
2441
|
+
label: dt("log"),
|
|
2442
|
+
onClick: () => void pi.ui.showView(DOUBLES_VIEW)
|
|
2443
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2444
|
+
className: "trm-panel-sep"
|
|
2445
|
+
}), page && room.view && /* @__PURE__ */ React.createElement(SettingRow, {
|
|
2446
|
+
label: t("openPage", { name: page.title }),
|
|
2447
|
+
onClick: () => void pi.ui.showView(room.view)
|
|
2448
|
+
}), /* @__PURE__ */ React.createElement(SettingRow, {
|
|
2449
|
+
label: t("me"),
|
|
2450
|
+
value: identity?.name,
|
|
2451
|
+
onClick: () => void rename()
|
|
2452
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
2453
|
+
className: "trm-panel-foot"
|
|
2454
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2455
|
+
type: "button",
|
|
2456
|
+
className: "trm-link trm-danger",
|
|
2457
|
+
onClick: () => void leaveRoom(room).then((left2) => left2 && book.set({ opened: undefined }))
|
|
2458
|
+
}, room.owner ? t("close") : t("leave"))));
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// web-src/rooms-page.tsx
|
|
2462
|
+
function plain(text) {
|
|
2463
|
+
return text.replace(/```[\s\S]*?(```|$)/g, " ").replace(/[*_~`>#]+/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\s+/g, " ").trim();
|
|
2464
|
+
}
|
|
2465
|
+
function roomPreview(room, last) {
|
|
2466
|
+
if (!last) {
|
|
2467
|
+
return statusLine(room);
|
|
2468
|
+
}
|
|
2469
|
+
const self = room.members.find((each) => each.self)?.member;
|
|
2470
|
+
const person = room.members.find((each) => each.member === last.from)?.name ?? last.name;
|
|
2471
|
+
const name = last.agent?.name ?? (!last.double ? person : last.from === self ? dt("myDouble") : dt("doubleOf", { name: person }));
|
|
2472
|
+
return last.from === self && !last.agent && !last.double ? plain(last.text) : t("said", { name, text: plain(last.text) });
|
|
2473
|
+
}
|
|
2474
|
+
function lastAt(room) {
|
|
2475
|
+
const lines = room.status === "member" ? book.chat(room.id)?.lines : undefined;
|
|
2476
|
+
return lines?.[lines.length - 1]?.at ?? room.joinedAt ?? room.createdAt;
|
|
2477
|
+
}
|
|
2478
|
+
function useSorted(list) {
|
|
2479
|
+
const ids = list.map((room) => room.id).join(",");
|
|
2480
|
+
const subscribe = React.useCallback((listener) => {
|
|
2481
|
+
const stops = list.filter((room) => room.status === "member").map((room) => book.chat(room.id)?.subscribe(listener));
|
|
2482
|
+
return () => {
|
|
2483
|
+
for (const stop of stops) {
|
|
2484
|
+
stop?.();
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
}, [ids]);
|
|
2488
|
+
const order = React.useSyncExternalStore(subscribe, () => list.map((room) => `${room.id}:${lastAt(room)}`).join(","));
|
|
2489
|
+
return React.useMemo(() => [...list].sort((a, b) => Number(b.status === "member") - Number(a.status === "member") || lastAt(b) - lastAt(a)), [order, list]);
|
|
2490
|
+
}
|
|
2491
|
+
function RoomRow({ room, active, seen, openMenu }) {
|
|
2492
|
+
const lines = useLines(room);
|
|
2493
|
+
const page = usePageOf(room);
|
|
2494
|
+
const member = room.status === "member";
|
|
2495
|
+
const last = lines[lines.length - 1];
|
|
2496
|
+
const unread = member && unseen(room, lines, seen);
|
|
2497
|
+
const preview = roomPreview(room, last);
|
|
2498
|
+
const menu = [
|
|
2499
|
+
member ? [
|
|
2500
|
+
...room.owner ? [{ key: "invite", label: t("invite"), icon: icon("UserPlus"), run: () => openInvite(room) }] : [],
|
|
2501
|
+
...page && room.view ? [{ key: "page", label: t("openPage", { name: page.title }), icon: page.icon, run: () => void pi.ui.showView(room.view) }] : []
|
|
2502
|
+
] : [],
|
|
2503
|
+
[
|
|
2504
|
+
{
|
|
2505
|
+
key: "leave",
|
|
2506
|
+
label: !member ? t("forget") : room.owner ? t("close") : t("leave"),
|
|
2507
|
+
icon: icon("Trash2"),
|
|
2508
|
+
danger: true,
|
|
2509
|
+
run: () => void leaveRoom(room)
|
|
2510
|
+
}
|
|
2511
|
+
]
|
|
2512
|
+
];
|
|
2513
|
+
return /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
2514
|
+
type: "button",
|
|
2515
|
+
className: `trm-room${active ? " trm-active" : ""}${member ? "" : " trm-room-out"}`,
|
|
2516
|
+
"aria-current": active || undefined,
|
|
2517
|
+
onClick: (event) => member ? openRoom(room.id) : openMenu(event, menu),
|
|
2518
|
+
onContextMenu: (event) => openMenu(event, menu)
|
|
2519
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
2520
|
+
room,
|
|
2521
|
+
unread
|
|
2522
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2523
|
+
className: "trm-room-text"
|
|
2524
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2525
|
+
className: "trm-room-line"
|
|
2526
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2527
|
+
className: "trm-room-name trm-ellipsis"
|
|
2528
|
+
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
2529
|
+
className: "trm-room-time"
|
|
2530
|
+
}, when(lastAt(room)))), /* @__PURE__ */ React.createElement("span", {
|
|
2531
|
+
className: `trm-room-preview trm-ellipsis${member ? "" : " trm-quiet"}`
|
|
2532
|
+
}, preview))));
|
|
2533
|
+
}
|
|
2534
|
+
function FriendRow({ friend, openMenu }) {
|
|
2535
|
+
const Remove = icon("Trash2");
|
|
2536
|
+
const remove = () => void confirmThen(t("removeFriendTitle", { name: friend.name }), t("removeFriendHint"), t("removeFriend"), async () => rooms()?.removeFriend(friend.id));
|
|
2537
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2538
|
+
className: "trm-friend",
|
|
2539
|
+
onContextMenu: (event) => openMenu(event, [[{ key: "remove", label: t("removeFriend"), icon: Remove, danger: true, run: remove }]])
|
|
2540
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2541
|
+
id: friend.id,
|
|
2542
|
+
name: friend.name,
|
|
2543
|
+
size: 38
|
|
2544
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2545
|
+
className: "trm-room-text"
|
|
2546
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2547
|
+
className: "trm-room-name trm-ellipsis"
|
|
2548
|
+
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
2549
|
+
className: "trm-room-preview trm-ellipsis"
|
|
2550
|
+
}, t("friendLine", { rooms: friend.rooms.slice(-3).reverse().join("、") }))), /* @__PURE__ */ React.createElement("button", {
|
|
2551
|
+
type: "button",
|
|
2552
|
+
className: "trm-icon trm-danger trm-hover-only",
|
|
2553
|
+
title: t("removeFriend"),
|
|
2554
|
+
"aria-label": t("removeFriend"),
|
|
2555
|
+
onClick: remove
|
|
2556
|
+
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
2557
|
+
size: 15
|
|
2558
|
+
})));
|
|
2559
|
+
}
|
|
2560
|
+
function RoomList({ openMenu }) {
|
|
2561
|
+
const { identity, rooms: list, requests, friends, opened, seen } = useBook();
|
|
2562
|
+
const { asks } = useDoubles();
|
|
2563
|
+
const sorted = useSorted(list ?? []);
|
|
2564
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2565
|
+
className: "trm-list"
|
|
2566
|
+
}, asks.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
2567
|
+
className: "trm-section"
|
|
2568
|
+
}, /* @__PURE__ */ React.createElement("h3", null, dt("asksTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
2569
|
+
className: "trm-card"
|
|
2570
|
+
}, asks.map((ask) => /* @__PURE__ */ React.createElement(AskRow, {
|
|
2571
|
+
key: ask.id,
|
|
2572
|
+
ask
|
|
2573
|
+
})))), requests.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
2574
|
+
className: "trm-section"
|
|
2575
|
+
}, /* @__PURE__ */ React.createElement("h3", null, t("requests")), /* @__PURE__ */ React.createElement("ul", {
|
|
2576
|
+
className: "trm-card"
|
|
2577
|
+
}, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
|
|
2578
|
+
key: `${request.room}:${request.ask}`,
|
|
2579
|
+
request
|
|
2580
|
+
})))), /* @__PURE__ */ React.createElement("section", {
|
|
2581
|
+
className: "trm-section"
|
|
2582
|
+
}, /* @__PURE__ */ React.createElement("h3", null, t("roomsTitle")), list === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
2583
|
+
rows: 3
|
|
2584
|
+
}) : null : sorted.length === 0 ? /* @__PURE__ */ React.createElement("p", {
|
|
2585
|
+
className: "trm-empty"
|
|
2586
|
+
}, t("emptyHint")) : /* @__PURE__ */ React.createElement("ul", {
|
|
2587
|
+
className: "trm-rooms"
|
|
2588
|
+
}, sorted.map((room) => /* @__PURE__ */ React.createElement(RoomRow, {
|
|
2589
|
+
key: room.id,
|
|
2590
|
+
room,
|
|
2591
|
+
active: room.id === opened,
|
|
2592
|
+
seen,
|
|
2593
|
+
openMenu
|
|
2594
|
+
})))), friends && friends.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
2595
|
+
className: "trm-section"
|
|
2596
|
+
}, /* @__PURE__ */ React.createElement("h3", null, t("friends")), /* @__PURE__ */ React.createElement("ul", {
|
|
2597
|
+
className: "trm-rooms"
|
|
2598
|
+
}, friends.map((friend) => /* @__PURE__ */ React.createElement(FriendRow, {
|
|
2599
|
+
key: friend.id,
|
|
2600
|
+
friend,
|
|
2601
|
+
openMenu
|
|
2602
|
+
})))), identity && /* @__PURE__ */ React.createElement("p", {
|
|
2603
|
+
className: "trm-me"
|
|
2604
|
+
}, t("meLine", { name: identity.name }), /* @__PURE__ */ React.createElement("button", {
|
|
2605
|
+
type: "button",
|
|
2606
|
+
className: "trm-link",
|
|
2607
|
+
onClick: () => void rename()
|
|
2608
|
+
}, t("rename"))));
|
|
2609
|
+
}
|
|
2610
|
+
function addMenu() {
|
|
2611
|
+
return [
|
|
2612
|
+
[
|
|
2613
|
+
{ key: "new", label: t("newRoom"), icon: icon("MessagesSquare"), run: () => void createRoom() },
|
|
2614
|
+
{ key: "link", label: t("joinByLink"), icon: icon("Link"), run: () => void pasteLink() },
|
|
2615
|
+
...pi.ui.scanCode ? [{ key: "scan", label: t("scan"), icon: icon("ScanLine"), run: () => void scanLink() }] : []
|
|
2616
|
+
],
|
|
2617
|
+
[
|
|
2618
|
+
{ key: "name", label: t("me"), icon: icon("Pencil"), run: () => void rename() },
|
|
2619
|
+
{ key: "doubles", label: dt("log"), icon: icon("Bot"), run: () => void pi.ui.showView(DOUBLES_VIEW) }
|
|
2620
|
+
]
|
|
2621
|
+
];
|
|
2622
|
+
}
|
|
2623
|
+
function RoomsHead() {
|
|
2624
|
+
const compact = useCompact();
|
|
2625
|
+
const opened = useOpened();
|
|
2626
|
+
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
2627
|
+
const Plus = icon("Plus");
|
|
2628
|
+
const add = rooms() && /* @__PURE__ */ React.createElement("button", {
|
|
2629
|
+
type: "button",
|
|
2630
|
+
className: "trm-icon",
|
|
2631
|
+
title: t("add"),
|
|
2632
|
+
"aria-label": t("add"),
|
|
2633
|
+
onClick: (event) => openMenu(event, addMenu())
|
|
2634
|
+
}, /* @__PURE__ */ React.createElement(Plus, {
|
|
2635
|
+
size: 18
|
|
2636
|
+
}));
|
|
2637
|
+
if (compact && opened && (pi.ui.Stack || book.get().direct)) {
|
|
2638
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2639
|
+
className: "trm-head"
|
|
2640
|
+
}, /* @__PURE__ */ React.createElement(RoomHead, {
|
|
2641
|
+
room: opened
|
|
2642
|
+
}));
|
|
2643
|
+
}
|
|
2644
|
+
if (compact) {
|
|
2645
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2646
|
+
className: "trm-head trm-head-center"
|
|
2647
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2648
|
+
className: "trm-head-title"
|
|
2649
|
+
}, t("roomsTitle")), /* @__PURE__ */ React.createElement("span", {
|
|
2650
|
+
className: "trm-head-end"
|
|
2651
|
+
}, add), menu);
|
|
2652
|
+
}
|
|
2653
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2654
|
+
className: "trm-head trm-head-split"
|
|
2655
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2656
|
+
className: "trm-head-list"
|
|
2657
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2658
|
+
className: "trm-head-title"
|
|
2659
|
+
}, t("roomsTitle")), add), /* @__PURE__ */ React.createElement("div", {
|
|
2660
|
+
className: "trm-head-room"
|
|
2661
|
+
}, opened && /* @__PURE__ */ React.createElement(RoomHead, {
|
|
2662
|
+
room: opened
|
|
2663
|
+
})), menu);
|
|
2664
|
+
}
|
|
2665
|
+
function RoomsPage() {
|
|
2666
|
+
const compact = useCompact();
|
|
2667
|
+
const opened = useOpened();
|
|
2668
|
+
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
2669
|
+
const { direct } = useBook();
|
|
2670
|
+
const shownPage = pi.ui.useView?.(ROOMS_VIEW)?.shown;
|
|
2671
|
+
React.useEffect(() => {
|
|
2672
|
+
if (shownPage === false && direct) {
|
|
2673
|
+
book.set({ opened: undefined, direct: false });
|
|
2674
|
+
}
|
|
2675
|
+
}, [shownPage, direct]);
|
|
2676
|
+
const [kept, setKept] = React.useState();
|
|
2677
|
+
React.useEffect(() => {
|
|
2678
|
+
if (opened) {
|
|
2679
|
+
setKept(opened);
|
|
2680
|
+
}
|
|
2681
|
+
}, [opened]);
|
|
2682
|
+
if (!rooms()) {
|
|
2683
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2684
|
+
className: "trm-page"
|
|
2685
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2686
|
+
title: t("emptyTitle"),
|
|
2687
|
+
hint: t("oldApp")
|
|
2688
|
+
}));
|
|
2689
|
+
}
|
|
2690
|
+
const list = /* @__PURE__ */ React.createElement(RoomList, {
|
|
2691
|
+
openMenu
|
|
2692
|
+
});
|
|
2693
|
+
const close = () => book.set({ opened: undefined });
|
|
2694
|
+
if (!compact) {
|
|
2695
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2696
|
+
className: "trm-split"
|
|
2697
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2698
|
+
className: "trm-split-list"
|
|
2699
|
+
}, list), /* @__PURE__ */ React.createElement("div", {
|
|
2700
|
+
className: "trm-split-room"
|
|
2701
|
+
}, opened ? /* @__PURE__ */ React.createElement(RoomView, {
|
|
2702
|
+
key: opened.id,
|
|
2703
|
+
room: opened,
|
|
2704
|
+
head: false
|
|
2705
|
+
}) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2706
|
+
title: t("pickRoom")
|
|
2707
|
+
})), menu);
|
|
2708
|
+
}
|
|
2709
|
+
if (opened && direct) {
|
|
2710
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RoomView, {
|
|
2711
|
+
key: opened.id,
|
|
2712
|
+
room: opened,
|
|
2713
|
+
head: false
|
|
2714
|
+
}), menu);
|
|
2715
|
+
}
|
|
2716
|
+
const Stack = pi.ui.Stack;
|
|
2717
|
+
const shown = opened ?? kept;
|
|
2718
|
+
if (!Stack) {
|
|
2719
|
+
return opened ? /* @__PURE__ */ React.createElement(RoomView, {
|
|
2720
|
+
key: opened.id,
|
|
2721
|
+
room: opened,
|
|
2722
|
+
head: true,
|
|
2723
|
+
onBack: close
|
|
2724
|
+
}) : /* @__PURE__ */ React.createElement("div", {
|
|
2725
|
+
className: "trm-page"
|
|
2726
|
+
}, list, menu);
|
|
2727
|
+
}
|
|
2728
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Stack, {
|
|
2729
|
+
base: /* @__PURE__ */ React.createElement("div", {
|
|
2730
|
+
className: "trm-page"
|
|
2731
|
+
}, list),
|
|
2732
|
+
top: shown ? /* @__PURE__ */ React.createElement(RoomView, {
|
|
2733
|
+
key: shown.id,
|
|
2734
|
+
room: shown,
|
|
2735
|
+
head: false
|
|
2736
|
+
}) : null,
|
|
2737
|
+
open: !!opened,
|
|
2738
|
+
onClose: close
|
|
2739
|
+
}), menu);
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
// web-src/rooms-home.tsx
|
|
2743
|
+
var HOME_KEY = "home.rooms";
|
|
2744
|
+
function homeFace(id) {
|
|
2745
|
+
return function HomeFace({ size }) {
|
|
2746
|
+
const room = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get().rooms?.find((each) => each.id === id));
|
|
2747
|
+
return room ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
2748
|
+
room,
|
|
2749
|
+
size
|
|
2750
|
+
}) : null;
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
class RoomsHome {
|
|
2755
|
+
current = [];
|
|
2756
|
+
signature = "";
|
|
2757
|
+
shown = true;
|
|
2758
|
+
listeners = new Set;
|
|
2759
|
+
chats = new Map;
|
|
2760
|
+
faces = new Map;
|
|
2761
|
+
items = () => this.current;
|
|
2762
|
+
subscribe = (listener) => {
|
|
2763
|
+
this.listeners.add(listener);
|
|
2764
|
+
return () => this.listeners.delete(listener);
|
|
2765
|
+
};
|
|
2766
|
+
start() {
|
|
2767
|
+
const stopBook = book.subscribe(() => this.refresh());
|
|
2768
|
+
const stopStorage = pi.storage.onChange((keys) => keys.includes(HOME_KEY) && this.readShown());
|
|
2769
|
+
this.readShown();
|
|
2770
|
+
this.refresh();
|
|
2771
|
+
return () => {
|
|
2772
|
+
stopBook();
|
|
2773
|
+
stopStorage();
|
|
2774
|
+
for (const stop of this.chats.values()) {
|
|
2775
|
+
stop();
|
|
2776
|
+
}
|
|
2777
|
+
this.chats.clear();
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
readShown() {
|
|
2781
|
+
pi.storage.get(HOME_KEY).then((value) => {
|
|
2782
|
+
this.shown = value !== false;
|
|
2783
|
+
this.refresh();
|
|
2784
|
+
}, () => {
|
|
2785
|
+
return;
|
|
2786
|
+
});
|
|
2787
|
+
}
|
|
2788
|
+
refresh() {
|
|
2789
|
+
const { rooms: rooms2 = [], seen } = book.get();
|
|
2790
|
+
const joined = this.shown ? rooms2.filter((room) => room.status === "member") : [];
|
|
2791
|
+
this.follow(joined);
|
|
2792
|
+
const rows = joined.map((room) => ({ room, lines: book.chat(room.id)?.lines ?? [] })).sort((a, b) => lastAt(b.room) - lastAt(a.room));
|
|
2793
|
+
const signature = rows.map(({ room, lines }) => [room.id, room.title, lines.at(-1)?.id ?? "", unseen(room, lines, seen) ? 1 : 0, room.connected ? 1 : 0, room.members.length].join(":")).join("|");
|
|
2794
|
+
if (signature === this.signature) {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
this.signature = signature;
|
|
2798
|
+
this.current = rows.map(({ room, lines }) => this.item(room, lines, unseen(room, lines, seen)));
|
|
2799
|
+
for (const listener of this.listeners) {
|
|
2800
|
+
listener();
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
item(room, lines, fresh) {
|
|
2804
|
+
let face = this.faces.get(room.id);
|
|
2805
|
+
if (!face) {
|
|
2806
|
+
face = homeFace(room.id);
|
|
2807
|
+
this.faces.set(room.id, face);
|
|
2808
|
+
}
|
|
2809
|
+
return {
|
|
2810
|
+
id: room.id,
|
|
2811
|
+
title: room.title,
|
|
2812
|
+
detail: roomPreview(room, lines.at(-1)),
|
|
2813
|
+
icon: icon("Users"),
|
|
2814
|
+
face,
|
|
2815
|
+
section: t("roomsTitle"),
|
|
2816
|
+
at: lastAt(room),
|
|
2817
|
+
unseen: fresh,
|
|
2818
|
+
open: () => openRoom(room.id, true)
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
follow(joined) {
|
|
2822
|
+
const ids = new Set(joined.map((room) => room.id));
|
|
2823
|
+
for (const [id, stop] of this.chats) {
|
|
2824
|
+
if (!ids.has(id)) {
|
|
2825
|
+
stop();
|
|
2826
|
+
this.chats.delete(id);
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
for (const room of joined) {
|
|
2830
|
+
if (!this.chats.has(room.id)) {
|
|
2831
|
+
const stop = book.chat(room.id)?.subscribe(() => this.refresh());
|
|
2832
|
+
this.chats.set(room.id, stop ?? (() => {
|
|
2833
|
+
return;
|
|
2834
|
+
}));
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
function HomeSwitch() {
|
|
2840
|
+
const [on, setOn] = React.useState(true);
|
|
2841
|
+
React.useEffect(() => {
|
|
2842
|
+
let live = true;
|
|
2843
|
+
const read = () => void pi.storage.get(HOME_KEY).then((value) => live && setOn(value !== false), () => {
|
|
2844
|
+
return;
|
|
2845
|
+
});
|
|
2846
|
+
read();
|
|
2847
|
+
const stop = pi.storage.onChange((keys) => keys.includes(HOME_KEY) && read());
|
|
2848
|
+
return () => {
|
|
2849
|
+
live = false;
|
|
2850
|
+
stop();
|
|
2851
|
+
};
|
|
2852
|
+
}, []);
|
|
2853
|
+
const change = (next) => {
|
|
2854
|
+
setOn(next);
|
|
2855
|
+
return pi.storage.set(HOME_KEY, next).catch((error) => {
|
|
2856
|
+
setOn(!next);
|
|
2857
|
+
pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
2858
|
+
});
|
|
2859
|
+
};
|
|
2860
|
+
const Switch = pi.ui.Switch;
|
|
2861
|
+
return Switch ? /* @__PURE__ */ React.createElement(Switch, {
|
|
2862
|
+
checked: on,
|
|
2863
|
+
label: t("showOnHome"),
|
|
2864
|
+
onChange: change
|
|
2865
|
+
}) : /* @__PURE__ */ React.createElement("input", {
|
|
2866
|
+
type: "checkbox",
|
|
2867
|
+
role: "switch",
|
|
2868
|
+
className: "ta-switch",
|
|
2869
|
+
checked: on,
|
|
2870
|
+
"aria-checked": on,
|
|
2871
|
+
"aria-label": t("showOnHome"),
|
|
2872
|
+
onChange: (event) => void change(event.target.checked)
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
function roomsSettings() {
|
|
2876
|
+
return {
|
|
2877
|
+
title: () => t("roomsTitle"),
|
|
2878
|
+
icon: icon("Users"),
|
|
2879
|
+
rows: [{ key: "home", label: () => t("showOnHome"), description: () => t("showOnHomeHint"), render: HomeSwitch }]
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
// web-src/style.ts
|
|
2884
|
+
var STYLE = `
|
|
2885
|
+
.trm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2886
|
+
.trm-quiet { color: var(--ta-muted); }
|
|
2887
|
+
/* The head of the page (RoomsHead): over the list and the room on a computer, as the sidebar and a channel's head */
|
|
2888
|
+
.trm-head { position: relative; display: flex; align-items: center; flex: 1; min-width: 0; height: 100%; }
|
|
2889
|
+
.trm-head-center { justify-content: center; padding: 0 44px; }
|
|
2890
|
+
.trm-head-title { font-weight: 600; font-size: calc(14.5px * var(--ta-font-scale)); }
|
|
2891
|
+
.trm-head-end { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; }
|
|
2892
|
+
.ta-main-head:has(.trm-head-split) { padding-left: 0; }
|
|
2893
|
+
.ta-main-head-view:has(.trm-head-split) { align-self: stretch; }
|
|
2894
|
+
.trm-head-split { align-items: stretch; }
|
|
2895
|
+
.trm-head-list { flex: none; display: flex; align-items: center; justify-content: space-between; width: 320px; box-sizing: border-box; padding: 0 8px 0 22px; background: var(--ta-side); border-right: 1px solid var(--ta-border-muted); }
|
|
2896
|
+
.trm-head-room { flex: 1; min-width: 0; display: flex; align-items: center; padding-left: 20px; }
|
|
2897
|
+
/* The list, as the sidebar of the double: faces, a name and when, a line under it */
|
|
2898
|
+
.trm-page { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: none; }
|
|
2899
|
+
.trm-page > .trm-list { max-width: 720px; margin: 0 auto; }
|
|
2900
|
+
.trm-list { display: flex; flex-direction: column; gap: 10px; padding: 4px 10px calc(24px + env(safe-area-inset-bottom)); box-sizing: border-box; }
|
|
2901
|
+
.trm-section h3 { display: flex; align-items: center; height: 30px; margin: 0; padding: 0 10px; font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; letter-spacing: 0.02em; color: var(--ta-muted); }
|
|
2902
|
+
.trm-empty { margin: 4px 10px 8px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.6; }
|
|
2903
|
+
.trm-card { margin: 0; padding: 2px 6px; list-style: none; border-radius: 14px; background: var(--ta-raised); }
|
|
2904
|
+
.trm-card .trm-row { padding: 10px 4px; }
|
|
2905
|
+
.trm-rooms { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
|
|
2906
|
+
.trm-room { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; margin: 1px 0; padding: 9px 10px; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 120ms; }
|
|
2907
|
+
@media (hover: hover) { .trm-room:hover, .trm-friend:hover, li.trm-member:hover, button.trm-member:hover { background: var(--ta-hover); } }
|
|
2908
|
+
.trm-room:active { background: var(--ta-hover); }
|
|
2909
|
+
.trm-room.trm-active { background: var(--ta-selected, var(--ta-hover-strong)); }
|
|
2910
|
+
.trm-room:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
|
|
2911
|
+
.trm-room-out { opacity: .55; }
|
|
2912
|
+
.trm-room-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
|
|
2913
|
+
.trm-room-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
2914
|
+
.trm-room-name { flex: 0 1 auto; font-size: calc(14px * var(--ta-font-scale)); font-weight: 500; line-height: calc(19px * var(--ta-font-scale)); }
|
|
2915
|
+
.trm-room-time { flex: none; margin-left: auto; padding-left: 4px; color: var(--ta-muted); font-size: calc(11px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
2916
|
+
.trm-room-preview { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(17px * var(--ta-font-scale)); }
|
|
2917
|
+
.trm-tag { flex: none; align-self: center; padding: 0 6px; border-radius: 6px; background: var(--ta-chip, var(--ta-hover)); color: var(--ta-secondary); font-size: calc(10.5px * var(--ta-font-scale)); font-weight: 400; line-height: calc(17px * var(--ta-font-scale)); }
|
|
2918
|
+
.trm-tag-friend { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
|
|
2919
|
+
.trm-friend { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 9px 10px; box-sizing: border-box; border-radius: 12px; }
|
|
2920
|
+
.trm-hover-only { opacity: 0; transition: opacity 120ms; }
|
|
2921
|
+
.trm-friend:hover .trm-hover-only, .trm-hover-only:focus-visible { opacity: 1; }
|
|
2922
|
+
@media (hover: none) { .trm-hover-only { display: none; } }
|
|
2923
|
+
.trm-me { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2924
|
+
.trm-link { padding: 2px 4px; border: 0; border-radius: 6px; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
|
|
2925
|
+
.trm-link:hover { background: var(--ta-hover); }
|
|
2926
|
+
.trm-link.trm-danger { color: var(--ta-red); }
|
|
2927
|
+
/* The faces: those of channels (ui.Face), or a letter in a circle in an app of before */
|
|
2928
|
+
.ta-face { --ta-face-ring: var(--ta-side); }
|
|
2929
|
+
.trm-chat .ta-face, .trm-panel .ta-face, .trm-head .ta-face { --ta-face-ring: var(--ta-main); }
|
|
2930
|
+
.trm-face { position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 600; line-height: 1; user-select: none; }
|
|
2931
|
+
.trm-face i { position: absolute; right: -1px; bottom: -1px; width: 28%; height: 28%; min-width: 7px; min-height: 7px; border-radius: 50%; border: 2px solid var(--ta-main); }
|
|
2932
|
+
.trm-on { background: var(--ta-green); }
|
|
2933
|
+
.trm-off { background: var(--ta-border-field); }
|
|
2934
|
+
.trm-room-face { position: relative; flex: none; display: inline-flex; }
|
|
2935
|
+
.trm-room-face-mark { position: absolute; right: -3px; bottom: -3px; z-index: 2; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--ta-raised); color: var(--ta-text); box-shadow: 0 0 0 2px var(--ta-side); }
|
|
2936
|
+
.trm-unread { position: absolute; top: -2px; right: -2px; z-index: 2; width: 10px; height: 10px; border-radius: 50%; background: var(--ta-yellow); box-shadow: 0 0 0 2px var(--ta-side); }
|
|
2937
|
+
/* Beside each other, on a computer or a tablet: the list on the colour of the sidebar */
|
|
2938
|
+
.trm-split { display: grid; grid-template-columns: 320px minmax(0, 1fr); flex: 1; min-height: 0; height: 100%; }
|
|
2939
|
+
.trm-split-list { min-height: 0; overflow-y: auto; overscroll-behavior: none; background: var(--ta-side); border-right: 1px solid var(--ta-border-muted); }
|
|
2940
|
+
.trm-split-room { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
|
|
2941
|
+
/* A room (room-view.tsx): a group chat, as a channel */
|
|
2942
|
+
.trm-room-page { display: flex; flex-direction: column; flex: 1; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); }
|
|
2943
|
+
.trm-room-bar { flex: none; display: flex; align-items: center; gap: 6px; min-height: 52px; padding: 6px 12px; box-sizing: border-box; }
|
|
2944
|
+
.trm-room-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
|
|
2945
|
+
.trm-room-head-title { display: flex; align-items: baseline; gap: 8px; flex: 1; min-width: 0; white-space: nowrap; }
|
|
2946
|
+
.trm-room-head-title strong { font-size: calc(14.5px * var(--ta-font-scale)); font-weight: 600; }
|
|
2947
|
+
.trm-room-head-count { flex: none; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2948
|
+
.trm-room-head-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ta-green); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2949
|
+
.trm-room-head-sub.trm-quiet { color: var(--ta-muted); }
|
|
2950
|
+
.trm-faces { display: flex; align-items: center; flex: none; height: 32px; padding: 0 6px 0 10px; border: 0; border-radius: 999px; background: none; color: var(--ta-secondary); font: inherit; cursor: pointer; transition: background 120ms; }
|
|
2951
|
+
.trm-faces.trm-on-icon { background: var(--ta-hover); }
|
|
2952
|
+
@media (hover: hover) { .trm-faces:hover { background: var(--ta-hover); } .trm-faces:hover .trm-faces-one { background: var(--ta-hover); } }
|
|
2953
|
+
.trm-faces-one { display: inline-flex; margin-left: -4px; padding: 1px; border-radius: 50%; background: var(--ta-main); }
|
|
2954
|
+
.trm-faces.trm-on-icon .trm-faces-one { background: var(--ta-hover); }
|
|
2955
|
+
.trm-faces-more { margin-left: 4px; font-size: calc(12px * var(--ta-font-scale)); }
|
|
2956
|
+
.trm-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ta-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; }
|
|
2957
|
+
.trm-icon:hover:not(:disabled) { background: var(--ta-hover-strong); color: var(--ta-text); }
|
|
2958
|
+
.trm-icon.trm-danger:hover:not(:disabled) { color: var(--ta-red); }
|
|
2959
|
+
.trm-page-line { flex: none; display: flex; align-items: center; gap: 10px; width: calc(100% - 48px); max-width: var(--ta-col); margin: 8px auto 0; padding: 8px 10px 8px 8px; box-sizing: border-box; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-side); color: var(--ta-text); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); text-align: left; cursor: pointer; transition: background 120ms; }
|
|
2960
|
+
.trm-page-line:hover { background: var(--ta-hover); }
|
|
2961
|
+
.trm-page-line-icon { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
|
|
2962
|
+
.trm-page-line-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-secondary); }
|
|
2963
|
+
.trm-page-line-open { display: inline-flex; align-items: center; gap: 2px; flex: none; color: var(--ta-link); font-weight: 500; }
|
|
2964
|
+
.trm-chat { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none; overscroll-behavior: none; }
|
|
2965
|
+
.trm-chat-col { position: relative; display: flex; flex-direction: column; gap: 4px; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 20px 24px 12px; box-sizing: border-box; }
|
|
2966
|
+
.trm-chat-time { align-self: center; margin: 14px 0 6px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
2967
|
+
.trm-chat-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 12vh auto 0; max-width: 360px; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); text-align: center; }
|
|
2968
|
+
.trm-chat-empty strong { margin-top: 6px; color: var(--ta-text); font-size: calc(16px * var(--ta-font-scale)); }
|
|
2969
|
+
.trm-chat-hint { margin-top: 4px; font-size: calc(12px * var(--ta-font-scale)); line-height: 1.6; }
|
|
2970
|
+
.trm-mine { margin: 6px 0 2px; }
|
|
2971
|
+
.trm-msg { display: flex; align-items: flex-start; gap: 10px; }
|
|
2972
|
+
.trm-msg.trm-first { margin-top: 10px; }
|
|
2973
|
+
.trm-msg-face { display: flex; justify-content: center; width: 28px; flex: none; }
|
|
2974
|
+
.trm-msg-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(84%, var(--ta-col)); }
|
|
2975
|
+
.trm-msg-name { margin: 0 2px 4px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(16px * var(--ta-font-scale)); }
|
|
2976
|
+
.trm-msg-bubble { min-width: 0; max-width: 100%; padding: 9px 14px; border: 1px solid var(--ta-border-muted); border-radius: 5px 16px 16px 16px; background: var(--ta-side); color: var(--ta-body); line-height: 1.6; overflow-wrap: anywhere; }
|
|
2977
|
+
.trm-msg-bubble pre { max-width: 100%; overflow-x: auto; }
|
|
2978
|
+
.trm-chat-bottom { flex: none; width: 100%; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 8px 24px calc(16px + env(safe-area-inset-bottom)); box-sizing: border-box; }
|
|
2979
|
+
/* Above the keyboard the home indicator is not there: no room for it, as under the box of a conversation. */
|
|
2980
|
+
:root[data-keyboard] .trm-chat-bottom { padding-bottom: 8px; }
|
|
2981
|
+
:root[data-keyboard-moving] .trm-chat-bottom { transition: padding-bottom 450ms cubic-bezier(0.15, 0.75, 0.2, 1); }
|
|
2982
|
+
/* The members of the room shown (members-view.tsx), in the workbench */
|
|
2983
|
+
.trm-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); font-size: calc(13px * var(--ta-font-scale)); }
|
|
2984
|
+
.trm-panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }
|
|
2985
|
+
.trm-panel-top { display: flex; align-items: center; gap: 12px; padding: 14px 10px 10px; }
|
|
2986
|
+
.trm-panel-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
2987
|
+
.trm-panel-title strong { font-size: calc(15px * var(--ta-font-scale)); font-weight: 600; }
|
|
2988
|
+
.trm-panel-title span { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2989
|
+
.trm-panel-label { padding: 10px 10px 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2990
|
+
.trm-panel-members { margin: 0; padding: 0; list-style: none; }
|
|
2991
|
+
.trm-member { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; box-sizing: border-box; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; }
|
|
2992
|
+
button.trm-member { cursor: pointer; }
|
|
2993
|
+
.trm-member-plus { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--ta-hover); color: var(--ta-secondary); }
|
|
2994
|
+
.trm-member-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
|
2995
|
+
.trm-member-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: calc(13.5px * var(--ta-font-scale)); font-weight: 500; }
|
|
2996
|
+
.trm-member-detail { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
2997
|
+
.trm-member-detail.trm-live { color: var(--ta-green); }
|
|
2998
|
+
.trm-member-action { opacity: 0; transition: opacity 120ms; }
|
|
2999
|
+
.trm-member:hover .trm-member-action, .trm-member-action:focus-visible { opacity: 1; }
|
|
3000
|
+
@media (hover: none) { .trm-member-action { opacity: 1; } }
|
|
3001
|
+
.trm-panel-sep { height: 1px; margin: 8px 10px; background: var(--ta-border-muted); }
|
|
3002
|
+
.trm-setting { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; }
|
|
3003
|
+
.trm-setting:hover { background: var(--ta-hover); }
|
|
3004
|
+
.trm-setting > svg { flex: none; color: var(--ta-muted); }
|
|
3005
|
+
.trm-setting-label { flex: none; }
|
|
3006
|
+
.trm-setting-value { flex: 1; text-align: right; color: var(--ta-muted); }
|
|
3007
|
+
.trm-panel-foot { display: flex; justify-content: center; flex: none; padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--ta-border-muted); }
|
|
3008
|
+
.trm-panel-foot .trm-link { width: 100%; min-height: 36px; border-radius: 10px; font-weight: 500; }
|
|
3009
|
+
/* Dialogs */
|
|
3010
|
+
.trm-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; }
|
|
3011
|
+
.trm-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
3012
|
+
.trm-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3013
|
+
.trm-row-line { display: flex; align-items: center; gap: 4px; min-width: 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3014
|
+
.trm-rows { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
|
|
3015
|
+
.trm-answers { flex: none; display: flex; gap: 6px; }
|
|
3016
|
+
.trm-dialog { display: flex; flex-direction: column; gap: 12px; width: min(420px, calc(100vw - 48px)); }
|
|
3017
|
+
.trm-lead { margin: 0; line-height: 1.5; }
|
|
3018
|
+
.trm-note, .trm-hint { margin: 0; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.5; }
|
|
3019
|
+
.trm-hint { text-align: center; color: var(--ta-secondary); }
|
|
3020
|
+
.trm-error { margin: 0; color: var(--ta-red); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
3021
|
+
.trm-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
|
|
3022
|
+
.trm-center { justify-content: center; }
|
|
3023
|
+
.trm-join { display: flex; align-items: center; gap: 12px; }
|
|
3024
|
+
.trm-invite { align-items: stretch; }
|
|
3025
|
+
.trm-qr { align-self: center; width: 188px; padding: 10px; border-radius: 14px; background: #fff; border: 1px solid var(--ta-border-muted); }
|
|
3026
|
+
.trm-qr svg { display: block; width: 100%; height: auto; }
|
|
3027
|
+
.trm-link-box { padding: 8px 10px; border-radius: 8px; background: var(--ta-code); font-family: var(--ta-mono); font-size: calc(11.5px * var(--ta-font-scale)); color: var(--ta-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3028
|
+
.trm-dialog .trm-row { padding: 8px 0; }
|
|
3029
|
+
/* The doubles (docs/design/ta-link.md 4): what a double says, its permissions, its log */
|
|
3030
|
+
.trm-tag-double { margin-left: 6px; background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
|
|
3031
|
+
.trm-double .trm-msg-bubble { border-style: dashed; background: var(--ta-main); }
|
|
3032
|
+
.trm-tag-agent { margin-left: 6px; background: var(--ta-tint-5); color: var(--ta-tint-ink-5); }
|
|
3033
|
+
.trm-member-name .trm-tag-agent { margin-left: 0; }
|
|
3034
|
+
.trm-try-alone { margin-top: 12px; }
|
|
3035
|
+
.trm-chat-joining { display: inline-flex; align-self: center; align-items: center; gap: 8px; margin: 10px 0 4px; padding: 6px 12px; border-radius: 999px; background: var(--ta-hover); color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
3036
|
+
.trm-agent-pick .trm-member:disabled { cursor: default; opacity: 1; }
|
|
3037
|
+
.trm-agent-pick .trm-member:disabled .trm-member-detail { color: var(--ta-green); }
|
|
3038
|
+
.trm-member-may { color: var(--ta-secondary); }
|
|
3039
|
+
.trm-member-action.trm-on-icon { opacity: 1; color: var(--ta-green); }
|
|
3040
|
+
.trm-double-switch, .trm-grant-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; }
|
|
3041
|
+
.trm-grant-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
|
3042
|
+
.trm-grant-who { display: flex; align-items: center; gap: 12px; }
|
|
3043
|
+
.trm-grant-reason { margin: 0; padding: 8px 12px; border-left: 3px solid var(--ta-border); border-radius: 0 8px 8px 0; background: var(--ta-side); color: var(--ta-body); line-height: 1.55; overflow-wrap: anywhere; }
|
|
3044
|
+
.trm-grant-list { margin: 0; padding: 4px 0; list-style: none; border: 1px solid var(--ta-border-muted); border-radius: 12px; }
|
|
3045
|
+
.trm-grant-list .trm-grant-item + .trm-grant-item { border-top: 1px solid var(--ta-border-muted); }
|
|
3046
|
+
.trm-grant-field { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
|
3047
|
+
.trm-grant-label { flex: none; width: 56px; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
3048
|
+
.trm-grant-dir { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; min-height: 34px; padding: 0 10px; border: 1px solid var(--ta-border-muted); border-radius: 8px; background: var(--ta-side); color: var(--ta-text); font: inherit; font-family: var(--ta-mono); font-size: calc(12px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
|
|
3049
|
+
.trm-grant-dir > svg { flex: none; color: var(--ta-muted); }
|
|
3050
|
+
.trm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
3051
|
+
.trm-chip { min-height: 30px; padding: 0 12px; border: 1px solid var(--ta-border-muted); border-radius: 999px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
|
|
3052
|
+
.trm-chip-on { border-color: var(--ta-green); background: var(--ta-hover); color: var(--ta-text); font-weight: 500; }
|
|
3053
|
+
.trm-panel-note { display: block; margin: 0 10px 8px; }
|
|
3054
|
+
.trm-log-label { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
|
|
3055
|
+
.trm-logs { margin: 0; padding: 0; list-style: none; }
|
|
3056
|
+
.trm-log { display: flex; flex-direction: column; gap: 4px; padding: 10px; border-radius: 12px; }
|
|
3057
|
+
.trm-log + .trm-log { border-top: 1px solid var(--ta-border-muted); border-radius: 0; }
|
|
3058
|
+
.trm-log-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
3059
|
+
.trm-log-who { flex: 1; color: var(--ta-secondary); font-size: calc(12px * var(--ta-font-scale)); }
|
|
3060
|
+
.trm-log-time { flex: none; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
3061
|
+
.trm-log-asked { color: var(--ta-text); line-height: 1.5; overflow-wrap: anywhere; }
|
|
3062
|
+
.trm-log-answer { padding-left: 10px; border-left: 2px solid var(--ta-border-muted); color: var(--ta-secondary); line-height: 1.5; overflow-wrap: anywhere; }
|
|
3063
|
+
.trm-log-meta { color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); }
|
|
3064
|
+
.trm-log-meta.trm-log-bad { color: var(--ta-yellow); }
|
|
3065
|
+
.trm-log-empty { display: flex; flex-direction: column; padding: 12px 0; }
|
|
3066
|
+
[data-layout='compact'] .trm-room-head-sub { display: none; }
|
|
3067
|
+
[data-layout='compact'] .trm-faces.trm-on-icon, [data-layout='compact'] .trm-faces.trm-on-icon .trm-faces-one { background: none; }
|
|
3068
|
+
@media (max-width: 720px) {
|
|
3069
|
+
.trm-chat-col, .trm-chat-bottom { padding-left: 12px; padding-right: 12px; }
|
|
3070
|
+
.trm-msg-col { max-width: calc(100% - 40px); }
|
|
3071
|
+
.trm-page-line { width: calc(100% - 24px); }
|
|
3072
|
+
}
|
|
3073
|
+
@media (max-width: 480px) { .trm-answers .ta-button { padding-left: 10px; padding-right: 10px; } }
|
|
3074
|
+
@media (prefers-reduced-motion: reduce) { .trm-room, .trm-page-line { transition: none; } }
|
|
3075
|
+
`;
|
|
3076
|
+
function injectStyle() {
|
|
3077
|
+
const element = document.createElement("style");
|
|
3078
|
+
element.dataset.taPackage = "ta-rooms";
|
|
3079
|
+
element.textContent = STYLE;
|
|
3080
|
+
document.head.appendChild(element);
|
|
3081
|
+
return () => element.remove();
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
// web-src/index.tsx
|
|
3085
|
+
var OPEN_WITHIN_MS = 15 * 60 * 1000;
|
|
3086
|
+
function tell(pi2, changes) {
|
|
3087
|
+
for (const { before, room } of changes) {
|
|
3088
|
+
if (before?.status === "waiting" && room.status === "member") {
|
|
3089
|
+
pi2.ui.notify(t("admitted", { title: room.title }));
|
|
3090
|
+
if (Date.now() - room.createdAt < OPEN_WITHIN_MS) {
|
|
3091
|
+
if (room.view) {
|
|
3092
|
+
pi2.ui.showView(room.view);
|
|
3093
|
+
} else {
|
|
3094
|
+
openRoom(room.id);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
} else if (before?.status === "waiting" && room.status === "refused") {
|
|
3098
|
+
pi2.ui.notify(t("refusedNotice", { by: room.ownerName, title: room.title }), "warning");
|
|
3099
|
+
} else if (before?.status === "member" && room.status === "gone") {
|
|
3100
|
+
pi2.ui.notify(room.reason === "removed" ? t("removedNotice", { title: room.title }) : t("closedNotice", { title: room.title }), "warning");
|
|
3101
|
+
if (book.get().opened === room.id) {
|
|
3102
|
+
book.set({ opened: undefined });
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
function activate(pi2) {
|
|
3108
|
+
bind(pi2.React);
|
|
3109
|
+
bindPage(pi2);
|
|
3110
|
+
const removeStyle = injectStyle();
|
|
3111
|
+
pi2.registerView("rooms", { title: () => t("roomsTitle"), icon: icon("Users"), render: RoomsPage, head: RoomsHead, discover: true, order: 81 });
|
|
3112
|
+
pi2.registerView("members", { title: () => t("membersTitle"), icon: icon("Users"), render: MembersView, location: "panel", order: 90 });
|
|
3113
|
+
pi2.registerView(DOUBLES_VIEW.slice(DOUBLES_VIEW.lastIndexOf("/") + 1), {
|
|
3114
|
+
title: () => dt("logTitle"),
|
|
3115
|
+
icon: icon("Bot"),
|
|
3116
|
+
render: DoublesView,
|
|
3117
|
+
location: "panel",
|
|
3118
|
+
order: 91
|
|
3119
|
+
});
|
|
3120
|
+
pi2.registerSettings(roomsSettings());
|
|
3121
|
+
const home = new RoomsHome;
|
|
3122
|
+
const stopHome = pi2.rooms ? home.start() : () => {
|
|
3123
|
+
return;
|
|
3124
|
+
};
|
|
3125
|
+
if (pi2.rooms) {
|
|
3126
|
+
pi2.registerHomeItems?.(home);
|
|
3127
|
+
}
|
|
3128
|
+
const stopAsks = pi2.rooms ? listenAsks() : () => {
|
|
3129
|
+
return;
|
|
3130
|
+
};
|
|
3131
|
+
pi2.registerOpener((link) => {
|
|
3132
|
+
if (link.type !== "url" || !RelayHubUtil.is(link.url)) {
|
|
3133
|
+
return false;
|
|
3134
|
+
}
|
|
3135
|
+
openJoin(link.url);
|
|
3136
|
+
return true;
|
|
3137
|
+
}, { specific: true });
|
|
3138
|
+
const stop = pi2.onRoomEvent?.((event) => {
|
|
3139
|
+
if (event.type === "request") {
|
|
3140
|
+
book.load().then(() => openRequests());
|
|
3141
|
+
} else if (event.type === "rooms") {
|
|
3142
|
+
book.reload();
|
|
3143
|
+
} else {
|
|
3144
|
+
book.heard(event);
|
|
3145
|
+
}
|
|
3146
|
+
}, { messages: false, state: CHAT_STATE });
|
|
3147
|
+
book.onChange = (changes) => tell(pi2, changes);
|
|
3148
|
+
if (pi2.rooms) {
|
|
3149
|
+
book.load().then(() => {
|
|
3150
|
+
if (book.get().requests.length) {
|
|
3151
|
+
openRequests();
|
|
3152
|
+
}
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
return () => {
|
|
3156
|
+
stop?.();
|
|
3157
|
+
stopAsks();
|
|
3158
|
+
stopHome();
|
|
3159
|
+
book.onChange = undefined;
|
|
3160
|
+
removeStyle();
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
export {
|
|
3164
|
+
activate as default
|
|
3165
|
+
};
|