@celljs/ta-rooms 4.11.0 → 4.13.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 +14 -5
- package/README.md +14 -5
- package/extension/index.mjs +526 -0
- package/host/index.mjs +1734 -0
- package/package.json +22 -7
- package/web/index.js +2585 -470
package/web/index.js
CHANGED
|
@@ -174,9 +174,16 @@ var RelayHubUtil;
|
|
|
174
174
|
(function(RelayHubUtil2) {
|
|
175
175
|
function link(link2) {
|
|
176
176
|
const fragment = new URLSearchParams({ v: "1", r: link2.room, i: link2.invite, o: link2.owner, n: link2.title, by: link2.by });
|
|
177
|
+
if (link2.kind) {
|
|
178
|
+
fragment.set("c", link2.kind);
|
|
179
|
+
}
|
|
177
180
|
return `${link2.relay}${RELAY_ROOM_PATH}#${fragment}`;
|
|
178
181
|
}
|
|
179
182
|
RelayHubUtil2.link = link;
|
|
183
|
+
function withKind(text, kind) {
|
|
184
|
+
return link({ ...parse(text), kind });
|
|
185
|
+
}
|
|
186
|
+
RelayHubUtil2.withKind = withKind;
|
|
180
187
|
function is(text) {
|
|
181
188
|
try {
|
|
182
189
|
parse(text);
|
|
@@ -187,7 +194,7 @@ var RelayHubUtil;
|
|
|
187
194
|
}
|
|
188
195
|
RelayHubUtil2.is = is;
|
|
189
196
|
function parse(text) {
|
|
190
|
-
var _a, _b;
|
|
197
|
+
var _a, _b, _c;
|
|
191
198
|
const url = new URL(text.trim());
|
|
192
199
|
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
193
200
|
const [room, invite, owner] = ["r", "i", "o"].map((name) => {
|
|
@@ -197,7 +204,16 @@ var RelayHubUtil;
|
|
|
197
204
|
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
205
|
throw new Error("Not a link inviting into a room of Ta.");
|
|
199
206
|
}
|
|
200
|
-
|
|
207
|
+
const kind = (_a = fragment.get("c")) !== null && _a !== undefined ? _a : "";
|
|
208
|
+
return {
|
|
209
|
+
relay: url.origin,
|
|
210
|
+
room,
|
|
211
|
+
invite,
|
|
212
|
+
owner,
|
|
213
|
+
title: ((_b = fragment.get("n")) !== null && _b !== undefined ? _b : "").slice(0, 200),
|
|
214
|
+
by: ((_c = fragment.get("by")) !== null && _c !== undefined ? _c : "").slice(0, 100),
|
|
215
|
+
.../^[a-z0-9-]{1,40}$/.test(kind) ? { kind } : {}
|
|
216
|
+
};
|
|
201
217
|
}
|
|
202
218
|
RelayHubUtil2.parse = parse;
|
|
203
219
|
function randomId() {
|
|
@@ -306,6 +322,100 @@ ${d}`, s)) {
|
|
|
306
322
|
RelayHubUtil2.openAnswer = openAnswer;
|
|
307
323
|
})(RelayHubUtil || (RelayHubUtil = {}));
|
|
308
324
|
|
|
325
|
+
// ../ta-relay/esm/common/relay-friends.js
|
|
326
|
+
var RELAY_FRIENDS_KIND = "ta-friends";
|
|
327
|
+
var LEGACY_KINDS = new Set(["ta-moments"]);
|
|
328
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
329
|
+
var RelayFriendsUtil;
|
|
330
|
+
(function(RelayFriendsUtil2) {
|
|
331
|
+
function isKind(kind) {
|
|
332
|
+
return kind === RELAY_FRIENDS_KIND || !!kind && LEGACY_KINDS.has(kind);
|
|
333
|
+
}
|
|
334
|
+
RelayFriendsUtil2.isKind = isKind;
|
|
335
|
+
function kindOf(kind) {
|
|
336
|
+
return LEGACY_KINDS.has(kind) ? RELAY_FRIENDS_KIND : kind;
|
|
337
|
+
}
|
|
338
|
+
RelayFriendsUtil2.kindOf = kindOf;
|
|
339
|
+
function isFriend(friend) {
|
|
340
|
+
const value = friend;
|
|
341
|
+
return !!value && typeof value.id === "string" && typeof value.name === "string" && typeof value.metAt === "number" && typeof value.seenAt === "number";
|
|
342
|
+
}
|
|
343
|
+
RelayFriendsUtil2.isFriend = isFriend;
|
|
344
|
+
function clean(friend) {
|
|
345
|
+
var _a;
|
|
346
|
+
return {
|
|
347
|
+
id: friend.id,
|
|
348
|
+
name: String((_a = friend.name) !== null && _a !== undefined ? _a : "").slice(0, 40),
|
|
349
|
+
...typeof friend.sign === "string" ? { sign: friend.sign } : {},
|
|
350
|
+
...typeof friend.box === "string" ? { box: friend.box } : {},
|
|
351
|
+
metAt: friend.metAt,
|
|
352
|
+
seenAt: friend.seenAt
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
RelayFriendsUtil2.clean = clean;
|
|
356
|
+
function mergeFriend(local, other) {
|
|
357
|
+
var _a, _b;
|
|
358
|
+
const later = other.seenAt > local.seenAt ? other : local;
|
|
359
|
+
const earlier = later === local ? other : local;
|
|
360
|
+
return clean({
|
|
361
|
+
...earlier,
|
|
362
|
+
...later,
|
|
363
|
+
sign: (_a = later.sign) !== null && _a !== undefined ? _a : earlier.sign,
|
|
364
|
+
box: (_b = later.box) !== null && _b !== undefined ? _b : earlier.box,
|
|
365
|
+
metAt: Math.min(local.metAt, other.metAt),
|
|
366
|
+
seenAt: Math.max(local.seenAt, other.seenAt)
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
RelayFriendsUtil2.mergeFriend = mergeFriend;
|
|
370
|
+
function requestOf(offer) {
|
|
371
|
+
return { id: offer.id, name: offer.name, at: offer.at, via: "room", room: offer.room };
|
|
372
|
+
}
|
|
373
|
+
RelayFriendsUtil2.requestOf = requestOf;
|
|
374
|
+
function book(value) {
|
|
375
|
+
const read = value !== null && value !== undefined ? value : {};
|
|
376
|
+
if (read.v !== 2) {
|
|
377
|
+
return { v: 2, friends: [], offers: [] };
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
v: 2,
|
|
381
|
+
friends: Array.isArray(read.friends) ? read.friends.filter(isFriend) : [],
|
|
382
|
+
offers: Array.isArray(read.offers) ? read.offers.filter((offer) => !!offer && typeof offer.id === "string" && typeof offer.link === "string") : []
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
RelayFriendsUtil2.book = book;
|
|
386
|
+
function migrate(records, stored) {
|
|
387
|
+
const read = stored !== null && stored !== undefined ? stored : {};
|
|
388
|
+
const legacy = records.some((record) => LEGACY_KINDS.has(record.kind));
|
|
389
|
+
if (read.v === 2 && !legacy) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const next = records.map((record) => LEGACY_KINDS.has(record.kind) ? { ...record, kind: RELAY_FRIENDS_KIND } : record);
|
|
393
|
+
if (read.v === 2) {
|
|
394
|
+
return { records: next, book: book(stored) };
|
|
395
|
+
}
|
|
396
|
+
const before = Array.isArray(read.friends) ? read.friends : [];
|
|
397
|
+
const now = Date.now();
|
|
398
|
+
const friends = [];
|
|
399
|
+
for (const record of next) {
|
|
400
|
+
if (record.own || record.kind !== RELAY_FRIENDS_KIND || record.status !== "member" && record.status !== "waiting") {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const known = before.find((friend) => (friend === null || friend === undefined ? undefined : friend.id) === record.owner.id);
|
|
404
|
+
if (!friends.some((friend) => friend.id === record.owner.id)) {
|
|
405
|
+
friends.push(clean({
|
|
406
|
+
...known !== null && known !== undefined ? known : {},
|
|
407
|
+
...record.owner,
|
|
408
|
+
name: record.owner.name || (known === null || known === undefined ? undefined : known.name) || "",
|
|
409
|
+
metAt: typeof (known === null || known === undefined ? undefined : known.metAt) === "number" ? known.metAt : now,
|
|
410
|
+
seenAt: typeof (known === null || known === undefined ? undefined : known.seenAt) === "number" ? known.seenAt : now
|
|
411
|
+
}));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return { records: next, book: { v: 2, friends, offers: [] } };
|
|
415
|
+
}
|
|
416
|
+
RelayFriendsUtil2.migrate = migrate;
|
|
417
|
+
})(RelayFriendsUtil || (RelayFriendsUtil = {}));
|
|
418
|
+
|
|
309
419
|
// ../ta-relay/esm/common/relay-room-chat.js
|
|
310
420
|
var RELAY_CHAT_KEY = "chat:";
|
|
311
421
|
var RELAY_CHAT_PART_BYTES = 8 * 1024;
|
|
@@ -330,14 +440,26 @@ var RelayRoomChatUtil;
|
|
|
330
440
|
const lines2 = [];
|
|
331
441
|
for (const line of value) {
|
|
332
442
|
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 });
|
|
443
|
+
lines2.push({ id: line.id, from: member, name: typeof line.name === "string" ? line.name : "", text: line.text, at: line.at, ...extra(line) });
|
|
334
444
|
}
|
|
335
445
|
}
|
|
336
446
|
return lines2;
|
|
337
447
|
}
|
|
338
448
|
RelayRoomChatUtil2.lines = lines;
|
|
449
|
+
function extra(line) {
|
|
450
|
+
const to = Array.isArray(line.to) ? line.to.filter((each) => typeof each === "string").slice(0, 16) : [];
|
|
451
|
+
const agent = line.agent;
|
|
452
|
+
return {
|
|
453
|
+
...line.double === true ? { double: true } : {},
|
|
454
|
+
...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) } } : {},
|
|
455
|
+
...to.length ? { to } : {},
|
|
456
|
+
...typeof line.re === "string" ? { re: line.re } : {},
|
|
457
|
+
...line.task === true && to.length ? { task: true } : {}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
RelayRoomChatUtil2.extra = extra;
|
|
339
461
|
function stored(lines2) {
|
|
340
|
-
return lines2.map(({
|
|
462
|
+
return lines2.map(({ from: _from, ...line }) => line);
|
|
341
463
|
}
|
|
342
464
|
RelayRoomChatUtil2.stored = stored;
|
|
343
465
|
function bytes(lines2) {
|
|
@@ -385,7 +507,7 @@ class RelayRoomChat {
|
|
|
385
507
|
this.changed();
|
|
386
508
|
return true;
|
|
387
509
|
}
|
|
388
|
-
async say(text, self) {
|
|
510
|
+
async say(text, self, extra = {}) {
|
|
389
511
|
var _a;
|
|
390
512
|
var _b, _c;
|
|
391
513
|
const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
|
|
@@ -396,7 +518,14 @@ class RelayRoomChat {
|
|
|
396
518
|
const latest = this.latest(self.member);
|
|
397
519
|
const last = latest === null || latest === undefined ? undefined : latest.lines[latest.lines.length - 1];
|
|
398
520
|
const at = Math.max(Date.now(), ((_b = last === null || last === undefined ? undefined : last.at) !== null && _b !== undefined ? _b : 0) + 1);
|
|
399
|
-
const line = {
|
|
521
|
+
const line = {
|
|
522
|
+
id: RelayRoomChatUtil.id(),
|
|
523
|
+
from: self.member,
|
|
524
|
+
name: self.name,
|
|
525
|
+
text: said,
|
|
526
|
+
at,
|
|
527
|
+
...RelayRoomChatUtil.extra(extra)
|
|
528
|
+
};
|
|
400
529
|
const fits = latest && RelayRoomChatUtil.bytes(RelayRoomChatUtil.stored([...latest.lines, line])) <= RELAY_CHAT_PART_BYTES;
|
|
401
530
|
const part = !latest ? 0 : fits ? latest.part : latest.part + 1;
|
|
402
531
|
const lines = fits && latest ? [...latest.lines, line] : [line];
|
|
@@ -409,7 +538,7 @@ class RelayRoomChat {
|
|
|
409
538
|
if (part >= RELAY_CHAT_PARTS) {
|
|
410
539
|
this.clear(RelayRoomChatUtil.key(self.member, part - RELAY_CHAT_PARTS));
|
|
411
540
|
}
|
|
412
|
-
return;
|
|
541
|
+
return line;
|
|
413
542
|
}
|
|
414
543
|
await this.load();
|
|
415
544
|
}
|
|
@@ -449,6 +578,97 @@ class RelayRoomChat {
|
|
|
449
578
|
}
|
|
450
579
|
}
|
|
451
580
|
|
|
581
|
+
// web-src/double-protocol.ts
|
|
582
|
+
var ROOM_AGENTS_KEY = "agents:";
|
|
583
|
+
var RoomAgentsUtil;
|
|
584
|
+
((RoomAgentsUtil) => {
|
|
585
|
+
function key(member) {
|
|
586
|
+
return `${ROOM_AGENTS_KEY}${member}`;
|
|
587
|
+
}
|
|
588
|
+
RoomAgentsUtil.key = key;
|
|
589
|
+
function address(member, agent) {
|
|
590
|
+
return `${member}/${agent}`;
|
|
591
|
+
}
|
|
592
|
+
RoomAgentsUtil.address = address;
|
|
593
|
+
function list(member, value, by) {
|
|
594
|
+
if (by !== member || !Array.isArray(value)) {
|
|
595
|
+
return [];
|
|
596
|
+
}
|
|
597
|
+
return value.filter((agent) => agent && typeof agent.id === "string" && agent.id && typeof agent.name === "string").slice(0, 16).map((agent) => ({
|
|
598
|
+
id: agent.id,
|
|
599
|
+
name: agent.name,
|
|
600
|
+
...typeof agent.role === "string" && agent.role ? { role: agent.role } : {},
|
|
601
|
+
...Number.isInteger(agent.face) && agent.face >= 0 && agent.face < 64 ? { face: agent.face } : {}
|
|
602
|
+
}));
|
|
603
|
+
}
|
|
604
|
+
RoomAgentsUtil.list = list;
|
|
605
|
+
function of(state) {
|
|
606
|
+
return Object.entries(state).flatMap(([key2, value]) => {
|
|
607
|
+
if (!key2.startsWith(ROOM_AGENTS_KEY) || value.value === null) {
|
|
608
|
+
return [];
|
|
609
|
+
}
|
|
610
|
+
const member = key2.slice(ROOM_AGENTS_KEY.length);
|
|
611
|
+
return list(member, value.value, value.by).map((agent) => ({ ...agent, member }));
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
RoomAgentsUtil.of = of;
|
|
615
|
+
})(RoomAgentsUtil ||= {});
|
|
616
|
+
var TASK_STATUSES = ["queued", "running", "permission", "done", "failed", "stopped", "declined"];
|
|
617
|
+
var ROOM_TASKS_KEY = "tasks:";
|
|
618
|
+
var ROOM_CANCEL_KEY = "cancel:";
|
|
619
|
+
var ROOM_TASKS_SHOWN = 30;
|
|
620
|
+
var RoomTasksUtil;
|
|
621
|
+
((RoomTasksUtil) => {
|
|
622
|
+
function key(member) {
|
|
623
|
+
return `${ROOM_TASKS_KEY}${member}`;
|
|
624
|
+
}
|
|
625
|
+
RoomTasksUtil.key = key;
|
|
626
|
+
function cancelKey(member) {
|
|
627
|
+
return `${ROOM_CANCEL_KEY}${member}`;
|
|
628
|
+
}
|
|
629
|
+
RoomTasksUtil.cancelKey = cancelKey;
|
|
630
|
+
function ended(status) {
|
|
631
|
+
return status === "done" || status === "failed" || status === "stopped" || status === "declined";
|
|
632
|
+
}
|
|
633
|
+
RoomTasksUtil.ended = ended;
|
|
634
|
+
function of(member, value, by) {
|
|
635
|
+
if (by !== member || !value || typeof value !== "object" || Array.isArray(value)) {
|
|
636
|
+
return {};
|
|
637
|
+
}
|
|
638
|
+
const tasks = {};
|
|
639
|
+
for (const [id, task] of Object.entries(value).slice(-ROOM_TASKS_SHOWN)) {
|
|
640
|
+
if (task && TASK_STATUSES.includes(task.status) && typeof task.at === "number") {
|
|
641
|
+
tasks[id] = {
|
|
642
|
+
status: task.status,
|
|
643
|
+
at: task.at,
|
|
644
|
+
...typeof task.detail === "string" && task.detail ? { detail: task.detail.slice(0, 200) } : {}
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return tasks;
|
|
649
|
+
}
|
|
650
|
+
RoomTasksUtil.of = of;
|
|
651
|
+
function cancelled(member, value, by) {
|
|
652
|
+
return by === member && Array.isArray(value) ? value.filter((id) => typeof id === "string").slice(-ROOM_TASKS_SHOWN) : [];
|
|
653
|
+
}
|
|
654
|
+
RoomTasksUtil.cancelled = cancelled;
|
|
655
|
+
})(RoomTasksUtil ||= {});
|
|
656
|
+
var TASK_MESSAGE_TYPE = "ta-rooms:task";
|
|
657
|
+
var ROOM_CAPABILITIES = ["files", "commands"];
|
|
658
|
+
var DoubleKeys;
|
|
659
|
+
((DoubleKeys) => {
|
|
660
|
+
DoubleKeys.QUIET = "doubles.quiet";
|
|
661
|
+
DoubleKeys.GRANTS = "doubles.grants";
|
|
662
|
+
DoubleKeys.ASKS = "doubles.asks";
|
|
663
|
+
DoubleKeys.LOG = "doubles.log";
|
|
664
|
+
DoubleKeys.SESSIONS = "doubles.sessions";
|
|
665
|
+
DoubleKeys.READ = "doubles.read";
|
|
666
|
+
DoubleKeys.TASKS = "doubles.tasks";
|
|
667
|
+
DoubleKeys.HANDED = "doubles.handed";
|
|
668
|
+
DoubleKeys.DEVICE = "doubles.device";
|
|
669
|
+
})(DoubleKeys ||= {});
|
|
670
|
+
var GRANT_HOURS = [1, 24, 24 * 7];
|
|
671
|
+
|
|
452
672
|
// web-src/i18n.ts
|
|
453
673
|
var EN = {
|
|
454
674
|
roomsTitle: "Rooms",
|
|
@@ -459,16 +679,16 @@ var EN = {
|
|
|
459
679
|
renamePlaceholder: "What others see",
|
|
460
680
|
requests: "Asking to join",
|
|
461
681
|
requestLine: "wants to join “{title}”",
|
|
462
|
-
friendTag: "
|
|
682
|
+
friendTag: "Friend",
|
|
463
683
|
newTag: "New",
|
|
464
684
|
guestTag: "Web guest",
|
|
465
|
-
requestGuest: "They ask from a browser, without Ta: let in, they only chat
|
|
685
|
+
requestGuest: "They ask from a browser, without Ta: let in, they only chat.",
|
|
466
686
|
accept: "Let in",
|
|
467
687
|
refuse: "Refuse",
|
|
468
688
|
requestBody: "{name} wants to join your room “{title}”.",
|
|
469
689
|
requestsBody: "{n} people ask to join your rooms.",
|
|
470
|
-
requestFriend: "
|
|
471
|
-
requestNew: "
|
|
690
|
+
requestFriend: "They are your friend.",
|
|
691
|
+
requestNew: "They are not your friend: let in only someone you know.",
|
|
472
692
|
requestWhat: "Once in, they see the messages and the shared state of the room: in a game, where everyone is and what is built.",
|
|
473
693
|
later: "Later",
|
|
474
694
|
ownRoom: "Your room",
|
|
@@ -495,6 +715,8 @@ var EN = {
|
|
|
495
715
|
send: "Send…",
|
|
496
716
|
qr: "QR code of the invitation",
|
|
497
717
|
members: "Members",
|
|
718
|
+
memberCount: "{n} members",
|
|
719
|
+
onlineCount: "{n} online",
|
|
498
720
|
membersTitle: "Members of the room",
|
|
499
721
|
membersCount: "{n} members · {online} online",
|
|
500
722
|
noRoomOpen: "Open a room to see who is in it",
|
|
@@ -512,13 +734,34 @@ var EN = {
|
|
|
512
734
|
closeTitle: "Close “{title}” for everyone?",
|
|
513
735
|
closeHint: "Everyone is taken out, and the relay deletes all the room kept.",
|
|
514
736
|
forget: "Remove",
|
|
515
|
-
friends: "
|
|
516
|
-
|
|
737
|
+
friends: "Friends",
|
|
738
|
+
friendsCount: "{n}",
|
|
739
|
+
friendsNone: "Add one",
|
|
740
|
+
friendAdding: "Waiting for them to agree",
|
|
517
741
|
removeFriend: "Remove",
|
|
518
|
-
removeFriendTitle: "Remove {name} from your
|
|
519
|
-
removeFriendHint: "The rooms you share stay as they are.",
|
|
742
|
+
removeFriendTitle: "Remove {name} from your friends?",
|
|
743
|
+
removeFriendHint: "You are no longer friends on both sides: neither sees the other’s posts, nor what is shared with friends. The rooms you share stay as they are.",
|
|
744
|
+
addFriend: "Add friend",
|
|
745
|
+
addFriendHint: "Let them scan this code, or send them the link. Once you both agree, you are friends: you see each other’s posts and may share with each other.",
|
|
746
|
+
addFriendExpires: "Works for {days} more days",
|
|
747
|
+
addFriendAction: "Add as friend",
|
|
748
|
+
addFriendBody: "Ask {name} to be your friend? They see your name and answer in their Ta. Once both agree, you see each other’s posts and may share with each other.",
|
|
749
|
+
addFriendOwn: "This is your own code.",
|
|
750
|
+
addFriendKnown: "{name} is already your friend.",
|
|
751
|
+
addFriendAsked: "Asked {name}: you are friends once they agree",
|
|
752
|
+
friendOffer: "Add friend",
|
|
753
|
+
friendOffered: "Asked {name} to be friends",
|
|
754
|
+
friendRequestsTitle: "New friends",
|
|
755
|
+
friendRequestLink: "Wants to be your friend",
|
|
756
|
+
friendRequestRoom: "Asks in “{room}” to be your friend",
|
|
757
|
+
friendAccept: "Agree",
|
|
758
|
+
friendRequestNote: "Once friends, you see each other’s posts, and they may share with you. Agree only to someone you know.",
|
|
759
|
+
friendsEmpty: "No friends yet",
|
|
760
|
+
friendsEmptyHint: "Add a friend by a code or a link, or from the members of a room you are both in.",
|
|
761
|
+
scanFriend: "Scan",
|
|
762
|
+
pasteFriend: "Paste a link",
|
|
520
763
|
emptyTitle: "No rooms yet",
|
|
521
|
-
|
|
764
|
+
emptyListHint: "Make one with +, or open a link of invitation",
|
|
522
765
|
pickRoom: "Pick a room to chat in",
|
|
523
766
|
joinTitle: "Join “{title}”?",
|
|
524
767
|
joinBody: "A room of {by}. They let you in first, and your name “{name}” goes to them.",
|
|
@@ -542,7 +785,9 @@ var EN = {
|
|
|
542
785
|
openPage: "Open {name}",
|
|
543
786
|
pageLine: "A room of {name}: play in it together",
|
|
544
787
|
chatEmpty: "Nothing said yet. Only those in the room read it: the relay keeps it sealed.",
|
|
545
|
-
chatPlaceholder: "Message"
|
|
788
|
+
chatPlaceholder: "Message",
|
|
789
|
+
showOnHome: "Show rooms on the double's home",
|
|
790
|
+
showOnHomeHint: "With rooms, the double's home has a Rooms section, beside members and channels."
|
|
546
791
|
};
|
|
547
792
|
var ZH = {
|
|
548
793
|
roomsTitle: "房间",
|
|
@@ -553,16 +798,16 @@ var ZH = {
|
|
|
553
798
|
renamePlaceholder: "别人看到的名字",
|
|
554
799
|
requests: "加入申请",
|
|
555
800
|
requestLine: "想加入「{title}」",
|
|
556
|
-
friendTag: "
|
|
801
|
+
friendTag: "好友",
|
|
557
802
|
newTag: "新朋友",
|
|
558
803
|
guestTag: "网页访客",
|
|
559
|
-
requestGuest: "对方是用浏览器申请的,没有装 Ta
|
|
804
|
+
requestGuest: "对方是用浏览器申请的,没有装 Ta:进来后只能聊天。",
|
|
560
805
|
accept: "同意",
|
|
561
806
|
refuse: "拒绝",
|
|
562
807
|
requestBody: "「{name}」想加入你的房间「{title}」。",
|
|
563
808
|
requestsBody: "有 {n} 人申请加入你的房间。",
|
|
564
|
-
requestFriend: "
|
|
565
|
-
requestNew: "
|
|
809
|
+
requestFriend: "对方是你的好友。",
|
|
810
|
+
requestNew: "对方不是你的好友:只让认识的人进来。",
|
|
566
811
|
requestWhat: "进来后,对方能看到房间里的消息和共享的内容;在游戏里就是大家的位置和搭的东西。",
|
|
567
812
|
later: "稍后",
|
|
568
813
|
ownRoom: "我建的房间",
|
|
@@ -589,6 +834,8 @@ var ZH = {
|
|
|
589
834
|
send: "发送…",
|
|
590
835
|
qr: "邀请二维码",
|
|
591
836
|
members: "成员",
|
|
837
|
+
memberCount: "{n} 位成员",
|
|
838
|
+
onlineCount: "{n} 人在线",
|
|
592
839
|
membersTitle: "房间成员",
|
|
593
840
|
membersCount: "{n} 位成员 · {online} 人在线",
|
|
594
841
|
noRoomOpen: "打开一个房间,这里显示它的成员",
|
|
@@ -606,13 +853,34 @@ var ZH = {
|
|
|
606
853
|
closeTitle: "解散「{title}」?",
|
|
607
854
|
closeHint: "所有人都会被移出,中继会删除房间保存的全部内容。",
|
|
608
855
|
forget: "删除",
|
|
609
|
-
friends: "
|
|
610
|
-
|
|
856
|
+
friends: "好友",
|
|
857
|
+
friendsCount: "{n} 位",
|
|
858
|
+
friendsNone: "去添加",
|
|
859
|
+
friendAdding: "等对方同意",
|
|
611
860
|
removeFriend: "删除",
|
|
612
|
-
removeFriendTitle: "
|
|
613
|
-
removeFriendHint: "
|
|
861
|
+
removeFriendTitle: "删除好友「{name}」?",
|
|
862
|
+
removeFriendHint: "两边同时不再是好友:互相看不到动态,也收不到只给好友的分享。一起所在的房间不受影响。",
|
|
863
|
+
addFriend: "加好友",
|
|
864
|
+
addFriendHint: "让对方扫这个码,或把链接发给对方。双方都同意后就是好友:互相看到动态,也能互相分享。",
|
|
865
|
+
addFriendExpires: "还能用 {days} 天",
|
|
866
|
+
addFriendAction: "加为好友",
|
|
867
|
+
addFriendBody: "请「{name}」加你为好友?对方会看到你的名字,在自己的 Ta 里同意。双方同意后互相看到动态,也能互相分享。",
|
|
868
|
+
addFriendOwn: "这是你自己的二维码。",
|
|
869
|
+
addFriendKnown: "「{name}」已经是你的好友。",
|
|
870
|
+
addFriendAsked: "已向「{name}」发出申请,对方同意后就是好友",
|
|
871
|
+
friendOffer: "加好友",
|
|
872
|
+
friendOffered: "已请「{name}」加你为好友",
|
|
873
|
+
friendRequestsTitle: "新的好友",
|
|
874
|
+
friendRequestLink: "想加你为好友",
|
|
875
|
+
friendRequestRoom: "在「{room}」里想加你为好友",
|
|
876
|
+
friendAccept: "同意",
|
|
877
|
+
friendRequestNote: "成为好友后互相看到动态,对方也能给你分享东西。只同意认识的人。",
|
|
878
|
+
friendsEmpty: "还没有好友",
|
|
879
|
+
friendsEmptyHint: "用二维码或链接加好友,也可以在一起所在房间的成员里加。",
|
|
880
|
+
scanFriend: "扫一扫",
|
|
881
|
+
pasteFriend: "粘贴链接",
|
|
614
882
|
emptyTitle: "还没有房间",
|
|
615
|
-
|
|
883
|
+
emptyListHint: "点 + 新建一个,或打开别人发来的邀请链接",
|
|
616
884
|
pickRoom: "选一个房间开始聊天",
|
|
617
885
|
joinTitle: "加入「{title}」?",
|
|
618
886
|
joinBody: "这是{by}的房间。房主同意后你才能进去,你的名字「{name}」会发给对方。",
|
|
@@ -636,7 +904,9 @@ var ZH = {
|
|
|
636
904
|
openPage: "打开{name}",
|
|
637
905
|
pageLine: "{name}的房间,大家可以一起玩",
|
|
638
906
|
chatEmpty: "还没有人说话。只有房间里的人能看到,中继保存的是密文。",
|
|
639
|
-
chatPlaceholder: "发消息"
|
|
907
|
+
chatPlaceholder: "发消息",
|
|
908
|
+
showOnHome: "在分身首页显示房间",
|
|
909
|
+
showOnHomeHint: "有房间时,分身首页多一个“房间”分类,和成员、频道放在一起。"
|
|
640
910
|
};
|
|
641
911
|
var RoomWords;
|
|
642
912
|
((RoomWords) => {
|
|
@@ -659,8 +929,9 @@ function bind(react) {
|
|
|
659
929
|
// web-src/page.tsx
|
|
660
930
|
var ROOMS_KIND = "ta-rooms";
|
|
661
931
|
var ROOMS_VIEW = "@celljs/ta-rooms/rooms";
|
|
932
|
+
var FRIENDS_VIEW = "@celljs/ta-rooms/friends";
|
|
662
933
|
var MEMBERS_VIEW = "@celljs/ta-rooms/members";
|
|
663
|
-
var CHAT_STATE = ["chat:"];
|
|
934
|
+
var CHAT_STATE = ["chat:", ROOM_AGENTS_KEY, ROOM_TASKS_KEY];
|
|
664
935
|
var SEEN_KEY = "seen";
|
|
665
936
|
var pi;
|
|
666
937
|
function bindPage(api) {
|
|
@@ -680,9 +951,14 @@ function rooms() {
|
|
|
680
951
|
}
|
|
681
952
|
|
|
682
953
|
class RoomBook {
|
|
683
|
-
state = { requests: [], seen: {} };
|
|
954
|
+
state = { requests: [], friendRequests: [], seen: {} };
|
|
684
955
|
listeners = new Set;
|
|
685
956
|
chats = new Map;
|
|
957
|
+
agentStates = new Map;
|
|
958
|
+
agentLists = new Map;
|
|
959
|
+
taskStates = new Map;
|
|
960
|
+
taskLists = new Map;
|
|
961
|
+
joiningLists = new Map;
|
|
686
962
|
timer;
|
|
687
963
|
loading;
|
|
688
964
|
again = false;
|
|
@@ -702,16 +978,23 @@ class RoomBook {
|
|
|
702
978
|
}
|
|
703
979
|
const server = rooms();
|
|
704
980
|
if (!server) {
|
|
705
|
-
this.set({ rooms: [], friends: [] });
|
|
981
|
+
this.set({ rooms: [], friends: [], friendRequests: [] });
|
|
706
982
|
return Promise.resolve();
|
|
707
983
|
}
|
|
708
984
|
this.readSeen();
|
|
709
985
|
this.loading = Promise.all([
|
|
710
986
|
server.getIdentity().catch(() => this.state.identity),
|
|
711
|
-
server.listRooms().catch(() =>
|
|
987
|
+
server.listRooms().catch(() => {
|
|
988
|
+
return;
|
|
989
|
+
}),
|
|
712
990
|
server.listRequests().catch(() => this.state.requests),
|
|
713
|
-
server.listFriends().catch(() => this.state.friends ?? [])
|
|
714
|
-
|
|
991
|
+
server.listFriends().catch(() => this.state.friends ?? []),
|
|
992
|
+
server.listFriendRequests ? server.listFriendRequests().catch(() => this.state.friendRequests) : Promise.resolve([])
|
|
993
|
+
]).then(([identity, all, requests, friends, friendRequests]) => {
|
|
994
|
+
const unlisted = new Set((all ?? []).filter((room) => room.unlisted).map((room) => room.id));
|
|
995
|
+
const list = all ? all.filter((room) => !unlisted.has(room.id)) : this.state.rooms ?? [];
|
|
996
|
+
this.read({ ...this.state, identity, rooms: list, requests: requests.filter((request) => !unlisted.has(request.room)), friends, friendRequests });
|
|
997
|
+
}).finally(() => {
|
|
715
998
|
this.loading = undefined;
|
|
716
999
|
if (this.again) {
|
|
717
1000
|
this.again = false;
|
|
@@ -729,6 +1012,12 @@ class RoomBook {
|
|
|
729
1012
|
return;
|
|
730
1013
|
});
|
|
731
1014
|
}
|
|
1015
|
+
for (const room of this.agentStates.keys()) {
|
|
1016
|
+
this.readAgents(room);
|
|
1017
|
+
}
|
|
1018
|
+
for (const room of this.taskStates.keys()) {
|
|
1019
|
+
this.readTasks(room);
|
|
1020
|
+
}
|
|
732
1021
|
}, 300);
|
|
733
1022
|
}
|
|
734
1023
|
set(partial) {
|
|
@@ -752,33 +1041,108 @@ class RoomBook {
|
|
|
752
1041
|
}
|
|
753
1042
|
return chat;
|
|
754
1043
|
}
|
|
1044
|
+
agents(room) {
|
|
1045
|
+
if (!this.agentStates.has(room)) {
|
|
1046
|
+
this.agentStates.set(room, {});
|
|
1047
|
+
this.readAgents(room);
|
|
1048
|
+
}
|
|
1049
|
+
return this.agentLists.get(room) ?? NO_AGENTS;
|
|
1050
|
+
}
|
|
1051
|
+
tasks(room) {
|
|
1052
|
+
if (!this.taskStates.has(room)) {
|
|
1053
|
+
this.taskStates.set(room, {});
|
|
1054
|
+
this.readTasks(room);
|
|
1055
|
+
}
|
|
1056
|
+
return this.taskLists.get(room) ?? NO_TASKS;
|
|
1057
|
+
}
|
|
1058
|
+
joining(room) {
|
|
1059
|
+
return this.joiningLists.get(room) ?? NO_JOINING;
|
|
1060
|
+
}
|
|
1061
|
+
setJoining(room, agent, on) {
|
|
1062
|
+
const others = this.joining(room).filter((each) => each.id !== agent.id);
|
|
1063
|
+
this.joiningLists.set(room, on ? [...others, agent] : others);
|
|
1064
|
+
this.set({});
|
|
1065
|
+
}
|
|
1066
|
+
putMine(room, member, agents) {
|
|
1067
|
+
const known = this.agentStates.get(room);
|
|
1068
|
+
if (!known) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
const key = RoomAgentsUtil.key(member);
|
|
1072
|
+
this.putAgents(room, { ...known, [key]: { value: agents, by: member, version: known[key]?.version ?? 0 } });
|
|
1073
|
+
}
|
|
755
1074
|
heard(event) {
|
|
756
|
-
if (event.type
|
|
757
|
-
|
|
1075
|
+
if (event.type !== "state") {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
this.chats.get(event.room)?.heard(event.key, event);
|
|
1079
|
+
const known = this.agentStates.get(event.room);
|
|
1080
|
+
if (known && event.key.startsWith(ROOM_AGENTS_KEY) && (known[event.key]?.version ?? 0) < event.version) {
|
|
1081
|
+
this.putAgents(event.room, { ...known, [event.key]: event });
|
|
1082
|
+
}
|
|
1083
|
+
const tasks = this.taskStates.get(event.room);
|
|
1084
|
+
if (tasks && event.key.startsWith(ROOM_TASKS_KEY) && (tasks[event.key]?.version ?? 0) < event.version) {
|
|
1085
|
+
this.putTasks(event.room, { ...tasks, [event.key]: event });
|
|
758
1086
|
}
|
|
759
1087
|
}
|
|
1088
|
+
readTasks(room) {
|
|
1089
|
+
rooms()?.getState(room, ROOM_TASKS_KEY).then((state) => this.putTasks(room, state)).catch(() => {
|
|
1090
|
+
return;
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
putTasks(room, state) {
|
|
1094
|
+
this.taskStates.set(room, state);
|
|
1095
|
+
const lines = {};
|
|
1096
|
+
for (const [key, value] of Object.entries(state)) {
|
|
1097
|
+
const member = key.slice(ROOM_TASKS_KEY.length);
|
|
1098
|
+
for (const [id, task] of Object.entries(RoomTasksUtil.of(member, value.value, value.by))) {
|
|
1099
|
+
lines[id] = [...lines[id] ?? [], { ...task, member }];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
this.taskLists.set(room, lines);
|
|
1103
|
+
this.set({});
|
|
1104
|
+
}
|
|
1105
|
+
readAgents(room) {
|
|
1106
|
+
rooms()?.getState(room, ROOM_AGENTS_KEY).then((state) => this.putAgents(room, state)).catch(() => {
|
|
1107
|
+
return;
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
putAgents(room, state) {
|
|
1111
|
+
this.agentStates.set(room, state);
|
|
1112
|
+
this.agentLists.set(room, RoomAgentsUtil.of(state));
|
|
1113
|
+
this.set({});
|
|
1114
|
+
}
|
|
760
1115
|
see(room, at) {
|
|
761
1116
|
if ((this.state.seen[room] ?? 0) >= at) {
|
|
762
1117
|
return;
|
|
763
1118
|
}
|
|
764
|
-
|
|
765
|
-
this.
|
|
766
|
-
|
|
1119
|
+
this.set({ seen: { ...this.state.seen, [room]: at } });
|
|
1120
|
+
this.keepSeen();
|
|
1121
|
+
}
|
|
1122
|
+
async keepSeen() {
|
|
1123
|
+
const storage = pi.storage;
|
|
1124
|
+
if (!storage) {
|
|
767
1125
|
return;
|
|
768
|
-
}
|
|
1126
|
+
}
|
|
1127
|
+
try {
|
|
1128
|
+
const kept = RoomSeenUtil.parse(await storage.get(SEEN_KEY));
|
|
1129
|
+
const local = this.state.seen;
|
|
1130
|
+
const seen = RoomSeenUtil.merge(local, kept);
|
|
1131
|
+
if (seen !== local) {
|
|
1132
|
+
this.set({ seen });
|
|
1133
|
+
}
|
|
1134
|
+
if (RoomSeenUtil.merge(kept, local) !== kept) {
|
|
1135
|
+
await storage.set(SEEN_KEY, seen);
|
|
1136
|
+
}
|
|
1137
|
+
} catch {}
|
|
769
1138
|
}
|
|
770
1139
|
readSeen() {
|
|
771
1140
|
if (this.seenRead || !pi.storage) {
|
|
772
1141
|
return;
|
|
773
1142
|
}
|
|
774
1143
|
this.seenRead = true;
|
|
775
|
-
pi.storage.
|
|
776
|
-
|
|
777
|
-
this.set({ seen: { ...seen, ...this.state.seen } });
|
|
778
|
-
}
|
|
779
|
-
}).catch(() => {
|
|
780
|
-
return;
|
|
781
|
-
});
|
|
1144
|
+
pi.storage.onChange((keys) => keys.includes(SEEN_KEY) && void this.keepSeen());
|
|
1145
|
+
this.keepSeen();
|
|
782
1146
|
}
|
|
783
1147
|
read(next) {
|
|
784
1148
|
const before = new Map((this.state.rooms ?? []).map((room) => [room.id, room]));
|
|
@@ -799,6 +1163,9 @@ function useBook() {
|
|
|
799
1163
|
return state;
|
|
800
1164
|
}
|
|
801
1165
|
var NO_LINES = [];
|
|
1166
|
+
var NO_AGENTS = [];
|
|
1167
|
+
var NO_JOINING = [];
|
|
1168
|
+
var NO_TASKS = {};
|
|
802
1169
|
var NO_STOP = () => {
|
|
803
1170
|
return;
|
|
804
1171
|
};
|
|
@@ -806,14 +1173,37 @@ function useLines(room) {
|
|
|
806
1173
|
const chat = room.status === "member" ? book.chat(room.id) : undefined;
|
|
807
1174
|
return React.useSyncExternalStore((listener) => chat?.subscribe(listener) ?? NO_STOP, () => chat?.lines ?? NO_LINES);
|
|
808
1175
|
}
|
|
1176
|
+
function useTaskStates(room) {
|
|
1177
|
+
const member = room.status === "member";
|
|
1178
|
+
return React.useSyncExternalStore((listener) => book.subscribe(listener), () => member ? book.tasks(room.id) : NO_TASKS);
|
|
1179
|
+
}
|
|
1180
|
+
function useAgents(room) {
|
|
1181
|
+
const member = room.status === "member";
|
|
1182
|
+
return React.useSyncExternalStore((listener) => book.subscribe(listener), () => member ? book.agents(room.id) : NO_AGENTS);
|
|
1183
|
+
}
|
|
1184
|
+
function useJoining(room) {
|
|
1185
|
+
return React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.joining(room.id));
|
|
1186
|
+
}
|
|
1187
|
+
var RoomSeenUtil;
|
|
1188
|
+
((RoomSeenUtil) => {
|
|
1189
|
+
function parse(value) {
|
|
1190
|
+
return value && typeof value === "object" ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "number")) : {};
|
|
1191
|
+
}
|
|
1192
|
+
RoomSeenUtil.parse = parse;
|
|
1193
|
+
function merge(a, b) {
|
|
1194
|
+
const later = Object.entries(b).filter(([room, at]) => at > (a[room] ?? 0));
|
|
1195
|
+
return later.length ? { ...a, ...Object.fromEntries(later) } : a;
|
|
1196
|
+
}
|
|
1197
|
+
RoomSeenUtil.merge = merge;
|
|
1198
|
+
})(RoomSeenUtil ||= {});
|
|
809
1199
|
function unseen(room, lines, seen) {
|
|
810
1200
|
const self = room.members.find((member) => member.self)?.member;
|
|
811
1201
|
const since = seen[room.id] ?? room.joinedAt ?? room.createdAt;
|
|
812
1202
|
const last = lines[lines.length - 1];
|
|
813
1203
|
return !!last && last.at > since && last.from !== self;
|
|
814
1204
|
}
|
|
815
|
-
function openRoom(id) {
|
|
816
|
-
book.set({ opened: id });
|
|
1205
|
+
function openRoom(id, direct = false) {
|
|
1206
|
+
book.set({ opened: id, direct });
|
|
817
1207
|
pi.ui.showView(ROOMS_VIEW);
|
|
818
1208
|
}
|
|
819
1209
|
function useOpened() {
|
|
@@ -873,7 +1263,15 @@ function tint(id) {
|
|
|
873
1263
|
function initial(name) {
|
|
874
1264
|
return Array.from(name.trim())[0]?.toUpperCase() ?? "?";
|
|
875
1265
|
}
|
|
876
|
-
function Face({ id, name, size = 34, online }) {
|
|
1266
|
+
function Face({ id, name, size = 34, online, face }) {
|
|
1267
|
+
if (pi.ui.Face) {
|
|
1268
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
1269
|
+
seed: id,
|
|
1270
|
+
face,
|
|
1271
|
+
size,
|
|
1272
|
+
online
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
877
1275
|
const n = tint(id);
|
|
878
1276
|
return /* @__PURE__ */ React.createElement("span", {
|
|
879
1277
|
className: "trm-face",
|
|
@@ -883,29 +1281,27 @@ function Face({ id, name, size = 34, online }) {
|
|
|
883
1281
|
className: online ? "trm-on" : "trm-off"
|
|
884
1282
|
}));
|
|
885
1283
|
}
|
|
886
|
-
function
|
|
1284
|
+
function faceMembers(room, agents = []) {
|
|
1285
|
+
const others = room.members.filter((member) => !member.self).sort((a, b) => Number(b.owner) - Number(a.owner));
|
|
1286
|
+
const all = [...others, ...agents, ...room.members.filter((member) => member.self)];
|
|
1287
|
+
return all.length ? all : [{ id: room.owner ? room.id : room.ownerName || room.id, name: room.ownerName || room.title }];
|
|
1288
|
+
}
|
|
1289
|
+
function RoomFace({ room, size = 40, unread }) {
|
|
887
1290
|
const page = usePageOf(room);
|
|
888
|
-
const members = room.members.length ? room.members.slice(0, 4) : [{ member: room.id, id: room.id, name: room.title }];
|
|
889
1291
|
const Mark = page?.icon;
|
|
890
|
-
const
|
|
1292
|
+
const members = faceMembers(room, useAgents(room));
|
|
891
1293
|
return /* @__PURE__ */ React.createElement("span", {
|
|
892
1294
|
className: "trm-room-face",
|
|
893
|
-
"aria-hidden": "true",
|
|
894
1295
|
style: { width: size, height: size },
|
|
895
|
-
"
|
|
896
|
-
},
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
fontSize: Math.round(cell * 0.5),
|
|
905
|
-
background: `var(--ta-tint-${n})`,
|
|
906
|
-
color: `var(--ta-tint-ink-${n})`
|
|
907
|
-
}
|
|
908
|
-
}, initial(member.name));
|
|
1296
|
+
"aria-hidden": "true"
|
|
1297
|
+
}, pi.ui.GroupFace ? /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
|
|
1298
|
+
members: members.map((member) => ({ seed: member.id, face: member.face })),
|
|
1299
|
+
size
|
|
1300
|
+
}) : /* @__PURE__ */ React.createElement(Face, {
|
|
1301
|
+
id: members[0]?.id ?? room.id,
|
|
1302
|
+
name: members[0]?.name ?? room.title,
|
|
1303
|
+
face: members[0]?.face,
|
|
1304
|
+
size
|
|
909
1305
|
}), Mark && /* @__PURE__ */ React.createElement("span", {
|
|
910
1306
|
className: "trm-room-face-mark"
|
|
911
1307
|
}, /* @__PURE__ */ React.createElement(Mark, {
|
|
@@ -915,110 +1311,1681 @@ function RoomFace({ room, size = 44, unread }) {
|
|
|
915
1311
|
className: "trm-unread"
|
|
916
1312
|
}));
|
|
917
1313
|
}
|
|
1314
|
+
function MemberFaces({ room, onClick, shown }) {
|
|
1315
|
+
const agents = useAgents(room);
|
|
1316
|
+
const members = [
|
|
1317
|
+
...[...room.members].sort((a, b) => Number(b.owner) - Number(a.owner)).map((member) => ({ key: member.member, id: member.id, name: member.name, face: undefined })),
|
|
1318
|
+
...agents.map((agent) => ({ key: `${agent.member}/${agent.id}`, id: agent.id, name: agent.name, face: agent.face }))
|
|
1319
|
+
];
|
|
1320
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
1321
|
+
type: "button",
|
|
1322
|
+
className: `trm-faces${shown ? " trm-on-icon" : ""}`,
|
|
1323
|
+
title: t("members"),
|
|
1324
|
+
"aria-label": t("members"),
|
|
1325
|
+
"aria-pressed": shown,
|
|
1326
|
+
onClick
|
|
1327
|
+
}, members.slice(0, 5).map((member) => /* @__PURE__ */ React.createElement("span", {
|
|
1328
|
+
key: member.key,
|
|
1329
|
+
className: "trm-faces-one"
|
|
1330
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1331
|
+
id: member.id,
|
|
1332
|
+
name: member.name,
|
|
1333
|
+
face: member.face,
|
|
1334
|
+
size: 24
|
|
1335
|
+
}))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
|
|
1336
|
+
className: "trm-faces-more"
|
|
1337
|
+
}, "+", members.length - 5));
|
|
1338
|
+
}
|
|
918
1339
|
|
|
919
|
-
// web-src/
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1340
|
+
// web-src/double-i18n.ts
|
|
1341
|
+
var EN2 = {
|
|
1342
|
+
doubleOf: "{name}'s double",
|
|
1343
|
+
myDouble: "Your double",
|
|
1344
|
+
doubleTag: "Double",
|
|
1345
|
+
mentionLabel: "Ask a double",
|
|
1346
|
+
mentionDetail: "Ask their double",
|
|
1347
|
+
answersHere: "Your double answers here",
|
|
1348
|
+
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.",
|
|
1349
|
+
permissions: "Let the double work for them",
|
|
1350
|
+
grantTitle: "Let your double work for {name}",
|
|
1351
|
+
grantLead: "When {name} asks your double in a room, it may also do this on your computer:",
|
|
1352
|
+
files: "Read and change files",
|
|
1353
|
+
filesHint: "Only inside the directory below.",
|
|
1354
|
+
commands: "Run commands",
|
|
1355
|
+
commandsHint: "In that directory, though a command can reach beyond it: only for someone you trust.",
|
|
1356
|
+
directory: "Directory",
|
|
1357
|
+
pick: "Choose",
|
|
1358
|
+
duration: "For",
|
|
1359
|
+
hours1: "1 hour",
|
|
1360
|
+
hours24: "1 day",
|
|
1361
|
+
hours168: "7 days",
|
|
1362
|
+
allow: "Allow",
|
|
1363
|
+
cancel: "Cancel",
|
|
1364
|
+
refuse: "Refuse",
|
|
1365
|
+
later: "Later",
|
|
1366
|
+
grantNote: "You can take it back at any time, and all your double does for them is logged.",
|
|
1367
|
+
asksTitle: "Your double asks",
|
|
1368
|
+
askLine: "{name} in “{title}”: {reason}",
|
|
1369
|
+
askLead: "{name} asked your double for something in “{title}”:",
|
|
1370
|
+
review: "Review",
|
|
1371
|
+
askWants: "For it, your double needs to {what} on your computer.",
|
|
1372
|
+
wantsFiles: "read and change files",
|
|
1373
|
+
wantsCommands: "run commands",
|
|
1374
|
+
may: "Your double may {what} · {left} left",
|
|
1375
|
+
mayFiles: "files",
|
|
1376
|
+
mayCommands: "commands",
|
|
1377
|
+
left: "{n} h",
|
|
1378
|
+
leftMinutes: "{n} min",
|
|
1379
|
+
leftDays: "{n} d",
|
|
1380
|
+
revoke: "Take back",
|
|
1381
|
+
revokeAll: "Stop all for {name}",
|
|
1382
|
+
revokeAllTitle: "Stop all your double does for {name}?",
|
|
1383
|
+
revokeAllHint: "The permissions and the asks of {name} go, and what your double does for them now stops.",
|
|
1384
|
+
stop: "Stop",
|
|
1385
|
+
logTitle: "What your double did",
|
|
1386
|
+
logEmpty: "Nothing yet",
|
|
1387
|
+
logEmptyHint: "What your double does for others in rooms is listed here",
|
|
1388
|
+
asked: "{name} asked",
|
|
1389
|
+
answered: "Answered",
|
|
1390
|
+
failed: "Failed",
|
|
1391
|
+
limited: "Skipped: too many this hour",
|
|
1392
|
+
tools: "{n} tool calls",
|
|
1393
|
+
clearLog: "Clear",
|
|
1394
|
+
grants: "Permissions",
|
|
1395
|
+
noGrants: "Your double only chats for others",
|
|
1396
|
+
log: "What your double did",
|
|
1397
|
+
noPermission: "Not yet set",
|
|
1398
|
+
oldServer: "Update Ta on the computer to use doubles in rooms.",
|
|
1399
|
+
agentTag: "Agent",
|
|
1400
|
+
myAgent: "Your agent",
|
|
1401
|
+
agentOf: "{name}'s agent",
|
|
1402
|
+
agentsTitle: "Agents",
|
|
1403
|
+
inviteAgent: "Invite an agent",
|
|
1404
|
+
inviteAgentLine: "One of your agents helps in the room",
|
|
1405
|
+
pickAgentTitle: "Invite an agent to “{title}”",
|
|
1406
|
+
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.",
|
|
1407
|
+
noAgents: "No agents yet",
|
|
1408
|
+
noAgentsHint: "Make one in the side bar of your double first.",
|
|
1409
|
+
inRoom: "In the room",
|
|
1410
|
+
joining: "Joining…",
|
|
1411
|
+
joiningRoom: "{name} is joining the room…",
|
|
1412
|
+
inviteFailed: "Could not invite {name}: {error}",
|
|
1413
|
+
dismiss: "Ask to leave",
|
|
1414
|
+
dismissTitle: "Ask {name} to leave “{title}”?",
|
|
1415
|
+
dismissHint: "It says goodbye in the room and answers nothing there any more.",
|
|
1416
|
+
tryAlone: "Invite one of your agents: you can try the room on your own.",
|
|
1417
|
+
agentAsked: "{name} asked {agent}",
|
|
1418
|
+
taskTag: "Task",
|
|
1419
|
+
taskSent: "Handed",
|
|
1420
|
+
taskQueued: "Queued",
|
|
1421
|
+
taskRunning: "Working on it",
|
|
1422
|
+
taskPermission: "Waiting for a permission",
|
|
1423
|
+
taskDone: "Done",
|
|
1424
|
+
taskFailed: "Not done",
|
|
1425
|
+
taskStopped: "Stopped",
|
|
1426
|
+
taskDeclined: "Not taken",
|
|
1427
|
+
taskFor: "For {name}: {text}",
|
|
1428
|
+
taskTo: "{name}'s double: {text}",
|
|
1429
|
+
taskNeedsYou: "Your double asks you to allow it",
|
|
1430
|
+
taskWaitsFor: "Waiting for {name} to allow it",
|
|
1431
|
+
stopTask: "Stop the task",
|
|
1432
|
+
cancelTask: "Call it off",
|
|
1433
|
+
openTaskRoom: "Open the room",
|
|
1434
|
+
forgetTask: "Delete",
|
|
1435
|
+
forgetTaskHint: "Only the entry goes: what was said in the room stays.",
|
|
1436
|
+
taskResult: "A task for {name}'s double",
|
|
1437
|
+
taskLog: "{name} handed a task"
|
|
1438
|
+
};
|
|
1439
|
+
var ZH2 = {
|
|
1440
|
+
doubleOf: "{name}的分身",
|
|
1441
|
+
myDouble: "我的分身",
|
|
1442
|
+
doubleTag: "分身",
|
|
1443
|
+
mentionLabel: "问分身",
|
|
1444
|
+
mentionDetail: "问 TA 的分身",
|
|
1445
|
+
answersHere: "我的分身在这里回答",
|
|
1446
|
+
answersHint: "有人 @ 你的分身时,它会在这个房间里回答。默认只能聊天和读房间里的内容,你允许后才能替某人做更多事。",
|
|
1447
|
+
permissions: "授权分身替 TA 做事",
|
|
1448
|
+
grantTitle: "让分身替{name}做事",
|
|
1449
|
+
grantLead: "{name}在房间里问你的分身时,它还可以在你的电脑上:",
|
|
1450
|
+
files: "读写文件",
|
|
1451
|
+
filesHint: "只限下面这个目录。",
|
|
1452
|
+
commands: "运行命令",
|
|
1453
|
+
commandsHint: "在这个目录里运行,但命令本身能碰到目录之外:只给信任的人。",
|
|
1454
|
+
directory: "目录",
|
|
1455
|
+
pick: "选择",
|
|
1456
|
+
duration: "有效期",
|
|
1457
|
+
hours1: "1 小时",
|
|
1458
|
+
hours24: "1 天",
|
|
1459
|
+
hours168: "7 天",
|
|
1460
|
+
allow: "允许",
|
|
1461
|
+
cancel: "取消",
|
|
1462
|
+
refuse: "拒绝",
|
|
1463
|
+
later: "稍后",
|
|
1464
|
+
grantNote: "可以随时收回;分身替对方做的每件事都有记录。",
|
|
1465
|
+
asksTitle: "分身请你授权",
|
|
1466
|
+
askLine: "{name}在「{title}」里:{reason}",
|
|
1467
|
+
askLead: "{name}在「{title}」里请你的分身帮忙:",
|
|
1468
|
+
review: "处理",
|
|
1469
|
+
askWants: "分身需要在你的电脑上{what}。",
|
|
1470
|
+
wantsFiles: "读写文件",
|
|
1471
|
+
wantsCommands: "运行命令",
|
|
1472
|
+
may: "分身可以{what} · 还剩 {left}",
|
|
1473
|
+
mayFiles: "读写文件",
|
|
1474
|
+
mayCommands: "运行命令",
|
|
1475
|
+
left: "{n} 小时",
|
|
1476
|
+
leftMinutes: "{n} 分钟",
|
|
1477
|
+
leftDays: "{n} 天",
|
|
1478
|
+
revoke: "收回",
|
|
1479
|
+
revokeAll: "停掉{name}的全部授权",
|
|
1480
|
+
revokeAllTitle: "停掉分身为{name}做的一切?",
|
|
1481
|
+
revokeAllHint: "{name}的授权和待处理的请求都会删除,分身正在替 TA 做的事也会停下。",
|
|
1482
|
+
stop: "停掉",
|
|
1483
|
+
logTitle: "分身记录",
|
|
1484
|
+
logEmpty: "还没有记录",
|
|
1485
|
+
logEmptyHint: "分身在房间里替别人做的事会列在这里",
|
|
1486
|
+
asked: "{name}问",
|
|
1487
|
+
answered: "已回答",
|
|
1488
|
+
failed: "失败",
|
|
1489
|
+
limited: "跳过:这一小时回答太多",
|
|
1490
|
+
tools: "用了 {n} 次工具",
|
|
1491
|
+
clearLog: "清空",
|
|
1492
|
+
grants: "授权",
|
|
1493
|
+
noGrants: "分身只替别人聊天",
|
|
1494
|
+
log: "分身记录",
|
|
1495
|
+
noPermission: "还没有授权",
|
|
1496
|
+
oldServer: "请先更新电脑上的 Ta,再在房间里使用分身。",
|
|
1497
|
+
agentTag: "智能体",
|
|
1498
|
+
myAgent: "我的智能体",
|
|
1499
|
+
agentOf: "{name}的智能体",
|
|
1500
|
+
agentsTitle: "智能体",
|
|
1501
|
+
inviteAgent: "邀请智能体",
|
|
1502
|
+
inviteAgentLine: "让你的智能体在房间里帮忙",
|
|
1503
|
+
pickAgentTitle: "邀请智能体进「{title}」",
|
|
1504
|
+
pickAgentLead: "房间里的人 @ 它就能找它帮忙。你自己问它时,它像平常一样在自己的目录里用工具做事;别人问它时,和分身一样只能聊天,除非你授权。",
|
|
1505
|
+
noAgents: "还没有智能体",
|
|
1506
|
+
noAgentsHint: "先在分身侧栏新建一个智能体。",
|
|
1507
|
+
inRoom: "已在房间里",
|
|
1508
|
+
joining: "正在加入…",
|
|
1509
|
+
joiningRoom: "{name}正在加入房间…",
|
|
1510
|
+
inviteFailed: "没能邀请{name}:{error}",
|
|
1511
|
+
dismiss: "请出房间",
|
|
1512
|
+
dismissTitle: "让{name}离开「{title}」?",
|
|
1513
|
+
dismissHint: "它会在房间里道别,之后不再回答这里的问题。",
|
|
1514
|
+
tryAlone: "邀请一个你的智能体进来,一个人也能试试房间。",
|
|
1515
|
+
agentAsked: "{name}问{agent}",
|
|
1516
|
+
taskTag: "任务",
|
|
1517
|
+
taskSent: "已交出",
|
|
1518
|
+
taskQueued: "排队中",
|
|
1519
|
+
taskRunning: "进行中",
|
|
1520
|
+
taskPermission: "等待授权",
|
|
1521
|
+
taskDone: "已完成",
|
|
1522
|
+
taskFailed: "没能完成",
|
|
1523
|
+
taskStopped: "已停止",
|
|
1524
|
+
taskDeclined: "没有接受",
|
|
1525
|
+
taskFor: "替{name}:{text}",
|
|
1526
|
+
taskTo: "交给{name}的分身:{text}",
|
|
1527
|
+
taskNeedsYou: "分身在等你授权",
|
|
1528
|
+
taskWaitsFor: "等{name}授权",
|
|
1529
|
+
stopTask: "停止任务",
|
|
1530
|
+
cancelTask: "取消任务",
|
|
1531
|
+
openTaskRoom: "打开房间",
|
|
1532
|
+
forgetTask: "删除",
|
|
1533
|
+
forgetTaskHint: "只删除这条记录,房间里说过的话还在。",
|
|
1534
|
+
taskResult: "交给{name}的分身的任务",
|
|
1535
|
+
taskLog: "{name}交来任务"
|
|
1536
|
+
};
|
|
1537
|
+
var DoubleWordsUtil;
|
|
1538
|
+
((DoubleWordsUtil) => {
|
|
1539
|
+
function of(language) {
|
|
1540
|
+
return language === "zh-CN" ? ZH2 : EN2;
|
|
924
1541
|
}
|
|
925
|
-
|
|
1542
|
+
DoubleWordsUtil.of = of;
|
|
1543
|
+
})(DoubleWordsUtil ||= {});
|
|
1544
|
+
function dt(key, values = {}) {
|
|
1545
|
+
return DoubleWordsUtil.of(pi.ui.language)[key].replace(/\{(\w+)\}/g, (whole, name) => (name in values) ? String(values[name]) : whole);
|
|
926
1546
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1547
|
+
|
|
1548
|
+
// web-src/doubles-store.ts
|
|
1549
|
+
var KEYS = [DoubleKeys.QUIET, DoubleKeys.GRANTS, DoubleKeys.ASKS, DoubleKeys.LOG, DoubleKeys.TASKS, DoubleKeys.HANDED];
|
|
1550
|
+
|
|
1551
|
+
class DoublesStore {
|
|
1552
|
+
state = { quiet: {}, grants: [], asks: [], log: [], tasks: [], handed: [] };
|
|
1553
|
+
listeners = new Set;
|
|
1554
|
+
started = false;
|
|
1555
|
+
onAsk;
|
|
1556
|
+
get() {
|
|
1557
|
+
return this.state;
|
|
1558
|
+
}
|
|
1559
|
+
subscribe(listener) {
|
|
1560
|
+
this.listeners.add(listener);
|
|
1561
|
+
return () => this.listeners.delete(listener);
|
|
1562
|
+
}
|
|
1563
|
+
start() {
|
|
1564
|
+
if (this.started || !pi.storage) {
|
|
1565
|
+
return () => {
|
|
1566
|
+
return;
|
|
1567
|
+
};
|
|
934
1568
|
}
|
|
935
|
-
|
|
1569
|
+
this.started = true;
|
|
1570
|
+
const stop = pi.storage.onChange((keys) => {
|
|
1571
|
+
const changed = keys.filter((key) => KEYS.includes(key));
|
|
1572
|
+
if (changed.length) {
|
|
1573
|
+
this.read(changed);
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
this.read(KEYS);
|
|
1577
|
+
return () => {
|
|
1578
|
+
stop();
|
|
1579
|
+
this.started = false;
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
async read(keys) {
|
|
1583
|
+
const values = await Promise.all(keys.map((key) => pi.storage.get(key).catch(() => {
|
|
1584
|
+
return;
|
|
1585
|
+
})));
|
|
1586
|
+
const next = { ...this.state };
|
|
1587
|
+
keys.forEach((key, index) => {
|
|
1588
|
+
const value = values[index];
|
|
1589
|
+
if (key === DoubleKeys.QUIET) {
|
|
1590
|
+
next.quiet = value && typeof value === "object" ? value : {};
|
|
1591
|
+
} else if (key === DoubleKeys.GRANTS) {
|
|
1592
|
+
next.grants = Array.isArray(value) ? value : [];
|
|
1593
|
+
} else if (key === DoubleKeys.ASKS) {
|
|
1594
|
+
next.asks = Array.isArray(value) ? value : [];
|
|
1595
|
+
} else if (key === DoubleKeys.LOG) {
|
|
1596
|
+
next.log = Array.isArray(value) ? value : [];
|
|
1597
|
+
} else if (key === DoubleKeys.TASKS) {
|
|
1598
|
+
next.tasks = Array.isArray(value) ? value : [];
|
|
1599
|
+
} else if (key === DoubleKeys.HANDED) {
|
|
1600
|
+
next.handed = Array.isArray(value) ? value : [];
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
const known = new Set(this.state.asks.map((ask) => ask.id));
|
|
1604
|
+
const fresh = keys.includes(DoubleKeys.ASKS) ? next.asks.filter((ask) => !known.has(ask.id)) : [];
|
|
1605
|
+
this.state = next;
|
|
1606
|
+
for (const listener of this.listeners) {
|
|
1607
|
+
listener();
|
|
1608
|
+
}
|
|
1609
|
+
if (fresh.length) {
|
|
1610
|
+
this.onAsk?.(fresh);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
var doubles = new DoublesStore;
|
|
1615
|
+
function useDoubles() {
|
|
1616
|
+
return React.useSyncExternalStore((listener) => doubles.subscribe(listener), () => doubles.get());
|
|
1617
|
+
}
|
|
1618
|
+
async function callDoubles(request) {
|
|
1619
|
+
try {
|
|
1620
|
+
return await pi.callHost("doubles", request);
|
|
1621
|
+
} catch (error) {
|
|
1622
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1623
|
+
throw new Error(/no method|no host/i.test(text) ? dt("oldServer") : text);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
function mentionName(name) {
|
|
1627
|
+
return dt("doubleOf", { name });
|
|
1628
|
+
}
|
|
1629
|
+
function askable(room) {
|
|
1630
|
+
return room.members.filter((member) => !member.self && !member.guest);
|
|
1631
|
+
}
|
|
1632
|
+
function names(text, name) {
|
|
1633
|
+
const quoted = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1634
|
+
return new RegExp(`@${quoted}(?![\\p{L}\\p{N}_])`, "u").test(text);
|
|
1635
|
+
}
|
|
1636
|
+
function addressed(text, room, agents = []) {
|
|
1637
|
+
return [
|
|
1638
|
+
...askable(room).filter((member) => text.includes(`@${mentionName(member.name)}`)).map((member) => member.member),
|
|
1639
|
+
...agents.filter((agent) => names(text, agent.name)).map((agent) => RoomAgentsUtil.address(agent.member, agent.id))
|
|
1640
|
+
];
|
|
1641
|
+
}
|
|
1642
|
+
function grantsOf(grants, friend, now = Date.now()) {
|
|
1643
|
+
return grants.filter((grant) => grant.friend === friend && grant.expiresAt > now);
|
|
1644
|
+
}
|
|
1645
|
+
function left(until, now = Date.now()) {
|
|
1646
|
+
const minutes = Math.max(1, Math.round((until - now) / 60000));
|
|
1647
|
+
if (minutes < 60) {
|
|
1648
|
+
return dt("leftMinutes", { n: minutes });
|
|
1649
|
+
}
|
|
1650
|
+
const hours = Math.round(minutes / 60);
|
|
1651
|
+
return hours < 48 ? dt("left", { n: hours }) : dt("leftDays", { n: Math.round(hours / 24) });
|
|
1652
|
+
}
|
|
1653
|
+
function capabilityName(capability) {
|
|
1654
|
+
return capability === "files" ? dt("mayFiles") : dt("mayCommands");
|
|
1655
|
+
}
|
|
1656
|
+
function mayLine(grants) {
|
|
1657
|
+
if (grants.length === 0) {
|
|
1658
|
+
return "";
|
|
1659
|
+
}
|
|
1660
|
+
const what = [...new Set(grants.map((grant) => grant.capability))].sort().map(capabilityName);
|
|
1661
|
+
return dt("may", { what: what.join(pi.ui.language === "zh-CN" ? "、" : ", "), left: left(Math.min(...grants.map((grant) => grant.expiresAt))) });
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// web-src/agents-view.tsx
|
|
1665
|
+
function agentOwner(room, agent) {
|
|
1666
|
+
const owner = room.members.find((member) => member.member === agent.member);
|
|
1667
|
+
return owner?.self ? dt("myAgent") : dt("agentOf", { name: owner?.name ?? "" });
|
|
1668
|
+
}
|
|
1669
|
+
function agentMentions(room, agents) {
|
|
1670
|
+
return agents.map((agent) => ({ name: agent.name, detail: agentOwner(room, agent) }));
|
|
1671
|
+
}
|
|
1672
|
+
function inviteAgent(room, agent) {
|
|
1673
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
1674
|
+
const joining = { id: agent.id, name: agent.name, ...typeof agent.face === "number" ? { face: agent.face } : {} };
|
|
1675
|
+
const chat = book.chat(room.id);
|
|
1676
|
+
const before = new Set(chat?.lines.map((line) => line.id));
|
|
1677
|
+
book.setJoining(room.id, joining, true);
|
|
1678
|
+
callDoubles({ kind: "invite", room: room.id, agent: agent.id }).then(async (list) => {
|
|
1679
|
+
if (self && Array.isArray(list)) {
|
|
1680
|
+
book.putMine(room.id, self, list);
|
|
1681
|
+
}
|
|
1682
|
+
if (chat) {
|
|
1683
|
+
await saidHello(chat, (line) => !before.has(line.id) && line.agent?.id === agent.id && line.from === self);
|
|
1684
|
+
}
|
|
1685
|
+
}).catch((failure) => pi.ui.notify(dt("inviteFailed", { name: agent.name, error: message(failure) }), "error")).finally(() => book.setJoining(room.id, joining, false));
|
|
1686
|
+
}
|
|
1687
|
+
var HELLO_MS = 1e4;
|
|
1688
|
+
function saidHello(chat, hello) {
|
|
1689
|
+
return new Promise((resolve) => {
|
|
1690
|
+
const check = () => {
|
|
1691
|
+
if (chat.lines.some(hello)) {
|
|
1692
|
+
done();
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
const stop = chat.subscribe(check);
|
|
1696
|
+
const timer = setTimeout(() => done(), HELLO_MS);
|
|
1697
|
+
const done = () => {
|
|
1698
|
+
stop();
|
|
1699
|
+
clearTimeout(timer);
|
|
1700
|
+
resolve();
|
|
1701
|
+
};
|
|
1702
|
+
check();
|
|
936
1703
|
});
|
|
937
|
-
return /* @__PURE__ */ React.createElement("li", {
|
|
938
|
-
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
939
|
-
}, /* @__PURE__ */ React.createElement(Face, {
|
|
940
|
-
id: request.id,
|
|
941
|
-
name: request.name
|
|
942
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
943
|
-
className: "trm-row-text"
|
|
944
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
945
|
-
className: "trm-row-title"
|
|
946
|
-
}, request.name, /* @__PURE__ */ React.createElement("span", {
|
|
947
|
-
className: `trm-tag${request.friend ? " trm-tag-friend" : ""}`
|
|
948
|
-
}, request.guest ? t("guestTag") : request.friend ? t("friendTag") : t("newTag"))), /* @__PURE__ */ React.createElement("span", {
|
|
949
|
-
className: "trm-row-line"
|
|
950
|
-
}, t("requestLine", { title: request.title }))), /* @__PURE__ */ React.createElement("div", {
|
|
951
|
-
className: "trm-answers"
|
|
952
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
953
|
-
type: "button",
|
|
954
|
-
className: "ta-button",
|
|
955
|
-
disabled: busy,
|
|
956
|
-
onClick: () => answer(false)
|
|
957
|
-
}, t("refuse")), /* @__PURE__ */ React.createElement("button", {
|
|
958
|
-
type: "button",
|
|
959
|
-
className: "ta-button ta-primary",
|
|
960
|
-
disabled: busy,
|
|
961
|
-
onClick: () => answer(true)
|
|
962
|
-
}, t("accept"))));
|
|
963
1704
|
}
|
|
964
|
-
function
|
|
965
|
-
const
|
|
966
|
-
const
|
|
1705
|
+
function AgentPicker({ room, close }) {
|
|
1706
|
+
const [agents, setAgents] = React.useState();
|
|
1707
|
+
const [error, setError] = React.useState();
|
|
1708
|
+
const inRoom = useAgents(room);
|
|
1709
|
+
const joining = useJoining(room);
|
|
1710
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
967
1711
|
React.useEffect(() => {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
const
|
|
1712
|
+
callDoubles({ kind: "agents" }).then((list) => setAgents(Array.isArray(list) ? list : []), (failure) => setError(message(failure)));
|
|
1713
|
+
}, []);
|
|
1714
|
+
const invite = (agent) => {
|
|
1715
|
+
inviteAgent(room, agent);
|
|
1716
|
+
close();
|
|
1717
|
+
};
|
|
1718
|
+
const Plus = icon("Plus");
|
|
975
1719
|
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
976
|
-
title:
|
|
1720
|
+
title: dt("pickAgentTitle", { title: room.title }),
|
|
977
1721
|
onClose: close
|
|
978
1722
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
979
1723
|
className: "trm-dialog"
|
|
980
|
-
},
|
|
981
|
-
className: "trm-lead"
|
|
982
|
-
}, requests.length === 1 ? t("requestBody", { name: first.name, title: first.title }) : t("requestsBody", { n: requests.length })), /* @__PURE__ */ React.createElement("ul", {
|
|
983
|
-
className: "trm-rows"
|
|
984
|
-
}, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
|
|
985
|
-
key: `${request.room}:${request.ask}`,
|
|
986
|
-
request
|
|
987
|
-
}))), /* @__PURE__ */ React.createElement("p", {
|
|
1724
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
988
1725
|
className: "trm-note"
|
|
989
|
-
},
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
}, /* @__PURE__ */ React.createElement("
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1726
|
+
}, dt("pickAgentLead")), !agents && !error && pi.ui.Skeleton && /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
1727
|
+
rows: 3
|
|
1728
|
+
}), agents?.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
1729
|
+
title: dt("noAgents"),
|
|
1730
|
+
hint: dt("noAgentsHint"),
|
|
1731
|
+
compact: true
|
|
1732
|
+
}), agents && agents.length > 0 && /* @__PURE__ */ React.createElement("ul", {
|
|
1733
|
+
className: "trm-rows trm-agent-pick"
|
|
1734
|
+
}, agents.map((agent) => {
|
|
1735
|
+
const joined = inRoom.some((each) => each.id === agent.id && each.member === self);
|
|
1736
|
+
const coming = joining.some((each) => each.id === agent.id);
|
|
1737
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1738
|
+
key: agent.id
|
|
1739
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1740
|
+
type: "button",
|
|
1741
|
+
className: "trm-member",
|
|
1742
|
+
disabled: joined || coming,
|
|
1743
|
+
onClick: () => invite(agent)
|
|
1744
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1745
|
+
id: agent.id,
|
|
1746
|
+
name: agent.name,
|
|
1747
|
+
face: agent.face,
|
|
1748
|
+
size: 34
|
|
1749
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1750
|
+
className: "trm-member-text"
|
|
1751
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1752
|
+
className: "trm-member-name trm-ellipsis"
|
|
1753
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
1754
|
+
className: "trm-member-detail trm-ellipsis"
|
|
1755
|
+
}, joined ? dt("inRoom") : coming ? dt("joining") : agent.role)), coming ? /* @__PURE__ */ React.createElement("span", {
|
|
1756
|
+
className: "ta-spinner"
|
|
1757
|
+
}) : !joined && /* @__PURE__ */ React.createElement(Plus, {
|
|
1758
|
+
size: 16
|
|
1759
|
+
})));
|
|
1760
|
+
})), error && /* @__PURE__ */ React.createElement("p", {
|
|
1761
|
+
className: "trm-error"
|
|
1762
|
+
}, error)));
|
|
1000
1763
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}
|
|
1006
|
-
const close = show(({ close: close2 }) => /* @__PURE__ */ React.createElement(RequestsDialog, {
|
|
1007
|
-
close: () => {
|
|
1008
|
-
requestsOpen = undefined;
|
|
1009
|
-
close2();
|
|
1010
|
-
}
|
|
1764
|
+
function openAgentPicker(room) {
|
|
1765
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(AgentPicker, {
|
|
1766
|
+
room,
|
|
1767
|
+
close
|
|
1011
1768
|
}));
|
|
1012
|
-
requestsOpen = close;
|
|
1013
1769
|
}
|
|
1014
|
-
function
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1770
|
+
function JoiningRow({ agent }) {
|
|
1771
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1772
|
+
className: "trm-member",
|
|
1773
|
+
"aria-busy": "true"
|
|
1774
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1775
|
+
id: agent.id,
|
|
1776
|
+
name: agent.name,
|
|
1777
|
+
face: agent.face,
|
|
1778
|
+
size: 34
|
|
1779
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1780
|
+
className: "trm-member-text"
|
|
1781
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1782
|
+
className: "trm-member-name trm-ellipsis"
|
|
1783
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
1784
|
+
className: "trm-member-detail trm-ellipsis"
|
|
1785
|
+
}, dt("joining"))), /* @__PURE__ */ React.createElement("span", {
|
|
1786
|
+
className: "ta-spinner trm-member-action"
|
|
1787
|
+
}));
|
|
1788
|
+
}
|
|
1789
|
+
function AgentRow({ room, agent }) {
|
|
1790
|
+
const Remove = icon("X");
|
|
1791
|
+
const mine = room.members.find((member) => member.self)?.member === agent.member;
|
|
1792
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1793
|
+
className: "trm-member"
|
|
1794
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1795
|
+
id: agent.id,
|
|
1796
|
+
name: agent.name,
|
|
1797
|
+
face: agent.face,
|
|
1798
|
+
size: 34
|
|
1799
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1800
|
+
className: "trm-member-text"
|
|
1801
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1802
|
+
className: "trm-member-name"
|
|
1803
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1804
|
+
className: "trm-ellipsis"
|
|
1805
|
+
}, agent.name), /* @__PURE__ */ React.createElement("span", {
|
|
1806
|
+
className: "trm-tag trm-tag-agent"
|
|
1807
|
+
}, agentOwner(room, agent))), agent.role && /* @__PURE__ */ React.createElement("span", {
|
|
1808
|
+
className: "trm-member-detail trm-ellipsis"
|
|
1809
|
+
}, agent.role)), mine && /* @__PURE__ */ React.createElement("button", {
|
|
1810
|
+
type: "button",
|
|
1811
|
+
className: "trm-icon trm-danger trm-member-action",
|
|
1812
|
+
title: dt("dismiss"),
|
|
1813
|
+
"aria-label": dt("dismiss"),
|
|
1814
|
+
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))
|
|
1815
|
+
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
1816
|
+
size: 15
|
|
1817
|
+
})));
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
// web-src/doubles-view.tsx
|
|
1821
|
+
var DOUBLES_VIEW = "@celljs/ta-rooms/doubles";
|
|
1822
|
+
function useBusy() {
|
|
1823
|
+
const fallback = React.useState(false);
|
|
1824
|
+
const busy = pi.ui.useBusy?.();
|
|
1825
|
+
if (busy) {
|
|
1826
|
+
return busy;
|
|
1827
|
+
}
|
|
1828
|
+
const [on, set] = fallback;
|
|
1829
|
+
return [
|
|
1830
|
+
on,
|
|
1831
|
+
async (action) => {
|
|
1832
|
+
set(true);
|
|
1833
|
+
try {
|
|
1834
|
+
await action();
|
|
1835
|
+
} finally {
|
|
1836
|
+
set(false);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
];
|
|
1840
|
+
}
|
|
1841
|
+
function hoursLabel(hours) {
|
|
1842
|
+
return hours === 1 ? dt("hours1") : hours === 24 ? dt("hours24") : dt("hours168");
|
|
1843
|
+
}
|
|
1844
|
+
function GrantDialog({ friend, name, ask, close }) {
|
|
1845
|
+
const cwd = pi.ui.useCwd();
|
|
1846
|
+
const [directory, setDirectory] = React.useState(cwd);
|
|
1847
|
+
const [picking, setPicking] = React.useState(false);
|
|
1848
|
+
const [hours, setHours] = React.useState(1);
|
|
1849
|
+
const [chosen, setChosen] = React.useState(ask ? [ask.capability] : ["files"]);
|
|
1850
|
+
const [error, setError] = React.useState();
|
|
1851
|
+
const [busy, run] = useBusy();
|
|
1852
|
+
const Folder = icon("Folder");
|
|
1853
|
+
const answer = (accept) => void run(async () => {
|
|
1854
|
+
setError(undefined);
|
|
1855
|
+
try {
|
|
1856
|
+
if (ask) {
|
|
1857
|
+
await callDoubles({ kind: "answer", ask: ask.id, accept, cwd: directory, hours });
|
|
1858
|
+
} else if (accept) {
|
|
1859
|
+
await callDoubles({ kind: "grant", friend, name, capabilities: chosen, cwd: directory, hours });
|
|
1860
|
+
}
|
|
1861
|
+
close();
|
|
1862
|
+
} catch (failure) {
|
|
1863
|
+
setError(message(failure));
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
const toggle = (capability, on) => setChosen((list) => on ? [...new Set([...list, capability])] : list.filter((each) => each !== capability));
|
|
1867
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
1868
|
+
title: ask ? dt("asksTitle") : dt("grantTitle", { name }),
|
|
1869
|
+
onClose: close
|
|
1870
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1871
|
+
className: "trm-dialog"
|
|
1872
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1873
|
+
className: "trm-grant-who"
|
|
1874
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1875
|
+
id: friend,
|
|
1876
|
+
name,
|
|
1877
|
+
size: 36
|
|
1878
|
+
}), /* @__PURE__ */ React.createElement("p", {
|
|
1879
|
+
className: "trm-lead"
|
|
1880
|
+
}, ask ? dt("askLead", { name, title: ask.title }) : dt("grantLead", { name }))), ask && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("blockquote", {
|
|
1881
|
+
className: "trm-grant-reason"
|
|
1882
|
+
}, ask.reason), /* @__PURE__ */ React.createElement("p", {
|
|
1883
|
+
className: "trm-lead"
|
|
1884
|
+
}, dt("askWants", { name, what: ask.capability === "files" ? dt("wantsFiles") : dt("wantsCommands") }))), !ask && /* @__PURE__ */ React.createElement("ul", {
|
|
1885
|
+
className: "trm-grant-list"
|
|
1886
|
+
}, ROOM_CAPABILITIES.map((capability) => /* @__PURE__ */ React.createElement("li", {
|
|
1887
|
+
key: capability,
|
|
1888
|
+
className: "trm-grant-item"
|
|
1889
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1890
|
+
className: "trm-grant-text"
|
|
1891
|
+
}, /* @__PURE__ */ React.createElement("span", null, capability === "files" ? dt("files") : dt("commands")), /* @__PURE__ */ React.createElement("span", {
|
|
1892
|
+
className: "trm-note"
|
|
1893
|
+
}, capability === "files" ? dt("filesHint") : dt("commandsHint"))), /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
1894
|
+
checked: chosen.includes(capability),
|
|
1895
|
+
label: capability === "files" ? dt("files") : dt("commands"),
|
|
1896
|
+
onChange: (on) => toggle(capability, on)
|
|
1897
|
+
})))), ask?.capability === "commands" && /* @__PURE__ */ React.createElement("p", {
|
|
1898
|
+
className: "trm-note"
|
|
1899
|
+
}, dt("commandsHint")), /* @__PURE__ */ React.createElement("div", {
|
|
1900
|
+
className: "trm-grant-field"
|
|
1901
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1902
|
+
className: "trm-grant-label"
|
|
1903
|
+
}, dt("directory")), /* @__PURE__ */ React.createElement("button", {
|
|
1904
|
+
type: "button",
|
|
1905
|
+
className: "trm-grant-dir",
|
|
1906
|
+
onClick: () => setPicking(true),
|
|
1907
|
+
title: directory
|
|
1908
|
+
}, /* @__PURE__ */ React.createElement(Folder, {
|
|
1909
|
+
size: 15
|
|
1910
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
1911
|
+
className: "trm-ellipsis"
|
|
1912
|
+
}, directory || dt("pick")))), /* @__PURE__ */ React.createElement("div", {
|
|
1913
|
+
className: "trm-grant-field"
|
|
1914
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1915
|
+
className: "trm-grant-label"
|
|
1916
|
+
}, dt("duration")), /* @__PURE__ */ React.createElement("span", {
|
|
1917
|
+
className: "trm-chips"
|
|
1918
|
+
}, GRANT_HOURS.map((each) => /* @__PURE__ */ React.createElement("button", {
|
|
1919
|
+
key: each,
|
|
1920
|
+
type: "button",
|
|
1921
|
+
"aria-pressed": hours === each,
|
|
1922
|
+
className: `trm-chip${hours === each ? " trm-chip-on" : ""}`,
|
|
1923
|
+
onClick: () => setHours(each)
|
|
1924
|
+
}, hoursLabel(each))))), /* @__PURE__ */ React.createElement("p", {
|
|
1925
|
+
className: "trm-note"
|
|
1926
|
+
}, dt("grantNote")), error && /* @__PURE__ */ React.createElement("p", {
|
|
1927
|
+
className: "trm-error"
|
|
1928
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
1929
|
+
className: "trm-actions"
|
|
1930
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1931
|
+
type: "button",
|
|
1932
|
+
className: "ta-button",
|
|
1933
|
+
disabled: busy,
|
|
1934
|
+
onClick: () => ask ? answer(false) : close()
|
|
1935
|
+
}, ask ? dt("refuse") : dt("cancel")), ask && /* @__PURE__ */ React.createElement("button", {
|
|
1936
|
+
type: "button",
|
|
1937
|
+
className: "ta-button",
|
|
1938
|
+
disabled: busy,
|
|
1939
|
+
onClick: close
|
|
1940
|
+
}, dt("later")), /* @__PURE__ */ React.createElement("button", {
|
|
1941
|
+
type: "button",
|
|
1942
|
+
className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
|
|
1943
|
+
disabled: busy || !directory || chosen.length === 0,
|
|
1944
|
+
onClick: () => answer(true)
|
|
1945
|
+
}, dt("allow")))), picking && pi.ui.FolderPicker && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
1946
|
+
initial: directory,
|
|
1947
|
+
onPick: (path) => {
|
|
1948
|
+
setDirectory(path);
|
|
1949
|
+
setPicking(false);
|
|
1950
|
+
},
|
|
1951
|
+
onClose: () => setPicking(false)
|
|
1952
|
+
}));
|
|
1953
|
+
}
|
|
1954
|
+
function openGrant(member) {
|
|
1955
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(GrantDialog, {
|
|
1956
|
+
friend: member.id,
|
|
1957
|
+
name: member.name,
|
|
1958
|
+
close
|
|
1959
|
+
}));
|
|
1960
|
+
}
|
|
1961
|
+
var asking;
|
|
1962
|
+
function openAsk(ask) {
|
|
1963
|
+
if (asking) {
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
asking = ask.id;
|
|
1967
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(GrantDialog, {
|
|
1968
|
+
friend: ask.friend,
|
|
1969
|
+
name: ask.name,
|
|
1970
|
+
ask,
|
|
1971
|
+
close: () => {
|
|
1972
|
+
asking = undefined;
|
|
1973
|
+
close();
|
|
1974
|
+
}
|
|
1975
|
+
}));
|
|
1976
|
+
}
|
|
1977
|
+
function AskRow({ ask }) {
|
|
1978
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
1979
|
+
className: "trm-row"
|
|
1980
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1981
|
+
id: ask.friend,
|
|
1982
|
+
name: ask.name
|
|
1983
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
1984
|
+
className: "trm-row-text"
|
|
1985
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1986
|
+
className: "trm-row-title"
|
|
1987
|
+
}, ask.name, /* @__PURE__ */ React.createElement("span", {
|
|
1988
|
+
className: "trm-tag"
|
|
1989
|
+
}, capabilityName(ask.capability))), /* @__PURE__ */ React.createElement("span", {
|
|
1990
|
+
className: "trm-row-line"
|
|
1991
|
+
}, dt("askLine", { name: ask.name, title: ask.title, reason: ask.reason }))), /* @__PURE__ */ React.createElement("div", {
|
|
1992
|
+
className: "trm-answers"
|
|
1993
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1994
|
+
type: "button",
|
|
1995
|
+
className: "ta-button ta-primary",
|
|
1996
|
+
onClick: () => openAsk(ask)
|
|
1997
|
+
}, dt("review"))));
|
|
1998
|
+
}
|
|
1999
|
+
function DoubleSwitch({ room }) {
|
|
2000
|
+
const { quiet } = useDoubles();
|
|
2001
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2002
|
+
className: "trm-double-switch"
|
|
2003
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2004
|
+
className: "trm-grant-text"
|
|
2005
|
+
}, /* @__PURE__ */ React.createElement("span", null, dt("answersHere")), /* @__PURE__ */ React.createElement("span", {
|
|
2006
|
+
className: "trm-note"
|
|
2007
|
+
}, dt("answersHint"))), /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
2008
|
+
checked: !quiet[room.id],
|
|
2009
|
+
label: dt("answersHere"),
|
|
2010
|
+
onChange: (on) => callDoubles({ kind: "quiet", room: room.id, quiet: !on }).catch((error) => pi.ui.notify(message(error), "error"))
|
|
2011
|
+
}));
|
|
2012
|
+
}
|
|
2013
|
+
function useMayLine(member) {
|
|
2014
|
+
const { grants } = useDoubles();
|
|
2015
|
+
return member.self || member.guest ? "" : mayLine(grantsOf(grants, member.id));
|
|
2016
|
+
}
|
|
2017
|
+
async function revokeAll(friend, name) {
|
|
2018
|
+
if (await pi.ui.confirm(dt("revokeAllTitle", { name }), dt("revokeAllHint", { name }), { confirmLabel: dt("stop"), danger: true })) {
|
|
2019
|
+
await callDoubles({ kind: "revokeAll", friend }).catch((error) => pi.ui.notify(message(error), "error"));
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
function GrantRow({ grant }) {
|
|
2023
|
+
const [busy, run] = useBusy();
|
|
2024
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2025
|
+
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
2026
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2027
|
+
id: grant.friend,
|
|
2028
|
+
name: grant.name,
|
|
2029
|
+
size: 30
|
|
2030
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2031
|
+
className: "trm-row-text"
|
|
2032
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2033
|
+
className: "trm-row-title"
|
|
2034
|
+
}, grant.name, /* @__PURE__ */ React.createElement("span", {
|
|
2035
|
+
className: "trm-tag"
|
|
2036
|
+
}, capabilityName(grant.capability))), /* @__PURE__ */ React.createElement("span", {
|
|
2037
|
+
className: "trm-row-line trm-ellipsis",
|
|
2038
|
+
title: grant.cwd
|
|
2039
|
+
}, grant.cwd, " · ", left(grant.expiresAt))), /* @__PURE__ */ React.createElement("button", {
|
|
2040
|
+
type: "button",
|
|
2041
|
+
className: "ta-button",
|
|
2042
|
+
disabled: busy,
|
|
2043
|
+
onClick: () => void run(() => callDoubles({ kind: "revoke", grant: grant.id }).catch((error) => pi.ui.notify(message(error), "error")))
|
|
2044
|
+
}, dt("revoke")));
|
|
2045
|
+
}
|
|
2046
|
+
function LogRow({ entry }) {
|
|
2047
|
+
const outcome = entry.outcome === "answered" ? dt("answered") : entry.outcome === "failed" ? dt("failed") : dt("limited");
|
|
2048
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2049
|
+
className: "trm-log"
|
|
2050
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2051
|
+
className: "trm-log-head"
|
|
2052
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2053
|
+
id: entry.friend,
|
|
2054
|
+
name: entry.name,
|
|
2055
|
+
size: 22
|
|
2056
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2057
|
+
className: "trm-log-who trm-ellipsis"
|
|
2058
|
+
}, entry.agent ? dt("agentAsked", { name: entry.name, agent: entry.agent }) : entry.task ? dt("taskLog", { name: entry.name }) : dt("asked", { name: entry.name }), " ", "· ", entry.title), /* @__PURE__ */ React.createElement("span", {
|
|
2059
|
+
className: "trm-log-time"
|
|
2060
|
+
}, when(entry.at))), /* @__PURE__ */ React.createElement("div", {
|
|
2061
|
+
className: "trm-log-asked"
|
|
2062
|
+
}, entry.asked), entry.answer && /* @__PURE__ */ React.createElement("div", {
|
|
2063
|
+
className: "trm-log-answer"
|
|
2064
|
+
}, entry.answer), /* @__PURE__ */ React.createElement("div", {
|
|
2065
|
+
className: `trm-log-meta${entry.outcome === "answered" ? "" : " trm-log-bad"}`
|
|
2066
|
+
}, [
|
|
2067
|
+
outcome,
|
|
2068
|
+
...entry.capabilities.length ? [entry.capabilities.map(capabilityName).join(" · ")] : [],
|
|
2069
|
+
...entry.tools.length ? [dt("tools", { n: entry.tools.length })] : [],
|
|
2070
|
+
...entry.error ? [entry.error] : []
|
|
2071
|
+
].join(" · ")));
|
|
2072
|
+
}
|
|
2073
|
+
function DoublesView() {
|
|
2074
|
+
const { grants, asks, log } = useDoubles();
|
|
2075
|
+
const now = Date.now();
|
|
2076
|
+
const live = grants.filter((grant) => grant.expiresAt > now);
|
|
2077
|
+
const friends = [...new Map(live.map((grant) => [grant.friend, grant.name])).entries()];
|
|
2078
|
+
const recent = [...log].reverse();
|
|
2079
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2080
|
+
className: "trm-panel"
|
|
2081
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2082
|
+
className: "trm-panel-scroll"
|
|
2083
|
+
}, asks.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
2084
|
+
className: "trm-panel-label"
|
|
2085
|
+
}, dt("asksTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
2086
|
+
className: "trm-rows"
|
|
2087
|
+
}, asks.map((ask) => /* @__PURE__ */ React.createElement(AskRow, {
|
|
2088
|
+
key: ask.id,
|
|
2089
|
+
ask
|
|
2090
|
+
})))), /* @__PURE__ */ React.createElement("div", {
|
|
2091
|
+
className: "trm-panel-label"
|
|
2092
|
+
}, dt("grants")), live.length === 0 ? /* @__PURE__ */ React.createElement("p", {
|
|
2093
|
+
className: "trm-note trm-panel-note"
|
|
2094
|
+
}, dt("noGrants")) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("ul", {
|
|
2095
|
+
className: "trm-rows"
|
|
2096
|
+
}, live.map((grant) => /* @__PURE__ */ React.createElement(GrantRow, {
|
|
2097
|
+
key: grant.id,
|
|
2098
|
+
grant
|
|
2099
|
+
}))), friends.map(([friend, name]) => /* @__PURE__ */ React.createElement("button", {
|
|
2100
|
+
key: friend,
|
|
2101
|
+
type: "button",
|
|
2102
|
+
className: "trm-link trm-danger trm-panel-note",
|
|
2103
|
+
onClick: () => void revokeAll(friend, name)
|
|
2104
|
+
}, dt("revokeAll", { name })))), /* @__PURE__ */ React.createElement("div", {
|
|
2105
|
+
className: "trm-panel-label trm-log-label"
|
|
2106
|
+
}, /* @__PURE__ */ React.createElement("span", null, dt("logTitle")), recent.length > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
2107
|
+
type: "button",
|
|
2108
|
+
className: "trm-link",
|
|
2109
|
+
onClick: () => void callDoubles({ kind: "clearLog" }).catch((error) => pi.ui.notify(message(error), "error"))
|
|
2110
|
+
}, dt("clearLog"))), recent.length === 0 ? /* @__PURE__ */ React.createElement("div", {
|
|
2111
|
+
className: "trm-log-empty"
|
|
2112
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2113
|
+
title: dt("logEmpty"),
|
|
2114
|
+
hint: dt("logEmptyHint"),
|
|
2115
|
+
compact: true
|
|
2116
|
+
})) : /* @__PURE__ */ React.createElement("ul", {
|
|
2117
|
+
className: "trm-logs"
|
|
2118
|
+
}, recent.map((entry) => /* @__PURE__ */ React.createElement(LogRow, {
|
|
2119
|
+
key: entry.id,
|
|
2120
|
+
entry
|
|
2121
|
+
})))));
|
|
2122
|
+
}
|
|
2123
|
+
function listenAsks() {
|
|
2124
|
+
doubles.onAsk = (asks) => {
|
|
2125
|
+
const latest = asks[asks.length - 1];
|
|
2126
|
+
if (latest) {
|
|
2127
|
+
openAsk(latest);
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
const stop = doubles.start();
|
|
2131
|
+
return () => {
|
|
2132
|
+
doubles.onAsk = undefined;
|
|
2133
|
+
stop();
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
// web-src/tasks-view.tsx
|
|
2138
|
+
function taskStatusWord(status) {
|
|
2139
|
+
switch (status) {
|
|
2140
|
+
case "sent":
|
|
2141
|
+
return dt("taskSent");
|
|
2142
|
+
case "queued":
|
|
2143
|
+
return dt("taskQueued");
|
|
2144
|
+
case "running":
|
|
2145
|
+
return dt("taskRunning");
|
|
2146
|
+
case "permission":
|
|
2147
|
+
return dt("taskPermission");
|
|
2148
|
+
case "done":
|
|
2149
|
+
return dt("taskDone");
|
|
2150
|
+
case "failed":
|
|
2151
|
+
return dt("taskFailed");
|
|
2152
|
+
case "stopped":
|
|
2153
|
+
return dt("taskStopped");
|
|
2154
|
+
default:
|
|
2155
|
+
return dt("taskDeclined");
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
function oneLine(text) {
|
|
2159
|
+
const lines = text.split(`
|
|
2160
|
+
`).map((line) => line.trim());
|
|
2161
|
+
const first = lines.find((line) => line && !line.startsWith("|") && !line.startsWith("```")) ?? lines.find(Boolean) ?? "";
|
|
2162
|
+
return first.replace(/^#+\s*|^[-*]\s+|\*\*|__|`/g, "").trim();
|
|
2163
|
+
}
|
|
2164
|
+
function listed(status, mine) {
|
|
2165
|
+
if (!RoomTasksUtil.ended(status)) {
|
|
2166
|
+
return mine && status === "permission" ? "waiting" : "running";
|
|
2167
|
+
}
|
|
2168
|
+
return status === "done" ? "done" : status === "stopped" ? "stopped" : "failed";
|
|
2169
|
+
}
|
|
2170
|
+
function act(run) {
|
|
2171
|
+
return () => void run().catch((error) => pi.ui.notify(message(error), "error"));
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
class RoomTaskSource {
|
|
2175
|
+
list = [];
|
|
2176
|
+
shown = new Map;
|
|
2177
|
+
listeners = new Set;
|
|
2178
|
+
stop;
|
|
2179
|
+
tasks() {
|
|
2180
|
+
return this.list;
|
|
2181
|
+
}
|
|
2182
|
+
subscribe(listener) {
|
|
2183
|
+
if (this.listeners.size === 0) {
|
|
2184
|
+
const unsubscribe = doubles.subscribe(() => this.build(doubles.get()));
|
|
2185
|
+
const stopStore = doubles.start();
|
|
2186
|
+
this.stop = () => {
|
|
2187
|
+
unsubscribe();
|
|
2188
|
+
stopStore();
|
|
2189
|
+
};
|
|
2190
|
+
this.build(doubles.get());
|
|
2191
|
+
}
|
|
2192
|
+
this.listeners.add(listener);
|
|
2193
|
+
return () => {
|
|
2194
|
+
this.listeners.delete(listener);
|
|
2195
|
+
if (this.listeners.size === 0) {
|
|
2196
|
+
this.stop?.();
|
|
2197
|
+
this.stop = undefined;
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
build(state) {
|
|
2202
|
+
const next = [
|
|
2203
|
+
...state.tasks.map((task) => this.reuse(`for:${task.id}`, task, () => this.forTask(task, state))),
|
|
2204
|
+
...state.handed.map((task) => this.reuse(`to:${task.id}`, task, () => this.toTask(task)))
|
|
2205
|
+
];
|
|
2206
|
+
if (next.length === this.list.length && next.every((entry, index) => entry === this.list[index])) {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
const ids = new Set(next.map((entry) => entry.id));
|
|
2210
|
+
for (const id of [...this.shown.keys()]) {
|
|
2211
|
+
if (!ids.has(id)) {
|
|
2212
|
+
this.shown.delete(id);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
this.list = next;
|
|
2216
|
+
for (const listener of this.listeners) {
|
|
2217
|
+
listener();
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
reuse(id, task, make) {
|
|
2221
|
+
const signature = `${pi.ui.language}:${JSON.stringify(task)}`;
|
|
2222
|
+
const before = this.shown.get(id);
|
|
2223
|
+
if (before?.signature === signature) {
|
|
2224
|
+
return before.entry;
|
|
2225
|
+
}
|
|
2226
|
+
const entry = make();
|
|
2227
|
+
this.shown.set(id, { signature, entry });
|
|
2228
|
+
return entry;
|
|
2229
|
+
}
|
|
2230
|
+
forTask(task, state) {
|
|
2231
|
+
const open = !RoomTasksUtil.ended(task.status);
|
|
2232
|
+
const remove = async () => {
|
|
2233
|
+
if (open) {
|
|
2234
|
+
await callDoubles({ kind: "stopTask", task: task.id });
|
|
2235
|
+
}
|
|
2236
|
+
await callDoubles({ kind: "forgetTask", task: task.id });
|
|
2237
|
+
};
|
|
2238
|
+
return {
|
|
2239
|
+
id: `for:${task.id}`,
|
|
2240
|
+
title: dt("taskFor", { name: task.name, text: task.text }),
|
|
2241
|
+
status: listed(task.status, true),
|
|
2242
|
+
detail: task.status === "permission" ? dt("taskNeedsYou") : open ? taskStatusWord(task.status) : oneLine(task.answer ?? task.detail ?? taskStatusWord(task.status)),
|
|
2243
|
+
startedAt: task.at,
|
|
2244
|
+
...task.endedAt && !open ? { endedAt: task.endedAt } : {},
|
|
2245
|
+
icon: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
2246
|
+
id: task.friend,
|
|
2247
|
+
name: task.name,
|
|
2248
|
+
size
|
|
2249
|
+
}),
|
|
2250
|
+
open: () => {
|
|
2251
|
+
const ask = state.asks.find((each) => each.friend === task.friend);
|
|
2252
|
+
if (task.status === "permission" && ask) {
|
|
2253
|
+
openAsk(ask);
|
|
2254
|
+
} else {
|
|
2255
|
+
openRoom(task.room, true);
|
|
2256
|
+
}
|
|
2257
|
+
},
|
|
2258
|
+
menu: () => this.menu(task.room, open ? { label: dt("stopTask"), run: () => callDoubles({ kind: "stopTask", task: task.id }) } : undefined, remove),
|
|
2259
|
+
remove,
|
|
2260
|
+
removeHint: dt("forgetTaskHint")
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
toTask(task) {
|
|
2264
|
+
const open = !RoomTasksUtil.ended(task.status);
|
|
2265
|
+
const remove = async () => {
|
|
2266
|
+
if (open) {
|
|
2267
|
+
await callDoubles({ kind: "stopTask", task: task.id, handed: true });
|
|
2268
|
+
}
|
|
2269
|
+
await callDoubles({ kind: "forgetTask", task: task.id, handed: true });
|
|
2270
|
+
};
|
|
2271
|
+
return {
|
|
2272
|
+
id: `to:${task.id}`,
|
|
2273
|
+
title: dt("taskTo", { name: task.toName, text: task.text }),
|
|
2274
|
+
status: listed(task.status, false),
|
|
2275
|
+
detail: task.status === "permission" ? dt("taskWaitsFor", { name: task.toName }) : open ? taskStatusWord(task.status) : oneLine(task.answer ?? task.detail ?? taskStatusWord(task.status)),
|
|
2276
|
+
startedAt: task.at,
|
|
2277
|
+
...task.endedAt && !open ? { endedAt: task.endedAt } : {},
|
|
2278
|
+
...task.origin ? { origin: task.origin } : {},
|
|
2279
|
+
icon: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
2280
|
+
id: task.friend,
|
|
2281
|
+
name: task.toName,
|
|
2282
|
+
size
|
|
2283
|
+
}),
|
|
2284
|
+
open: () => openRoom(task.room, true),
|
|
2285
|
+
menu: () => this.menu(task.room, open ? { label: dt("cancelTask"), run: () => callDoubles({ kind: "stopTask", task: task.id, handed: true }) } : undefined, remove),
|
|
2286
|
+
remove,
|
|
2287
|
+
removeHint: dt("forgetTaskHint")
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
menu(room, stop, remove) {
|
|
2291
|
+
return [
|
|
2292
|
+
stop ? [{ key: "stop", label: stop.label, icon: icon("Square"), run: act(stop.run) }] : [],
|
|
2293
|
+
[{ key: "room", label: dt("openTaskRoom"), icon: icon("Users"), run: () => openRoom(room, true) }],
|
|
2294
|
+
[
|
|
2295
|
+
{
|
|
2296
|
+
key: "delete",
|
|
2297
|
+
label: dt("forgetTask"),
|
|
2298
|
+
icon: icon("Trash2"),
|
|
2299
|
+
danger: true,
|
|
2300
|
+
run: act(() => pi.ui.removeTasks([{ title: dt("forgetTask"), remove, removeHint: dt("forgetTaskHint") }]))
|
|
2301
|
+
}
|
|
2302
|
+
]
|
|
2303
|
+
];
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
function TaskMessage({ message: shown }) {
|
|
2307
|
+
const task = shown.details;
|
|
2308
|
+
if (!task || typeof task.id !== "string") {
|
|
2309
|
+
return null;
|
|
2310
|
+
}
|
|
2311
|
+
const Open = icon("ChevronRight");
|
|
2312
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2313
|
+
className: `trm-task-card trm-task-${task.status}`
|
|
2314
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2315
|
+
type: "button",
|
|
2316
|
+
className: "trm-task-card-head",
|
|
2317
|
+
onClick: () => openRoom(task.room, true)
|
|
2318
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2319
|
+
id: task.friend,
|
|
2320
|
+
name: task.toName,
|
|
2321
|
+
size: 22
|
|
2322
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2323
|
+
className: "trm-task-card-title trm-ellipsis"
|
|
2324
|
+
}, dt("taskResult", { name: task.toName })), /* @__PURE__ */ React.createElement("span", {
|
|
2325
|
+
className: "trm-task-chip"
|
|
2326
|
+
}, taskStatusWord(task.status)), /* @__PURE__ */ React.createElement(Open, {
|
|
2327
|
+
size: 14
|
|
2328
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
2329
|
+
className: "trm-task-card-text"
|
|
2330
|
+
}, task.text), task.answer ? /* @__PURE__ */ React.createElement("div", {
|
|
2331
|
+
className: "trm-task-card-answer"
|
|
2332
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
2333
|
+
text: task.answer
|
|
2334
|
+
})) : task.detail && /* @__PURE__ */ React.createElement("div", {
|
|
2335
|
+
className: "trm-task-card-answer trm-quiet"
|
|
2336
|
+
}, task.detail));
|
|
2337
|
+
}
|
|
2338
|
+
function TaskLine({ statuses }) {
|
|
2339
|
+
const status = statuses[0] ?? "sent";
|
|
2340
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2341
|
+
className: `trm-task-line trm-task-${status}`
|
|
2342
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2343
|
+
className: "trm-task-dot"
|
|
2344
|
+
}), taskStatusWord(status));
|
|
2345
|
+
}
|
|
2346
|
+
function registerTasks() {
|
|
2347
|
+
pi.registerTasks?.(new RoomTaskSource);
|
|
2348
|
+
pi.registerMessageRenderer?.(TASK_MESSAGE_TYPE, TaskMessage);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
// web-src/room-view.tsx
|
|
2352
|
+
var RUN_MS = 5 * 60 * 1000;
|
|
2353
|
+
var PAUSE_MS = 15 * 60 * 1000;
|
|
2354
|
+
async function confirmThen(title, hint, label, action) {
|
|
2355
|
+
if (!await pi.ui.confirm(title, hint, { confirmLabel: label, danger: true })) {
|
|
2356
|
+
return false;
|
|
2357
|
+
}
|
|
2358
|
+
try {
|
|
2359
|
+
await action();
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
pi.ui.notify(message(error), "error");
|
|
2362
|
+
}
|
|
2363
|
+
await book.load();
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
function leaveRoom(room) {
|
|
2367
|
+
if (room.status !== "member") {
|
|
2368
|
+
return (rooms()?.leave(room.id) ?? Promise.resolve()).then(() => book.load()).then(() => true);
|
|
2369
|
+
}
|
|
2370
|
+
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));
|
|
2371
|
+
}
|
|
2372
|
+
function speaker(line) {
|
|
2373
|
+
return `${line.from}:${line.double ? "d" : ""}:${line.agent?.id ?? ""}`;
|
|
2374
|
+
}
|
|
2375
|
+
function time(at) {
|
|
2376
|
+
const date = new Date(at);
|
|
2377
|
+
const clock = date.toLocaleTimeString(pi.ui.language, { hour: "2-digit", minute: "2-digit" });
|
|
2378
|
+
return date.toDateString() === new Date().toDateString() ? clock : `${date.toLocaleDateString(pi.ui.language, { month: "numeric", day: "numeric" })} ${clock}`;
|
|
2379
|
+
}
|
|
2380
|
+
function RoomHead({ room }) {
|
|
2381
|
+
const shown = !!pi.ui.useView?.(MEMBERS_VIEW)?.shown;
|
|
2382
|
+
const page = usePageOf(room);
|
|
2383
|
+
const online = room.members.filter((member) => member.online).length;
|
|
2384
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2385
|
+
className: "trm-room-head"
|
|
2386
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2387
|
+
className: "trm-room-head-title"
|
|
2388
|
+
}, /* @__PURE__ */ React.createElement("strong", {
|
|
2389
|
+
className: "trm-ellipsis"
|
|
2390
|
+
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
2391
|
+
className: "trm-room-head-count"
|
|
2392
|
+
}, t("memberCount", { n: room.members.length })), /* @__PURE__ */ React.createElement("span", {
|
|
2393
|
+
className: `trm-room-head-sub${room.connected ? "" : " trm-quiet"}`
|
|
2394
|
+
}, !room.connected ? t("connecting") : page ? page.title : t("onlineCount", { n: online }))), /* @__PURE__ */ React.createElement(MemberFaces, {
|
|
2395
|
+
room,
|
|
2396
|
+
shown,
|
|
2397
|
+
onClick: () => void pi.ui.showView(MEMBERS_VIEW)
|
|
2398
|
+
}));
|
|
2399
|
+
}
|
|
2400
|
+
function PageLine({ room }) {
|
|
2401
|
+
const page = usePageOf(room);
|
|
2402
|
+
if (!page || !room.view) {
|
|
2403
|
+
return null;
|
|
2404
|
+
}
|
|
2405
|
+
const Icon = page.icon ?? icon("ExternalLink");
|
|
2406
|
+
const Chevron = icon("ChevronRight");
|
|
2407
|
+
const view = room.view;
|
|
2408
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
2409
|
+
type: "button",
|
|
2410
|
+
className: "trm-page-line",
|
|
2411
|
+
onClick: () => void pi.ui.showView(view)
|
|
2412
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2413
|
+
className: "trm-page-line-icon"
|
|
2414
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
2415
|
+
size: 15
|
|
2416
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
2417
|
+
className: "trm-page-line-text"
|
|
2418
|
+
}, t("pageLine", { name: page.title })), /* @__PURE__ */ React.createElement("span", {
|
|
2419
|
+
className: "trm-page-line-open"
|
|
2420
|
+
}, t("openPage", { name: page.title }), /* @__PURE__ */ React.createElement(Chevron, {
|
|
2421
|
+
size: 14
|
|
2422
|
+
})));
|
|
2423
|
+
}
|
|
2424
|
+
function RoomView({ room, head, onBack }) {
|
|
2425
|
+
const Back = icon("ArrowLeft");
|
|
2426
|
+
const chat = book.chat(room.id);
|
|
2427
|
+
const lines = useLines(room);
|
|
2428
|
+
const agents = useAgents(room);
|
|
2429
|
+
const joining = useJoining(room);
|
|
2430
|
+
const tasks = useTaskStates(room);
|
|
2431
|
+
const list = React.useRef(null);
|
|
2432
|
+
const stuck = React.useRef(true);
|
|
2433
|
+
const self = room.members.find((member) => member.self);
|
|
2434
|
+
const personOf = (line) => room.members.find((member) => member.member === line.from)?.name ?? line.name;
|
|
2435
|
+
const nameOf = (line) => line.agent ? line.agent.name : !line.double ? personOf(line) : line.from === self?.member ? dt("myDouble") : dt("doubleOf", { name: personOf(line) });
|
|
2436
|
+
const tagOf = (line) => line.agent ? agentOwner(room, { member: line.from }) : line.double ? dt("doubleTag") : "";
|
|
2437
|
+
const mentions = React.useMemo(() => [...agentMentions(room, agents), ...askable(room).map((member) => ({ name: mentionName(member.name), detail: dt("mentionDetail") }))], [room, agents]);
|
|
2438
|
+
React.useLayoutEffect(() => {
|
|
2439
|
+
const element = list.current;
|
|
2440
|
+
if (element && stuck.current) {
|
|
2441
|
+
element.scrollTop = element.scrollHeight;
|
|
2442
|
+
}
|
|
2443
|
+
}, [lines, joining]);
|
|
2444
|
+
React.useEffect(() => {
|
|
2445
|
+
if (pi.ui.Stack) {
|
|
2446
|
+
return;
|
|
2447
|
+
}
|
|
2448
|
+
return pi.onRoomEvent?.((event) => book.heard(event), { messages: true });
|
|
2449
|
+
}, []);
|
|
2450
|
+
React.useEffect(() => {
|
|
2451
|
+
const last = lines[lines.length - 1];
|
|
2452
|
+
if (last) {
|
|
2453
|
+
book.see(room.id, last.at);
|
|
2454
|
+
}
|
|
2455
|
+
}, [lines, room.id]);
|
|
2456
|
+
const say = async (text) => {
|
|
2457
|
+
if (!self || !chat) {
|
|
2458
|
+
throw new Error(t("connecting"));
|
|
2459
|
+
}
|
|
2460
|
+
stuck.current = true;
|
|
2461
|
+
const to = addressed(text, room, agents);
|
|
2462
|
+
await chat.say(text, self, to.length ? { to } : {});
|
|
2463
|
+
};
|
|
2464
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2465
|
+
className: "trm-room-page"
|
|
2466
|
+
}, head && /* @__PURE__ */ React.createElement("div", {
|
|
2467
|
+
className: "trm-room-bar"
|
|
2468
|
+
}, onBack && /* @__PURE__ */ React.createElement("button", {
|
|
2469
|
+
type: "button",
|
|
2470
|
+
className: "trm-icon",
|
|
2471
|
+
title: t("back"),
|
|
2472
|
+
"aria-label": t("back"),
|
|
2473
|
+
onClick: onBack
|
|
2474
|
+
}, /* @__PURE__ */ React.createElement(Back, {
|
|
2475
|
+
size: 18
|
|
2476
|
+
})), /* @__PURE__ */ React.createElement(RoomHead, {
|
|
2477
|
+
room
|
|
2478
|
+
})), /* @__PURE__ */ React.createElement(PageLine, {
|
|
2479
|
+
room
|
|
2480
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2481
|
+
className: "trm-chat ta-conversation",
|
|
2482
|
+
ref: list,
|
|
2483
|
+
onScroll: (event) => {
|
|
2484
|
+
const element = event.currentTarget;
|
|
2485
|
+
stuck.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
|
|
2486
|
+
}
|
|
2487
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2488
|
+
className: "trm-chat-col"
|
|
2489
|
+
}, lines.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
2490
|
+
className: "trm-chat-empty"
|
|
2491
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
2492
|
+
room,
|
|
2493
|
+
size: 56
|
|
2494
|
+
}), /* @__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", {
|
|
2495
|
+
className: "trm-chat-hint"
|
|
2496
|
+
}, t("chatEmpty")), agents.length === 0 && joining.length === 0 && room.members.length < 2 && /* @__PURE__ */ React.createElement("button", {
|
|
2497
|
+
type: "button",
|
|
2498
|
+
className: "ta-button trm-try-alone",
|
|
2499
|
+
onClick: () => openAgentPicker(room)
|
|
2500
|
+
}, dt("inviteAgent"))), lines.map((line, index) => {
|
|
2501
|
+
const before = lines[index - 1];
|
|
2502
|
+
const separator = !before || line.at - before.at > PAUSE_MS;
|
|
2503
|
+
const first = separator || speaker(before) !== speaker(line) || line.at - before.at > RUN_MS;
|
|
2504
|
+
const other = room.members.find((member) => member.member === line.from);
|
|
2505
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
2506
|
+
key: line.id
|
|
2507
|
+
}, separator && /* @__PURE__ */ React.createElement("div", {
|
|
2508
|
+
className: "trm-chat-time"
|
|
2509
|
+
}, time(line.at)), line.from === self?.member && !line.double && !line.agent ? /* @__PURE__ */ React.createElement("div", {
|
|
2510
|
+
className: "ta-message ta-user trm-mine",
|
|
2511
|
+
title: time(line.at)
|
|
2512
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2513
|
+
className: "ta-bubble"
|
|
2514
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
2515
|
+
text: line.text
|
|
2516
|
+
}))) : /* @__PURE__ */ React.createElement("div", {
|
|
2517
|
+
className: `trm-msg${first ? " trm-first" : ""}${line.double ? " trm-double" : ""}${line.agent ? " trm-agent" : ""}`
|
|
2518
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2519
|
+
className: "trm-msg-face"
|
|
2520
|
+
}, first && /* @__PURE__ */ React.createElement(Face, {
|
|
2521
|
+
id: line.agent?.id ?? other?.id ?? line.from,
|
|
2522
|
+
name: nameOf(line),
|
|
2523
|
+
face: line.agent && agents.find((agent) => agent.id === line.agent?.id && agent.member === line.from)?.face,
|
|
2524
|
+
size: 28
|
|
2525
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
2526
|
+
className: "trm-msg-col"
|
|
2527
|
+
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
2528
|
+
className: "trm-msg-name"
|
|
2529
|
+
}, nameOf(line), tagOf(line) && /* @__PURE__ */ React.createElement("span", {
|
|
2530
|
+
className: `trm-tag ${line.agent ? "trm-tag-agent" : "trm-tag-double"}`
|
|
2531
|
+
}, tagOf(line)), line.task && /* @__PURE__ */ React.createElement("span", {
|
|
2532
|
+
className: "trm-tag trm-tag-task"
|
|
2533
|
+
}, dt("taskTag"))), /* @__PURE__ */ React.createElement("div", {
|
|
2534
|
+
className: "trm-msg-bubble",
|
|
2535
|
+
title: time(line.at)
|
|
2536
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
2537
|
+
text: line.text
|
|
2538
|
+
})), line.task && /* @__PURE__ */ React.createElement(TaskLine, {
|
|
2539
|
+
statuses: (tasks[line.id] ?? []).filter((each) => line.to?.includes(each.member)).map((each) => each.status)
|
|
2540
|
+
}))));
|
|
2541
|
+
}), joining.map((agent) => /* @__PURE__ */ React.createElement("div", {
|
|
2542
|
+
key: agent.id,
|
|
2543
|
+
className: "trm-chat-joining",
|
|
2544
|
+
role: "status"
|
|
2545
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2546
|
+
className: "ta-spinner"
|
|
2547
|
+
}), dt("joiningRoom", { name: agent.name }))))), /* @__PURE__ */ React.createElement("div", {
|
|
2548
|
+
className: "trm-chat-bottom"
|
|
2549
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Composer, {
|
|
2550
|
+
placeholder: t("chatPlaceholder"),
|
|
2551
|
+
onSend: say,
|
|
2552
|
+
mentions,
|
|
2553
|
+
mentionLabel: dt("mentionLabel")
|
|
2554
|
+
})));
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// web-src/friends-view.tsx
|
|
2558
|
+
function isFriendLink(text) {
|
|
2559
|
+
return RelayHubUtil.is(text) && RelayFriendsUtil.isKind(RelayHubUtil.parse(text).kind);
|
|
2560
|
+
}
|
|
2561
|
+
function useRun() {
|
|
2562
|
+
const [busy, setBusy] = React.useState(false);
|
|
2563
|
+
const run = React.useCallback(async (action) => {
|
|
2564
|
+
setBusy(true);
|
|
2565
|
+
try {
|
|
2566
|
+
await action();
|
|
2567
|
+
} catch (error) {
|
|
2568
|
+
pi.ui.notify(message(error), "error");
|
|
2569
|
+
} finally {
|
|
2570
|
+
setBusy(false);
|
|
2571
|
+
}
|
|
2572
|
+
}, []);
|
|
2573
|
+
return [busy, run];
|
|
2574
|
+
}
|
|
2575
|
+
function FriendRequestRow({ request }) {
|
|
2576
|
+
const [busy, run] = useRun();
|
|
2577
|
+
const answer = (accept) => void run(async () => {
|
|
2578
|
+
await rooms()?.answerFriend(request.id, accept);
|
|
2579
|
+
await book.load();
|
|
2580
|
+
});
|
|
2581
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2582
|
+
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
2583
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2584
|
+
id: request.id,
|
|
2585
|
+
name: request.name
|
|
2586
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2587
|
+
className: "trm-row-text"
|
|
2588
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2589
|
+
className: "trm-row-title"
|
|
2590
|
+
}, request.name), /* @__PURE__ */ React.createElement("span", {
|
|
2591
|
+
className: "trm-row-line"
|
|
2592
|
+
}, request.via === "room" && request.room ? t("friendRequestRoom", { room: request.room }) : t("friendRequestLink"))), /* @__PURE__ */ React.createElement("div", {
|
|
2593
|
+
className: "trm-answers"
|
|
2594
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2595
|
+
type: "button",
|
|
2596
|
+
className: "ta-button",
|
|
2597
|
+
disabled: busy,
|
|
2598
|
+
onClick: () => answer(false)
|
|
2599
|
+
}, t("refuse")), /* @__PURE__ */ React.createElement("button", {
|
|
2600
|
+
type: "button",
|
|
2601
|
+
className: "ta-button ta-primary",
|
|
2602
|
+
disabled: busy,
|
|
2603
|
+
onClick: () => answer(true)
|
|
2604
|
+
}, t("friendAccept"))));
|
|
2605
|
+
}
|
|
2606
|
+
function FriendRow({ friend }) {
|
|
2607
|
+
const Remove = icon("Trash2");
|
|
2608
|
+
const remove = () => void confirmThen(t("removeFriendTitle", { name: friend.name }), t("removeFriendHint"), t("removeFriend"), async () => {
|
|
2609
|
+
await rooms()?.removeFriend(friend.id);
|
|
2610
|
+
await book.load();
|
|
2611
|
+
});
|
|
2612
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2613
|
+
className: "trm-friend"
|
|
2614
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2615
|
+
id: friend.id,
|
|
2616
|
+
name: friend.name,
|
|
2617
|
+
size: 38,
|
|
2618
|
+
online: friend.status === "friend" ? friend.online : undefined
|
|
2619
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2620
|
+
className: "trm-room-text"
|
|
2621
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2622
|
+
className: "trm-room-name trm-ellipsis"
|
|
2623
|
+
}, friend.name), friend.status === "adding" && /* @__PURE__ */ React.createElement("span", {
|
|
2624
|
+
className: "trm-room-preview trm-ellipsis"
|
|
2625
|
+
}, t("friendAdding"))), /* @__PURE__ */ React.createElement("button", {
|
|
2626
|
+
type: "button",
|
|
2627
|
+
className: "trm-icon trm-danger",
|
|
2628
|
+
title: t("removeFriend"),
|
|
2629
|
+
"aria-label": `${t("removeFriend")} · ${friend.name}`,
|
|
2630
|
+
onClick: remove
|
|
2631
|
+
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
2632
|
+
size: 15
|
|
2633
|
+
})));
|
|
2634
|
+
}
|
|
2635
|
+
function FriendsPage() {
|
|
2636
|
+
const { friends, friendRequests } = useBook();
|
|
2637
|
+
const Add = icon("UserPlus");
|
|
2638
|
+
if (!rooms()) {
|
|
2639
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2640
|
+
title: t("oldApp")
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2644
|
+
className: "trm-list trm-friends-page"
|
|
2645
|
+
}, friendRequests.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
2646
|
+
className: "trm-section"
|
|
2647
|
+
}, /* @__PURE__ */ React.createElement("h3", null, t("friendRequestsTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
2648
|
+
className: "trm-card"
|
|
2649
|
+
}, friendRequests.map((request) => /* @__PURE__ */ React.createElement(FriendRequestRow, {
|
|
2650
|
+
key: request.id,
|
|
2651
|
+
request
|
|
2652
|
+
})))), /* @__PURE__ */ React.createElement("section", {
|
|
2653
|
+
className: "trm-section"
|
|
2654
|
+
}, !!friends?.length && /* @__PURE__ */ React.createElement("h3", null, `${t("friends")} · ${friends.length}`), friends === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
2655
|
+
rows: 3
|
|
2656
|
+
}) : null : friends.length === 0 ? /* @__PURE__ */ React.createElement("div", {
|
|
2657
|
+
className: "trm-friends-empty"
|
|
2658
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
2659
|
+
compact: true,
|
|
2660
|
+
title: t("friendsEmpty"),
|
|
2661
|
+
hint: t("friendsEmptyHint")
|
|
2662
|
+
}), /* @__PURE__ */ React.createElement("button", {
|
|
2663
|
+
type: "button",
|
|
2664
|
+
className: "ta-button ta-primary",
|
|
2665
|
+
onClick: openAddFriend
|
|
2666
|
+
}, /* @__PURE__ */ React.createElement(Add, {
|
|
2667
|
+
size: 14
|
|
2668
|
+
}), " ", t("addFriend"))) : /* @__PURE__ */ React.createElement("ul", {
|
|
2669
|
+
className: "trm-rooms"
|
|
2670
|
+
}, friends.map((friend) => /* @__PURE__ */ React.createElement(FriendRow, {
|
|
2671
|
+
key: friend.id,
|
|
2672
|
+
friend
|
|
2673
|
+
})))));
|
|
2674
|
+
}
|
|
2675
|
+
function FriendsHead() {
|
|
2676
|
+
const Add = icon("UserPlus");
|
|
2677
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2678
|
+
className: "trm-head trm-head-center"
|
|
2679
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2680
|
+
className: "trm-head-title"
|
|
2681
|
+
}, t("friends")), /* @__PURE__ */ React.createElement("span", {
|
|
2682
|
+
className: "trm-head-end"
|
|
2683
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2684
|
+
type: "button",
|
|
2685
|
+
className: "trm-icon",
|
|
2686
|
+
title: t("addFriend"),
|
|
2687
|
+
"aria-label": t("addFriend"),
|
|
2688
|
+
onClick: openAddFriend
|
|
2689
|
+
}, /* @__PURE__ */ React.createElement(Add, {
|
|
2690
|
+
size: 18
|
|
2691
|
+
}))));
|
|
2692
|
+
}
|
|
2693
|
+
function FriendsEntry() {
|
|
2694
|
+
const { friends, friendRequests } = useBook();
|
|
2695
|
+
const Chevron = icon("ChevronRight");
|
|
2696
|
+
const list = (friends ?? []).filter((friend) => friend.status === "friend");
|
|
2697
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
2698
|
+
type: "button",
|
|
2699
|
+
className: "trm-friends-entry",
|
|
2700
|
+
onClick: () => void pi.ui.showView(FRIENDS_VIEW)
|
|
2701
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2702
|
+
className: "trm-friends-entry-label"
|
|
2703
|
+
}, t("friends")), friendRequests.length > 0 && /* @__PURE__ */ React.createElement("span", {
|
|
2704
|
+
className: "trm-dot"
|
|
2705
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2706
|
+
className: "trm-grow"
|
|
2707
|
+
}), list.length > 0 && pi.ui.GroupFace && /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
|
|
2708
|
+
members: list.slice(0, 4).map((friend) => ({ seed: friend.id })),
|
|
2709
|
+
size: 24
|
|
2710
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2711
|
+
className: "trm-quiet"
|
|
2712
|
+
}, list.length ? t("friendsCount", { n: list.length }) : t("friendsNone")), /* @__PURE__ */ React.createElement(Chevron, {
|
|
2713
|
+
size: 16
|
|
2714
|
+
}));
|
|
2715
|
+
}
|
|
2716
|
+
function AddFriendDialog({ close }) {
|
|
2717
|
+
const [link, setLink] = React.useState();
|
|
2718
|
+
const [error, setError] = React.useState();
|
|
2719
|
+
const [copied, setCopied] = React.useState(false);
|
|
2720
|
+
const make = React.useCallback((renew) => {
|
|
2721
|
+
setError(undefined);
|
|
2722
|
+
setCopied(false);
|
|
2723
|
+
rooms()?.friendLink(renew).then(setLink).catch((failure) => setError(message(failure)));
|
|
2724
|
+
}, []);
|
|
2725
|
+
React.useEffect(() => make(false), [make]);
|
|
2726
|
+
const canSend = typeof navigator !== "undefined" && typeof navigator.share === "function";
|
|
2727
|
+
const days = link ? Math.max(1, Math.round((link.expiresAt - Date.now()) / 86400000)) : 0;
|
|
2728
|
+
const other = (read) => () => {
|
|
2729
|
+
close();
|
|
2730
|
+
read().then((text) => text && openFriendLink(text));
|
|
2731
|
+
};
|
|
2732
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
2733
|
+
title: t("addFriend"),
|
|
2734
|
+
onClose: close
|
|
2735
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2736
|
+
className: "trm-dialog trm-invite"
|
|
2737
|
+
}, link ? /* @__PURE__ */ React.createElement(React.Fragment, null, pi.ui.QrCode && /* @__PURE__ */ React.createElement("div", {
|
|
2738
|
+
className: "trm-qr"
|
|
2739
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.QrCode, {
|
|
2740
|
+
text: link.link,
|
|
2741
|
+
label: t("qr")
|
|
2742
|
+
})), /* @__PURE__ */ React.createElement("p", {
|
|
2743
|
+
className: "trm-hint"
|
|
2744
|
+
}, t("addFriendHint")), /* @__PURE__ */ React.createElement("p", {
|
|
2745
|
+
className: "trm-hint trm-quiet"
|
|
2746
|
+
}, t("addFriendExpires", { days })), /* @__PURE__ */ React.createElement("div", {
|
|
2747
|
+
className: "trm-actions trm-center"
|
|
2748
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2749
|
+
type: "button",
|
|
2750
|
+
className: "ta-button ta-primary",
|
|
2751
|
+
onClick: () => void navigator.clipboard?.writeText(link.link).then(() => setCopied(true))
|
|
2752
|
+
}, copied ? t("copied") : t("copy")), canSend && /* @__PURE__ */ React.createElement("button", {
|
|
2753
|
+
type: "button",
|
|
2754
|
+
className: "ta-button",
|
|
2755
|
+
onClick: () => void navigator.share({ title: t("addFriend"), url: link.link }).catch(() => {
|
|
2756
|
+
return;
|
|
2757
|
+
})
|
|
2758
|
+
}, t("send")), /* @__PURE__ */ React.createElement("button", {
|
|
2759
|
+
type: "button",
|
|
2760
|
+
className: "ta-button",
|
|
2761
|
+
onClick: () => make(true)
|
|
2762
|
+
}, t("newLink")))) : error ? /* @__PURE__ */ React.createElement("p", {
|
|
2763
|
+
className: "trm-error"
|
|
2764
|
+
}, error) : /* @__PURE__ */ React.createElement("p", {
|
|
2765
|
+
className: "trm-hint"
|
|
2766
|
+
}, t("making")), /* @__PURE__ */ React.createElement("div", {
|
|
2767
|
+
className: "trm-actions trm-center trm-friends-other"
|
|
2768
|
+
}, pi.ui.scanCode && /* @__PURE__ */ React.createElement("button", {
|
|
2769
|
+
type: "button",
|
|
2770
|
+
className: "trm-link",
|
|
2771
|
+
onClick: other(async () => (await pi.ui.scanCode?.(t("scanHint")))?.trim())
|
|
2772
|
+
}, t("scanFriend")), /* @__PURE__ */ React.createElement("button", {
|
|
2773
|
+
type: "button",
|
|
2774
|
+
className: "trm-link",
|
|
2775
|
+
onClick: other(async () => (await pi.ui.input(t("pasteFriend"), t("joinByLinkPlaceholder")))?.trim())
|
|
2776
|
+
}, t("pasteFriend")))));
|
|
2777
|
+
}
|
|
2778
|
+
function openAddFriend() {
|
|
2779
|
+
show(AddFriendDialog);
|
|
2780
|
+
}
|
|
2781
|
+
function FriendLinkDialog({ text, close }) {
|
|
2782
|
+
const link = RelayHubUtil.parse(text);
|
|
2783
|
+
const { identity, friends } = useBook();
|
|
2784
|
+
const [busy, run] = useRun();
|
|
2785
|
+
const known = friends?.find((friend) => friend.id === link.owner && friend.status === "friend");
|
|
2786
|
+
const own = identity?.id === link.owner;
|
|
2787
|
+
const add = () => void run(async () => {
|
|
2788
|
+
await rooms()?.addFriend(text);
|
|
2789
|
+
pi.ui.notify(t("addFriendAsked", { name: link.by || "…" }));
|
|
2790
|
+
close();
|
|
2791
|
+
await book.load();
|
|
2792
|
+
});
|
|
2793
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
2794
|
+
title: t("addFriend"),
|
|
2795
|
+
onClose: close
|
|
2796
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2797
|
+
className: "trm-dialog"
|
|
2798
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2799
|
+
className: "trm-join"
|
|
2800
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2801
|
+
id: link.owner,
|
|
2802
|
+
name: link.by || "?",
|
|
2803
|
+
size: 56
|
|
2804
|
+
}), /* @__PURE__ */ React.createElement("strong", {
|
|
2805
|
+
className: "trm-join-name"
|
|
2806
|
+
}, link.by || "…"), /* @__PURE__ */ React.createElement("p", {
|
|
2807
|
+
className: "trm-lead"
|
|
2808
|
+
}, own ? t("addFriendOwn") : known ? t("addFriendKnown", { name: link.by }) : t("addFriendBody", { name: link.by || "…" }))), /* @__PURE__ */ React.createElement("div", {
|
|
2809
|
+
className: "trm-actions"
|
|
2810
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2811
|
+
type: "button",
|
|
2812
|
+
className: "ta-button",
|
|
2813
|
+
onClick: close
|
|
2814
|
+
}, t("later")), !own && !known && /* @__PURE__ */ React.createElement("button", {
|
|
2815
|
+
type: "button",
|
|
2816
|
+
className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
|
|
2817
|
+
disabled: busy,
|
|
2818
|
+
onClick: add
|
|
2819
|
+
}, t("addFriendAction")))));
|
|
2820
|
+
}
|
|
2821
|
+
function openFriendLink(text) {
|
|
2822
|
+
if (!isFriendLink(text)) {
|
|
2823
|
+
if (!RelayHubUtil.is(text)) {
|
|
2824
|
+
pi.ui.notify(t("notInvite"), "warning");
|
|
2825
|
+
}
|
|
2826
|
+
return false;
|
|
2827
|
+
}
|
|
2828
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(FriendLinkDialog, {
|
|
2829
|
+
text,
|
|
2830
|
+
close
|
|
2831
|
+
}));
|
|
2832
|
+
return true;
|
|
2833
|
+
}
|
|
2834
|
+
function FriendRequestsDialog({ close }) {
|
|
2835
|
+
const { friendRequests } = useBook();
|
|
2836
|
+
const seen = React.useRef(false);
|
|
2837
|
+
React.useEffect(() => {
|
|
2838
|
+
if (friendRequests.length) {
|
|
2839
|
+
seen.current = true;
|
|
2840
|
+
} else if (seen.current) {
|
|
2841
|
+
close();
|
|
2842
|
+
}
|
|
2843
|
+
}, [friendRequests.length, close]);
|
|
2844
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
2845
|
+
title: t("friendRequestsTitle"),
|
|
2846
|
+
onClose: close
|
|
2847
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2848
|
+
className: "trm-dialog"
|
|
2849
|
+
}, /* @__PURE__ */ React.createElement("ul", {
|
|
2850
|
+
className: "trm-rows"
|
|
2851
|
+
}, friendRequests.map((request) => /* @__PURE__ */ React.createElement(FriendRequestRow, {
|
|
2852
|
+
key: request.id,
|
|
2853
|
+
request
|
|
2854
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
2855
|
+
className: "trm-note"
|
|
2856
|
+
}, t("friendRequestNote")), /* @__PURE__ */ React.createElement("div", {
|
|
2857
|
+
className: "trm-actions"
|
|
2858
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2859
|
+
type: "button",
|
|
2860
|
+
className: "ta-button",
|
|
2861
|
+
onClick: close
|
|
2862
|
+
}, t("later")))));
|
|
2863
|
+
}
|
|
2864
|
+
var requestsOpen;
|
|
2865
|
+
function openFriendRequests() {
|
|
2866
|
+
if (requestsOpen) {
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
requestsOpen = show(({ close }) => /* @__PURE__ */ React.createElement(FriendRequestsDialog, {
|
|
2870
|
+
close: () => {
|
|
2871
|
+
requestsOpen = undefined;
|
|
2872
|
+
close();
|
|
2873
|
+
}
|
|
2874
|
+
}));
|
|
2875
|
+
}
|
|
2876
|
+
async function offerFriend(room, member, name) {
|
|
2877
|
+
try {
|
|
2878
|
+
await rooms()?.offerFriend(room, member);
|
|
2879
|
+
pi.ui.notify(t("friendOffered", { name }));
|
|
2880
|
+
await book.load();
|
|
2881
|
+
} catch (error) {
|
|
2882
|
+
pi.ui.notify(message(error), "error");
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
// web-src/dialogs.tsx
|
|
2887
|
+
function show(component) {
|
|
2888
|
+
if (!pi.ui.custom) {
|
|
2889
|
+
pi.ui.notify(t("oldApp"), "warning");
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
return pi.ui.custom(component);
|
|
2893
|
+
}
|
|
2894
|
+
function RequestRow({ request }) {
|
|
2895
|
+
const [busy, run] = (pi.ui.useBusy ?? (() => [false, async (action) => action()]))();
|
|
2896
|
+
const answer = (accept) => void run(async () => {
|
|
2897
|
+
try {
|
|
2898
|
+
await rooms()?.answer(request.room, request.ask, accept);
|
|
2899
|
+
} catch (error) {
|
|
2900
|
+
pi.ui.notify(message(error), "error");
|
|
2901
|
+
}
|
|
2902
|
+
await book.load();
|
|
2903
|
+
});
|
|
2904
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
2905
|
+
className: `trm-row${busy ? " ta-pending" : ""}`
|
|
2906
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
2907
|
+
id: request.id,
|
|
2908
|
+
name: request.name
|
|
2909
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
2910
|
+
className: "trm-row-text"
|
|
2911
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
2912
|
+
className: "trm-row-title"
|
|
2913
|
+
}, request.name, /* @__PURE__ */ React.createElement("span", {
|
|
2914
|
+
className: `trm-tag${request.friend ? " trm-tag-friend" : ""}`
|
|
2915
|
+
}, request.guest ? t("guestTag") : request.friend ? t("friendTag") : t("newTag"))), /* @__PURE__ */ React.createElement("span", {
|
|
2916
|
+
className: "trm-row-line"
|
|
2917
|
+
}, t("requestLine", { title: request.title }))), /* @__PURE__ */ React.createElement("div", {
|
|
2918
|
+
className: "trm-answers"
|
|
2919
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2920
|
+
type: "button",
|
|
2921
|
+
className: "ta-button",
|
|
2922
|
+
disabled: busy,
|
|
2923
|
+
onClick: () => answer(false)
|
|
2924
|
+
}, t("refuse")), /* @__PURE__ */ React.createElement("button", {
|
|
2925
|
+
type: "button",
|
|
2926
|
+
className: "ta-button ta-primary",
|
|
2927
|
+
disabled: busy,
|
|
2928
|
+
onClick: () => answer(true)
|
|
2929
|
+
}, t("accept"))));
|
|
2930
|
+
}
|
|
2931
|
+
function RequestsDialog({ close }) {
|
|
2932
|
+
const { requests } = useBook();
|
|
2933
|
+
const seen = React.useRef(false);
|
|
2934
|
+
React.useEffect(() => {
|
|
2935
|
+
if (requests.length) {
|
|
2936
|
+
seen.current = true;
|
|
2937
|
+
} else if (seen.current) {
|
|
2938
|
+
close();
|
|
2939
|
+
}
|
|
2940
|
+
}, [requests.length, close]);
|
|
2941
|
+
const first = requests[0];
|
|
2942
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
2943
|
+
title: t("requests"),
|
|
2944
|
+
onClose: close
|
|
2945
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
2946
|
+
className: "trm-dialog"
|
|
2947
|
+
}, first && /* @__PURE__ */ React.createElement("p", {
|
|
2948
|
+
className: "trm-lead"
|
|
2949
|
+
}, requests.length === 1 ? t("requestBody", { name: first.name, title: first.title }) : t("requestsBody", { n: requests.length })), /* @__PURE__ */ React.createElement("ul", {
|
|
2950
|
+
className: "trm-rows"
|
|
2951
|
+
}, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
|
|
2952
|
+
key: `${request.room}:${request.ask}`,
|
|
2953
|
+
request
|
|
2954
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
2955
|
+
className: "trm-note"
|
|
2956
|
+
}, [
|
|
2957
|
+
requests.some((request) => !request.friend) ? t("requestNew") : requests.length ? t("requestFriend") : "",
|
|
2958
|
+
requests.some((request) => request.guest) ? t("requestGuest") : "",
|
|
2959
|
+
t("requestWhat")
|
|
2960
|
+
].filter(Boolean).join(pi.ui.language === "zh-CN" ? "" : " ")), /* @__PURE__ */ React.createElement("div", {
|
|
2961
|
+
className: "trm-actions"
|
|
2962
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
2963
|
+
type: "button",
|
|
2964
|
+
className: "ta-button",
|
|
2965
|
+
onClick: close
|
|
2966
|
+
}, t("later")))));
|
|
2967
|
+
}
|
|
2968
|
+
var requestsOpen2;
|
|
2969
|
+
function openRequests() {
|
|
2970
|
+
if (requestsOpen2) {
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
const close = show(({ close: close2 }) => /* @__PURE__ */ React.createElement(RequestsDialog, {
|
|
2974
|
+
close: () => {
|
|
2975
|
+
requestsOpen2 = undefined;
|
|
2976
|
+
close2();
|
|
2977
|
+
}
|
|
2978
|
+
}));
|
|
2979
|
+
requestsOpen2 = close;
|
|
2980
|
+
}
|
|
2981
|
+
function JoinDialog({ link, text, close }) {
|
|
2982
|
+
const { identity } = useBook();
|
|
2983
|
+
const [busy, setBusy] = React.useState(false);
|
|
2984
|
+
const [error, setError] = React.useState();
|
|
2985
|
+
const join = async () => {
|
|
2986
|
+
setBusy(true);
|
|
2987
|
+
setError(undefined);
|
|
2988
|
+
try {
|
|
1022
2989
|
const room = await rooms()?.join(text);
|
|
1023
2990
|
await book.load();
|
|
1024
2991
|
close();
|
|
@@ -1118,6 +3085,10 @@ function openInvite(room) {
|
|
|
1118
3085
|
}));
|
|
1119
3086
|
}
|
|
1120
3087
|
function openJoin(text) {
|
|
3088
|
+
if (isFriendLink(text)) {
|
|
3089
|
+
openFriendLink(text);
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
1121
3092
|
const link = RelayHubUtil.parse(text);
|
|
1122
3093
|
const known = book.get().rooms?.find((room) => room.id === link.room && room.status === "member");
|
|
1123
3094
|
if (known) {
|
|
@@ -1169,212 +3140,42 @@ async function scanLink() {
|
|
|
1169
3140
|
}
|
|
1170
3141
|
if (!RelayHubUtil.is(text)) {
|
|
1171
3142
|
pi.ui.notify(t("notInvite"), "warning");
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
openJoin(text);
|
|
1175
|
-
}
|
|
1176
|
-
async function rename() {
|
|
1177
|
-
const identity = book.get().identity;
|
|
1178
|
-
const name = await pi.ui.input(t("me"), t("renamePlaceholder"), { value: identity?.name ?? "" });
|
|
1179
|
-
if (name?.trim() && name.trim() !== identity?.name) {
|
|
1180
|
-
try {
|
|
1181
|
-
book.set({ identity: await rooms()?.setName(name.trim()) });
|
|
1182
|
-
} catch (error) {
|
|
1183
|
-
pi.ui.notify(message(error), "error");
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
// web-src/room-view.tsx
|
|
1189
|
-
var RUN_MS = 5 * 60 * 1000;
|
|
1190
|
-
var PAUSE_MS = 15 * 60 * 1000;
|
|
1191
|
-
async function confirmThen(title, hint, label, action) {
|
|
1192
|
-
if (!await pi.ui.confirm(title, hint, { confirmLabel: label, danger: true })) {
|
|
1193
|
-
return false;
|
|
1194
|
-
}
|
|
1195
|
-
try {
|
|
1196
|
-
await action();
|
|
1197
|
-
} catch (error) {
|
|
1198
|
-
pi.ui.notify(message(error), "error");
|
|
1199
|
-
}
|
|
1200
|
-
await book.load();
|
|
1201
|
-
return true;
|
|
1202
|
-
}
|
|
1203
|
-
function leaveRoom(room) {
|
|
1204
|
-
if (room.status !== "member") {
|
|
1205
|
-
return (rooms()?.leave(room.id) ?? Promise.resolve()).then(() => book.load()).then(() => true);
|
|
1206
|
-
}
|
|
1207
|
-
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));
|
|
1208
|
-
}
|
|
1209
|
-
function time(at) {
|
|
1210
|
-
const date = new Date(at);
|
|
1211
|
-
const clock = date.toLocaleTimeString(pi.ui.language, { hour: "2-digit", minute: "2-digit" });
|
|
1212
|
-
return date.toDateString() === new Date().toDateString() ? clock : `${date.toLocaleDateString(pi.ui.language, { month: "numeric", day: "numeric" })} ${clock}`;
|
|
1213
|
-
}
|
|
1214
|
-
function MembersButton() {
|
|
1215
|
-
const shown = !!pi.ui.useView?.(MEMBERS_VIEW)?.shown;
|
|
1216
|
-
const More = icon("Ellipsis");
|
|
1217
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
1218
|
-
type: "button",
|
|
1219
|
-
className: `trm-icon trm-members-button${shown ? " trm-on-icon" : ""}`,
|
|
1220
|
-
title: t("members"),
|
|
1221
|
-
"aria-label": t("members"),
|
|
1222
|
-
"aria-pressed": shown,
|
|
1223
|
-
onClick: () => void pi.ui.showView(MEMBERS_VIEW)
|
|
1224
|
-
}, /* @__PURE__ */ React.createElement(More, {
|
|
1225
|
-
size: 18
|
|
1226
|
-
}));
|
|
1227
|
-
}
|
|
1228
|
-
function RoomTitle({ room }) {
|
|
1229
|
-
const online = room.members.filter((member) => member.online && !member.self).length;
|
|
1230
|
-
return /* @__PURE__ */ React.createElement("span", {
|
|
1231
|
-
className: "trm-room-title"
|
|
1232
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
1233
|
-
className: "trm-room-title-text"
|
|
1234
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
1235
|
-
className: "trm-ellipsis"
|
|
1236
|
-
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
1237
|
-
className: "trm-room-count"
|
|
1238
|
-
}, "(", room.members.length, ")")), /* @__PURE__ */ React.createElement("span", {
|
|
1239
|
-
className: `trm-room-sub${room.connected ? "" : " trm-quiet"}`
|
|
1240
|
-
}, !room.connected ? t("connecting") : online ? t("othersOnline", { n: online }) : t("nobodyOnline")));
|
|
1241
|
-
}
|
|
1242
|
-
function PageLine({ room }) {
|
|
1243
|
-
const page = usePageOf(room);
|
|
1244
|
-
if (!page || !room.view) {
|
|
1245
|
-
return null;
|
|
3143
|
+
return;
|
|
1246
3144
|
}
|
|
1247
|
-
|
|
1248
|
-
const Chevron = icon("ChevronRight");
|
|
1249
|
-
const view = room.view;
|
|
1250
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
1251
|
-
type: "button",
|
|
1252
|
-
className: "trm-page-line",
|
|
1253
|
-
onClick: () => void pi.ui.showView(view)
|
|
1254
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
1255
|
-
className: "trm-page-line-icon"
|
|
1256
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
1257
|
-
size: 15
|
|
1258
|
-
})), /* @__PURE__ */ React.createElement("span", {
|
|
1259
|
-
className: "trm-page-line-text"
|
|
1260
|
-
}, t("pageLine", { name: page.title })), /* @__PURE__ */ React.createElement("span", {
|
|
1261
|
-
className: "trm-page-line-open"
|
|
1262
|
-
}, t("openPage", { name: page.title }), /* @__PURE__ */ React.createElement(Chevron, {
|
|
1263
|
-
size: 14
|
|
1264
|
-
})));
|
|
3145
|
+
openJoin(text);
|
|
1265
3146
|
}
|
|
1266
|
-
function
|
|
1267
|
-
const
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
React.useLayoutEffect(() => {
|
|
1275
|
-
const element = list.current;
|
|
1276
|
-
if (element && stuck.current) {
|
|
1277
|
-
element.scrollTop = element.scrollHeight;
|
|
1278
|
-
}
|
|
1279
|
-
}, [lines]);
|
|
1280
|
-
React.useEffect(() => {
|
|
1281
|
-
if (pi.ui.Stack) {
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
return pi.onRoomEvent?.((event) => book.heard(event), { messages: true });
|
|
1285
|
-
}, []);
|
|
1286
|
-
React.useEffect(() => {
|
|
1287
|
-
const last = lines[lines.length - 1];
|
|
1288
|
-
if (last) {
|
|
1289
|
-
book.see(room.id, last.at);
|
|
1290
|
-
}
|
|
1291
|
-
}, [lines, room.id]);
|
|
1292
|
-
const say = async (text) => {
|
|
1293
|
-
if (!self || !chat) {
|
|
1294
|
-
throw new Error(t("connecting"));
|
|
1295
|
-
}
|
|
1296
|
-
stuck.current = true;
|
|
1297
|
-
await chat.say(text, self);
|
|
1298
|
-
};
|
|
1299
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
1300
|
-
className: "trm-room-page"
|
|
1301
|
-
}, head && /* @__PURE__ */ React.createElement("div", {
|
|
1302
|
-
className: "trm-room-head"
|
|
1303
|
-
}, onBack && /* @__PURE__ */ React.createElement("button", {
|
|
1304
|
-
type: "button",
|
|
1305
|
-
className: "trm-icon",
|
|
1306
|
-
title: t("back"),
|
|
1307
|
-
"aria-label": t("back"),
|
|
1308
|
-
onClick: onBack
|
|
1309
|
-
}, /* @__PURE__ */ React.createElement(Back, {
|
|
1310
|
-
size: 18
|
|
1311
|
-
})), /* @__PURE__ */ React.createElement(RoomTitle, {
|
|
1312
|
-
room
|
|
1313
|
-
}), /* @__PURE__ */ React.createElement(MembersButton, null)), /* @__PURE__ */ React.createElement(PageLine, {
|
|
1314
|
-
room
|
|
1315
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
1316
|
-
className: "trm-chat ta-conversation",
|
|
1317
|
-
ref: list,
|
|
1318
|
-
onScroll: (event) => {
|
|
1319
|
-
const element = event.currentTarget;
|
|
1320
|
-
stuck.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
|
|
3147
|
+
async function rename() {
|
|
3148
|
+
const identity = book.get().identity;
|
|
3149
|
+
const name = await pi.ui.input(t("me"), t("renamePlaceholder"), { value: identity?.name ?? "" });
|
|
3150
|
+
if (name?.trim() && name.trim() !== identity?.name) {
|
|
3151
|
+
try {
|
|
3152
|
+
book.set({ identity: await rooms()?.setName(name.trim()) });
|
|
3153
|
+
} catch (error) {
|
|
3154
|
+
pi.ui.notify(message(error), "error");
|
|
1321
3155
|
}
|
|
1322
|
-
}
|
|
1323
|
-
className: "trm-chat-col"
|
|
1324
|
-
}, lines.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
1325
|
-
className: "trm-chat-empty"
|
|
1326
|
-
}, t("chatEmpty")), lines.map((line, index) => {
|
|
1327
|
-
const before = lines[index - 1];
|
|
1328
|
-
const separator = !before || line.at - before.at > PAUSE_MS;
|
|
1329
|
-
const first = separator || before.from !== line.from || line.at - before.at > RUN_MS;
|
|
1330
|
-
const other = room.members.find((member) => member.member === line.from);
|
|
1331
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
1332
|
-
key: line.id
|
|
1333
|
-
}, separator && /* @__PURE__ */ React.createElement("div", {
|
|
1334
|
-
className: "trm-chat-time"
|
|
1335
|
-
}, time(line.at)), line.from === self?.member ? /* @__PURE__ */ React.createElement("div", {
|
|
1336
|
-
className: "ta-message ta-user trm-mine",
|
|
1337
|
-
title: time(line.at)
|
|
1338
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
1339
|
-
className: "ta-bubble"
|
|
1340
|
-
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
1341
|
-
text: line.text
|
|
1342
|
-
}))) : /* @__PURE__ */ React.createElement("div", {
|
|
1343
|
-
className: `trm-msg${first ? " trm-first" : ""}`
|
|
1344
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
1345
|
-
className: "trm-msg-face"
|
|
1346
|
-
}, first && /* @__PURE__ */ React.createElement(Face, {
|
|
1347
|
-
id: other?.id ?? line.from,
|
|
1348
|
-
name: nameOf(line),
|
|
1349
|
-
size: 30
|
|
1350
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
1351
|
-
className: "trm-msg-col"
|
|
1352
|
-
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
1353
|
-
className: "trm-msg-name"
|
|
1354
|
-
}, nameOf(line)), /* @__PURE__ */ React.createElement("div", {
|
|
1355
|
-
className: "trm-msg-bubble",
|
|
1356
|
-
title: time(line.at)
|
|
1357
|
-
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
1358
|
-
text: line.text
|
|
1359
|
-
})))));
|
|
1360
|
-
}))), /* @__PURE__ */ React.createElement("div", {
|
|
1361
|
-
className: "trm-chat-bottom"
|
|
1362
|
-
}, /* @__PURE__ */ React.createElement(pi.ui.Composer, {
|
|
1363
|
-
placeholder: t("chatPlaceholder"),
|
|
1364
|
-
onSend: say
|
|
1365
|
-
})));
|
|
3156
|
+
}
|
|
1366
3157
|
}
|
|
1367
3158
|
|
|
1368
3159
|
// web-src/members-view.tsx
|
|
1369
3160
|
function MemberRow({ room, member }) {
|
|
1370
3161
|
const Remove = icon("X");
|
|
1371
|
-
const
|
|
3162
|
+
const Key = pi.ui.icons.KeyRound ?? icon("Bot");
|
|
3163
|
+
const may = useMayLine(member);
|
|
3164
|
+
const { friends } = useBook();
|
|
3165
|
+
const friend = friends?.find((each) => each.id === member.id);
|
|
3166
|
+
const Add = icon("UserPlus");
|
|
3167
|
+
const tags = [
|
|
3168
|
+
member.self ? t("you") : "",
|
|
3169
|
+
member.owner ? t("owner") : "",
|
|
3170
|
+
member.guest ? t("guestTag") : "",
|
|
3171
|
+
friend?.status === "friend" ? t("friendTag") : ""
|
|
3172
|
+
].filter(Boolean);
|
|
1372
3173
|
return /* @__PURE__ */ React.createElement("li", {
|
|
1373
3174
|
className: "trm-member"
|
|
1374
3175
|
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1375
3176
|
id: member.id,
|
|
1376
3177
|
name: member.name,
|
|
1377
|
-
size:
|
|
3178
|
+
size: 34,
|
|
1378
3179
|
online: member.online
|
|
1379
3180
|
}), /* @__PURE__ */ React.createElement("span", {
|
|
1380
3181
|
className: "trm-member-text"
|
|
@@ -1387,7 +3188,25 @@ function MemberRow({ room, member }) {
|
|
|
1387
3188
|
className: "trm-tag"
|
|
1388
3189
|
}, tag))), /* @__PURE__ */ React.createElement("span", {
|
|
1389
3190
|
className: `trm-member-detail${member.online ? " trm-live" : ""}`
|
|
1390
|
-
}, member.online ? t("online") : t("offline"))
|
|
3191
|
+
}, member.online ? t("online") : t("offline")), may && /* @__PURE__ */ React.createElement("span", {
|
|
3192
|
+
className: "trm-member-detail trm-member-may trm-ellipsis"
|
|
3193
|
+
}, may)), !member.self && !member.guest && !friend && /* @__PURE__ */ React.createElement("button", {
|
|
3194
|
+
type: "button",
|
|
3195
|
+
className: "trm-icon trm-member-action",
|
|
3196
|
+
title: t("friendOffer"),
|
|
3197
|
+
"aria-label": `${t("friendOffer")} · ${member.name}`,
|
|
3198
|
+
onClick: () => void offerFriend(room.id, member.member, member.name)
|
|
3199
|
+
}, /* @__PURE__ */ React.createElement(Add, {
|
|
3200
|
+
size: 15
|
|
3201
|
+
})), !member.self && !member.guest && /* @__PURE__ */ React.createElement("button", {
|
|
3202
|
+
type: "button",
|
|
3203
|
+
className: `trm-icon trm-member-action${may ? " trm-on-icon" : ""}`,
|
|
3204
|
+
title: dt("permissions"),
|
|
3205
|
+
"aria-label": dt("permissions"),
|
|
3206
|
+
onClick: () => openGrant(member)
|
|
3207
|
+
}, /* @__PURE__ */ React.createElement(Key, {
|
|
3208
|
+
size: 15
|
|
3209
|
+
})), room.owner && !member.self && /* @__PURE__ */ React.createElement("button", {
|
|
1391
3210
|
type: "button",
|
|
1392
3211
|
className: "trm-icon trm-danger trm-member-action",
|
|
1393
3212
|
title: t("remove"),
|
|
@@ -1415,6 +3234,8 @@ function MembersView() {
|
|
|
1415
3234
|
const { identity } = useBook();
|
|
1416
3235
|
const room = useOpened();
|
|
1417
3236
|
const page = usePageOf(room ?? { view: undefined });
|
|
3237
|
+
const agents = useAgents(room ?? { status: "gone" });
|
|
3238
|
+
const joining = useJoining(room ?? { id: "", status: "gone", members: [] });
|
|
1418
3239
|
if (!room) {
|
|
1419
3240
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1420
3241
|
className: "trm-panel"
|
|
@@ -1423,7 +3244,9 @@ function MembersView() {
|
|
|
1423
3244
|
}));
|
|
1424
3245
|
}
|
|
1425
3246
|
const Plus = icon("Plus");
|
|
3247
|
+
const Bot = icon("Bot");
|
|
1426
3248
|
const online = room.members.filter((member) => member.online).length;
|
|
3249
|
+
const self = room.members.find((member) => member.self)?.member;
|
|
1427
3250
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1428
3251
|
className: "trm-panel"
|
|
1429
3252
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
@@ -1462,6 +3285,38 @@ function MembersView() {
|
|
|
1462
3285
|
room,
|
|
1463
3286
|
member
|
|
1464
3287
|
}))), /* @__PURE__ */ React.createElement("div", {
|
|
3288
|
+
className: "trm-panel-label"
|
|
3289
|
+
}, agents.length ? `${dt("agentsTitle")} · ${agents.length}` : dt("agentsTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
3290
|
+
className: "trm-panel-members"
|
|
3291
|
+
}, /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
3292
|
+
type: "button",
|
|
3293
|
+
className: "trm-member trm-member-add",
|
|
3294
|
+
onClick: () => openAgentPicker(room)
|
|
3295
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3296
|
+
className: "trm-member-plus"
|
|
3297
|
+
}, /* @__PURE__ */ React.createElement(Bot, {
|
|
3298
|
+
size: 16
|
|
3299
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
3300
|
+
className: "trm-member-text"
|
|
3301
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3302
|
+
className: "trm-member-name"
|
|
3303
|
+
}, dt("inviteAgent")), /* @__PURE__ */ React.createElement("span", {
|
|
3304
|
+
className: "trm-member-detail"
|
|
3305
|
+
}, dt("inviteAgentLine"))))), agents.map((agent) => /* @__PURE__ */ React.createElement(AgentRow, {
|
|
3306
|
+
key: `${agent.member}/${agent.id}`,
|
|
3307
|
+
room,
|
|
3308
|
+
agent
|
|
3309
|
+
})), joining.filter((agent) => !agents.some((each) => each.id === agent.id && each.member === self)).map((agent) => /* @__PURE__ */ React.createElement(JoiningRow, {
|
|
3310
|
+
key: `joining/${agent.id}`,
|
|
3311
|
+
agent
|
|
3312
|
+
}))), /* @__PURE__ */ React.createElement("div", {
|
|
3313
|
+
className: "trm-panel-sep"
|
|
3314
|
+
}), /* @__PURE__ */ React.createElement(DoubleSwitch, {
|
|
3315
|
+
room
|
|
3316
|
+
}), /* @__PURE__ */ React.createElement(SettingRow, {
|
|
3317
|
+
label: dt("log"),
|
|
3318
|
+
onClick: () => void pi.ui.showView(DOUBLES_VIEW)
|
|
3319
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
1465
3320
|
className: "trm-panel-sep"
|
|
1466
3321
|
}), page && room.view && /* @__PURE__ */ React.createElement(SettingRow, {
|
|
1467
3322
|
label: t("openPage", { name: page.title }),
|
|
@@ -1475,7 +3330,7 @@ function MembersView() {
|
|
|
1475
3330
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
1476
3331
|
type: "button",
|
|
1477
3332
|
className: "trm-link trm-danger",
|
|
1478
|
-
onClick: () => void leaveRoom(room).then((
|
|
3333
|
+
onClick: () => void leaveRoom(room).then((left2) => left2 && book.set({ opened: undefined }))
|
|
1479
3334
|
}, room.owner ? t("close") : t("leave"))));
|
|
1480
3335
|
}
|
|
1481
3336
|
|
|
@@ -1483,6 +3338,15 @@ function MembersView() {
|
|
|
1483
3338
|
function plain(text) {
|
|
1484
3339
|
return text.replace(/```[\s\S]*?(```|$)/g, " ").replace(/[*_~`>#]+/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\s+/g, " ").trim();
|
|
1485
3340
|
}
|
|
3341
|
+
function roomPreview(room, last) {
|
|
3342
|
+
if (!last) {
|
|
3343
|
+
return statusLine(room);
|
|
3344
|
+
}
|
|
3345
|
+
const self = room.members.find((each) => each.self)?.member;
|
|
3346
|
+
const person = room.members.find((each) => each.member === last.from)?.name ?? last.name;
|
|
3347
|
+
const name = last.agent?.name ?? (!last.double ? person : last.from === self ? dt("myDouble") : dt("doubleOf", { name: person }));
|
|
3348
|
+
return last.from === self && !last.agent && !last.double ? plain(last.text) : t("said", { name, text: plain(last.text) });
|
|
3349
|
+
}
|
|
1486
3350
|
function lastAt(room) {
|
|
1487
3351
|
const lines = room.status === "member" ? book.chat(room.id)?.lines : undefined;
|
|
1488
3352
|
return lines?.[lines.length - 1]?.at ?? room.joinedAt ?? room.createdAt;
|
|
@@ -1505,10 +3369,8 @@ function RoomRow({ room, active, seen, openMenu }) {
|
|
|
1505
3369
|
const page = usePageOf(room);
|
|
1506
3370
|
const member = room.status === "member";
|
|
1507
3371
|
const last = lines[lines.length - 1];
|
|
1508
|
-
const self = room.members.find((each) => each.self)?.member;
|
|
1509
3372
|
const unread = member && unseen(room, lines, seen);
|
|
1510
|
-
const
|
|
1511
|
-
const preview = last ? last.from === self ? plain(last.text) : t("said", { name: name ?? "", text: plain(last.text) }) : statusLine(room);
|
|
3373
|
+
const preview = roomPreview(room, last);
|
|
1512
3374
|
const menu = [
|
|
1513
3375
|
member ? [
|
|
1514
3376
|
...room.owner ? [{ key: "invite", label: t("invite"), icon: icon("UserPlus"), run: () => openInvite(room) }] : [],
|
|
@@ -1539,46 +3401,26 @@ function RoomRow({ room, active, seen, openMenu }) {
|
|
|
1539
3401
|
className: "trm-room-line"
|
|
1540
3402
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
1541
3403
|
className: "trm-room-name trm-ellipsis"
|
|
1542
|
-
}, room.title),
|
|
1543
|
-
className: "trm-kind"
|
|
1544
|
-
}, page.title), /* @__PURE__ */ React.createElement("span", {
|
|
3404
|
+
}, room.title), /* @__PURE__ */ React.createElement("span", {
|
|
1545
3405
|
className: "trm-room-time"
|
|
1546
3406
|
}, when(lastAt(room)))), /* @__PURE__ */ React.createElement("span", {
|
|
1547
3407
|
className: `trm-room-preview trm-ellipsis${member ? "" : " trm-quiet"}`
|
|
1548
3408
|
}, preview))));
|
|
1549
3409
|
}
|
|
1550
|
-
function FriendRow({ friend, openMenu }) {
|
|
1551
|
-
const Remove = icon("Trash2");
|
|
1552
|
-
const remove = () => void confirmThen(t("removeFriendTitle", { name: friend.name }), t("removeFriendHint"), t("removeFriend"), async () => rooms()?.removeFriend(friend.id));
|
|
1553
|
-
return /* @__PURE__ */ React.createElement("li", {
|
|
1554
|
-
className: "trm-friend",
|
|
1555
|
-
onContextMenu: (event) => openMenu(event, [[{ key: "remove", label: t("removeFriend"), icon: Remove, danger: true, run: remove }]])
|
|
1556
|
-
}, /* @__PURE__ */ React.createElement(Face, {
|
|
1557
|
-
id: friend.id,
|
|
1558
|
-
name: friend.name,
|
|
1559
|
-
size: 36
|
|
1560
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
1561
|
-
className: "trm-room-text"
|
|
1562
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
1563
|
-
className: "trm-room-name trm-ellipsis"
|
|
1564
|
-
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
1565
|
-
className: "trm-room-preview trm-ellipsis"
|
|
1566
|
-
}, t("friendLine", { rooms: friend.rooms.slice(-3).reverse().join("、") }))), /* @__PURE__ */ React.createElement("button", {
|
|
1567
|
-
type: "button",
|
|
1568
|
-
className: "trm-icon trm-danger trm-hover-only",
|
|
1569
|
-
title: t("removeFriend"),
|
|
1570
|
-
"aria-label": t("removeFriend"),
|
|
1571
|
-
onClick: remove
|
|
1572
|
-
}, /* @__PURE__ */ React.createElement(Remove, {
|
|
1573
|
-
size: 15
|
|
1574
|
-
})));
|
|
1575
|
-
}
|
|
1576
3410
|
function RoomList({ openMenu }) {
|
|
1577
|
-
const { identity, rooms: list, requests,
|
|
3411
|
+
const { identity, rooms: list, requests, opened, seen } = useBook();
|
|
3412
|
+
const { asks } = useDoubles();
|
|
1578
3413
|
const sorted = useSorted(list ?? []);
|
|
1579
3414
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1580
3415
|
className: "trm-list"
|
|
1581
|
-
},
|
|
3416
|
+
}, asks.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
3417
|
+
className: "trm-section"
|
|
3418
|
+
}, /* @__PURE__ */ React.createElement("h3", null, dt("asksTitle")), /* @__PURE__ */ React.createElement("ul", {
|
|
3419
|
+
className: "trm-card"
|
|
3420
|
+
}, asks.map((ask) => /* @__PURE__ */ React.createElement(AskRow, {
|
|
3421
|
+
key: ask.id,
|
|
3422
|
+
ask
|
|
3423
|
+
})))), requests.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
1582
3424
|
className: "trm-section"
|
|
1583
3425
|
}, /* @__PURE__ */ React.createElement("h3", null, t("requests")), /* @__PURE__ */ React.createElement("ul", {
|
|
1584
3426
|
className: "trm-card"
|
|
@@ -1587,11 +3429,13 @@ function RoomList({ openMenu }) {
|
|
|
1587
3429
|
request
|
|
1588
3430
|
})))), /* @__PURE__ */ React.createElement("section", {
|
|
1589
3431
|
className: "trm-section"
|
|
1590
|
-
}, list === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
3432
|
+
}, /* @__PURE__ */ React.createElement("h3", null, t("roomsTitle")), list === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
1591
3433
|
rows: 3
|
|
1592
|
-
}) : null : sorted.length === 0 ? /* @__PURE__ */ React.createElement(
|
|
1593
|
-
|
|
1594
|
-
|
|
3434
|
+
}) : null : sorted.length === 0 ? /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3435
|
+
compact: true,
|
|
3436
|
+
title: t("emptyTitle"),
|
|
3437
|
+
hint: t("emptyListHint")
|
|
3438
|
+
}) : /* @__PURE__ */ React.createElement("ul", {
|
|
1595
3439
|
className: "trm-rooms"
|
|
1596
3440
|
}, sorted.map((room) => /* @__PURE__ */ React.createElement(RoomRow, {
|
|
1597
3441
|
key: room.id,
|
|
@@ -1599,15 +3443,7 @@ function RoomList({ openMenu }) {
|
|
|
1599
3443
|
active: room.id === opened,
|
|
1600
3444
|
seen,
|
|
1601
3445
|
openMenu
|
|
1602
|
-
})))),
|
|
1603
|
-
className: "trm-section"
|
|
1604
|
-
}, /* @__PURE__ */ React.createElement("h3", null, t("friends")), /* @__PURE__ */ React.createElement("ul", {
|
|
1605
|
-
className: "trm-rooms"
|
|
1606
|
-
}, friends.map((friend) => /* @__PURE__ */ React.createElement(FriendRow, {
|
|
1607
|
-
key: friend.id,
|
|
1608
|
-
friend,
|
|
1609
|
-
openMenu
|
|
1610
|
-
})))), identity && /* @__PURE__ */ React.createElement("p", {
|
|
3446
|
+
})))), /* @__PURE__ */ React.createElement(FriendsEntry, null), identity && /* @__PURE__ */ React.createElement("p", {
|
|
1611
3447
|
className: "trm-me"
|
|
1612
3448
|
}, t("meLine", { name: identity.name }), /* @__PURE__ */ React.createElement("button", {
|
|
1613
3449
|
type: "button",
|
|
@@ -1622,7 +3458,11 @@ function addMenu() {
|
|
|
1622
3458
|
{ key: "link", label: t("joinByLink"), icon: icon("Link"), run: () => void pasteLink() },
|
|
1623
3459
|
...pi.ui.scanCode ? [{ key: "scan", label: t("scan"), icon: icon("ScanLine"), run: () => void scanLink() }] : []
|
|
1624
3460
|
],
|
|
1625
|
-
[{ key: "
|
|
3461
|
+
[{ key: "friend", label: t("addFriend"), icon: icon("UserPlus"), run: openAddFriend }],
|
|
3462
|
+
[
|
|
3463
|
+
{ key: "name", label: t("me"), icon: icon("Pencil"), run: () => void rename() },
|
|
3464
|
+
{ key: "doubles", label: dt("log"), icon: icon("Bot"), run: () => void pi.ui.showView(DOUBLES_VIEW) }
|
|
3465
|
+
]
|
|
1626
3466
|
];
|
|
1627
3467
|
}
|
|
1628
3468
|
function RoomsHead() {
|
|
@@ -1630,35 +3470,54 @@ function RoomsHead() {
|
|
|
1630
3470
|
const opened = useOpened();
|
|
1631
3471
|
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
1632
3472
|
const Plus = icon("Plus");
|
|
1633
|
-
|
|
3473
|
+
const add = rooms() && /* @__PURE__ */ React.createElement("button", {
|
|
3474
|
+
type: "button",
|
|
3475
|
+
className: "trm-icon",
|
|
3476
|
+
title: t("add"),
|
|
3477
|
+
"aria-label": t("add"),
|
|
3478
|
+
onClick: (event) => openMenu(event, addMenu())
|
|
3479
|
+
}, /* @__PURE__ */ React.createElement(Plus, {
|
|
3480
|
+
size: 18
|
|
3481
|
+
}));
|
|
3482
|
+
if (compact && opened && (pi.ui.Stack || book.get().direct)) {
|
|
1634
3483
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1635
3484
|
className: "trm-head"
|
|
1636
|
-
}, /* @__PURE__ */ React.createElement(
|
|
3485
|
+
}, /* @__PURE__ */ React.createElement(RoomHead, {
|
|
1637
3486
|
room: opened
|
|
1638
|
-
})
|
|
3487
|
+
}));
|
|
3488
|
+
}
|
|
3489
|
+
if (compact) {
|
|
3490
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
3491
|
+
className: "trm-head trm-head-center"
|
|
3492
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3493
|
+
className: "trm-head-title"
|
|
3494
|
+
}, t("roomsTitle")), /* @__PURE__ */ React.createElement("span", {
|
|
1639
3495
|
className: "trm-head-end"
|
|
1640
|
-
},
|
|
3496
|
+
}, add), menu);
|
|
1641
3497
|
}
|
|
1642
3498
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1643
|
-
className: "trm-head"
|
|
3499
|
+
className: "trm-head trm-head-split"
|
|
3500
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3501
|
+
className: "trm-head-list"
|
|
1644
3502
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
1645
3503
|
className: "trm-head-title"
|
|
1646
|
-
}, t("roomsTitle")),
|
|
1647
|
-
className: "trm-head-
|
|
1648
|
-
}, /* @__PURE__ */ React.createElement(
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
title: t("add"),
|
|
1652
|
-
"aria-label": t("add"),
|
|
1653
|
-
onClick: (event) => openMenu(event, addMenu())
|
|
1654
|
-
}, /* @__PURE__ */ React.createElement(Plus, {
|
|
1655
|
-
size: 18
|
|
1656
|
-
}))), menu);
|
|
3504
|
+
}, t("roomsTitle")), add), /* @__PURE__ */ React.createElement("div", {
|
|
3505
|
+
className: "trm-head-room"
|
|
3506
|
+
}, opened && /* @__PURE__ */ React.createElement(RoomHead, {
|
|
3507
|
+
room: opened
|
|
3508
|
+
})), menu);
|
|
1657
3509
|
}
|
|
1658
3510
|
function RoomsPage() {
|
|
1659
3511
|
const compact = useCompact();
|
|
1660
3512
|
const opened = useOpened();
|
|
1661
3513
|
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
3514
|
+
const { direct } = useBook();
|
|
3515
|
+
const shownPage = pi.ui.useView?.(ROOMS_VIEW)?.shown;
|
|
3516
|
+
React.useEffect(() => {
|
|
3517
|
+
if (shownPage === false && direct) {
|
|
3518
|
+
book.set({ opened: undefined, direct: false });
|
|
3519
|
+
}
|
|
3520
|
+
}, [shownPage, direct]);
|
|
1662
3521
|
const [kept, setKept] = React.useState();
|
|
1663
3522
|
React.useEffect(() => {
|
|
1664
3523
|
if (opened) {
|
|
@@ -1687,10 +3546,17 @@ function RoomsPage() {
|
|
|
1687
3546
|
}, opened ? /* @__PURE__ */ React.createElement(RoomView, {
|
|
1688
3547
|
key: opened.id,
|
|
1689
3548
|
room: opened,
|
|
1690
|
-
head:
|
|
1691
|
-
}) : /* @__PURE__ */ React.createElement(
|
|
1692
|
-
|
|
1693
|
-
}
|
|
3549
|
+
head: false
|
|
3550
|
+
}) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3551
|
+
title: t("pickRoom")
|
|
3552
|
+
})), menu);
|
|
3553
|
+
}
|
|
3554
|
+
if (opened && direct) {
|
|
3555
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RoomView, {
|
|
3556
|
+
key: opened.id,
|
|
3557
|
+
room: opened,
|
|
3558
|
+
head: false
|
|
3559
|
+
}), menu);
|
|
1694
3560
|
}
|
|
1695
3561
|
const Stack = pi.ui.Stack;
|
|
1696
3562
|
const shown = opened ?? kept;
|
|
@@ -1718,38 +3584,183 @@ function RoomsPage() {
|
|
|
1718
3584
|
}), menu);
|
|
1719
3585
|
}
|
|
1720
3586
|
|
|
3587
|
+
// web-src/rooms-home.tsx
|
|
3588
|
+
var HOME_KEY = "home.rooms";
|
|
3589
|
+
function homeFace(id) {
|
|
3590
|
+
return function HomeFace({ size }) {
|
|
3591
|
+
const room = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get().rooms?.find((each) => each.id === id));
|
|
3592
|
+
return room ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
3593
|
+
room,
|
|
3594
|
+
size
|
|
3595
|
+
}) : null;
|
|
3596
|
+
};
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
class RoomsHome {
|
|
3600
|
+
current = [];
|
|
3601
|
+
signature = "";
|
|
3602
|
+
shown = true;
|
|
3603
|
+
listeners = new Set;
|
|
3604
|
+
chats = new Map;
|
|
3605
|
+
faces = new Map;
|
|
3606
|
+
items = () => this.current;
|
|
3607
|
+
subscribe = (listener) => {
|
|
3608
|
+
this.listeners.add(listener);
|
|
3609
|
+
return () => this.listeners.delete(listener);
|
|
3610
|
+
};
|
|
3611
|
+
start() {
|
|
3612
|
+
const stopBook = book.subscribe(() => this.refresh());
|
|
3613
|
+
const stopStorage = pi.storage.onChange((keys) => keys.includes(HOME_KEY) && this.readShown());
|
|
3614
|
+
this.readShown();
|
|
3615
|
+
this.refresh();
|
|
3616
|
+
return () => {
|
|
3617
|
+
stopBook();
|
|
3618
|
+
stopStorage();
|
|
3619
|
+
for (const stop of this.chats.values()) {
|
|
3620
|
+
stop();
|
|
3621
|
+
}
|
|
3622
|
+
this.chats.clear();
|
|
3623
|
+
};
|
|
3624
|
+
}
|
|
3625
|
+
readShown() {
|
|
3626
|
+
pi.storage.get(HOME_KEY).then((value) => {
|
|
3627
|
+
this.shown = value !== false;
|
|
3628
|
+
this.refresh();
|
|
3629
|
+
}, () => {
|
|
3630
|
+
return;
|
|
3631
|
+
});
|
|
3632
|
+
}
|
|
3633
|
+
refresh() {
|
|
3634
|
+
const { rooms: rooms2 = [], seen } = book.get();
|
|
3635
|
+
const joined = this.shown ? rooms2.filter((room) => room.status === "member") : [];
|
|
3636
|
+
this.follow(joined);
|
|
3637
|
+
const rows = joined.map((room) => ({ room, lines: book.chat(room.id)?.lines ?? [] })).sort((a, b) => lastAt(b.room) - lastAt(a.room));
|
|
3638
|
+
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("|");
|
|
3639
|
+
if (signature === this.signature) {
|
|
3640
|
+
return;
|
|
3641
|
+
}
|
|
3642
|
+
this.signature = signature;
|
|
3643
|
+
this.current = rows.map(({ room, lines }) => this.item(room, lines, unseen(room, lines, seen)));
|
|
3644
|
+
for (const listener of this.listeners) {
|
|
3645
|
+
listener();
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
item(room, lines, fresh) {
|
|
3649
|
+
let face = this.faces.get(room.id);
|
|
3650
|
+
if (!face) {
|
|
3651
|
+
face = homeFace(room.id);
|
|
3652
|
+
this.faces.set(room.id, face);
|
|
3653
|
+
}
|
|
3654
|
+
return {
|
|
3655
|
+
id: room.id,
|
|
3656
|
+
title: room.title,
|
|
3657
|
+
detail: roomPreview(room, lines.at(-1)),
|
|
3658
|
+
icon: icon("Users"),
|
|
3659
|
+
face,
|
|
3660
|
+
section: t("roomsTitle"),
|
|
3661
|
+
at: lastAt(room),
|
|
3662
|
+
unseen: fresh,
|
|
3663
|
+
open: () => openRoom(room.id, true)
|
|
3664
|
+
};
|
|
3665
|
+
}
|
|
3666
|
+
follow(joined) {
|
|
3667
|
+
const ids = new Set(joined.map((room) => room.id));
|
|
3668
|
+
for (const [id, stop] of this.chats) {
|
|
3669
|
+
if (!ids.has(id)) {
|
|
3670
|
+
stop();
|
|
3671
|
+
this.chats.delete(id);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
for (const room of joined) {
|
|
3675
|
+
if (!this.chats.has(room.id)) {
|
|
3676
|
+
const stop = book.chat(room.id)?.subscribe(() => this.refresh());
|
|
3677
|
+
this.chats.set(room.id, stop ?? (() => {
|
|
3678
|
+
return;
|
|
3679
|
+
}));
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
function HomeSwitch() {
|
|
3685
|
+
const [on, setOn] = React.useState(true);
|
|
3686
|
+
React.useEffect(() => {
|
|
3687
|
+
let live = true;
|
|
3688
|
+
const read = () => void pi.storage.get(HOME_KEY).then((value) => live && setOn(value !== false), () => {
|
|
3689
|
+
return;
|
|
3690
|
+
});
|
|
3691
|
+
read();
|
|
3692
|
+
const stop = pi.storage.onChange((keys) => keys.includes(HOME_KEY) && read());
|
|
3693
|
+
return () => {
|
|
3694
|
+
live = false;
|
|
3695
|
+
stop();
|
|
3696
|
+
};
|
|
3697
|
+
}, []);
|
|
3698
|
+
const change = (next) => {
|
|
3699
|
+
setOn(next);
|
|
3700
|
+
return pi.storage.set(HOME_KEY, next).catch((error) => {
|
|
3701
|
+
setOn(!next);
|
|
3702
|
+
pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
3703
|
+
});
|
|
3704
|
+
};
|
|
3705
|
+
const Switch = pi.ui.Switch;
|
|
3706
|
+
return Switch ? /* @__PURE__ */ React.createElement(Switch, {
|
|
3707
|
+
checked: on,
|
|
3708
|
+
label: t("showOnHome"),
|
|
3709
|
+
onChange: change
|
|
3710
|
+
}) : /* @__PURE__ */ React.createElement("input", {
|
|
3711
|
+
type: "checkbox",
|
|
3712
|
+
role: "switch",
|
|
3713
|
+
className: "ta-switch",
|
|
3714
|
+
checked: on,
|
|
3715
|
+
"aria-checked": on,
|
|
3716
|
+
"aria-label": t("showOnHome"),
|
|
3717
|
+
onChange: (event) => void change(event.target.checked)
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
function roomsSettings() {
|
|
3721
|
+
return {
|
|
3722
|
+
title: () => t("roomsTitle"),
|
|
3723
|
+
icon: icon("Users"),
|
|
3724
|
+
rows: [{ key: "home", label: () => t("showOnHome"), description: () => t("showOnHomeHint"), render: HomeSwitch }]
|
|
3725
|
+
};
|
|
3726
|
+
}
|
|
3727
|
+
|
|
1721
3728
|
// web-src/style.ts
|
|
1722
3729
|
var STYLE = `
|
|
1723
3730
|
.trm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1724
3731
|
.trm-quiet { color: var(--ta-muted); }
|
|
1725
|
-
/* The head of the page (RoomsHead): the
|
|
1726
|
-
.trm-head { position: relative; display: flex; align-items: center;
|
|
3732
|
+
/* The head of the page (RoomsHead): over the list and the room on a computer, as the sidebar and a channel's head */
|
|
3733
|
+
.trm-head { position: relative; display: flex; align-items: center; flex: 1; min-width: 0; height: 100%; }
|
|
3734
|
+
.trm-head-center { justify-content: center; padding: 0 44px; }
|
|
1727
3735
|
.trm-head-title { font-weight: 600; font-size: calc(14.5px * var(--ta-font-scale)); }
|
|
1728
3736
|
.trm-head-end { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; }
|
|
1729
|
-
.
|
|
1730
|
-
|
|
3737
|
+
.ta-main-head:has(.trm-head-split) { padding-left: 0; }
|
|
3738
|
+
.ta-main-head-view:has(.trm-head-split) { align-self: stretch; }
|
|
3739
|
+
.trm-head-split { align-items: stretch; }
|
|
3740
|
+
.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); }
|
|
3741
|
+
.trm-head-room { flex: 1; min-width: 0; display: flex; align-items: center; padding-left: 20px; }
|
|
3742
|
+
/* The list, as the sidebar of the double: faces, a name and when, a line under it */
|
|
1731
3743
|
.trm-page { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: none; }
|
|
1732
3744
|
.trm-page > .trm-list { max-width: 720px; margin: 0 auto; }
|
|
1733
|
-
.trm-list { display: flex; flex-direction: column; gap:
|
|
1734
|
-
.trm-section h3 { margin:
|
|
1735
|
-
.trm-
|
|
1736
|
-
.trm-card {
|
|
1737
|
-
.trm-
|
|
1738
|
-
.trm-
|
|
1739
|
-
.trm-room { display: flex; align-items: center; gap: 12px; width: 100%; 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; }
|
|
3745
|
+
.trm-list { display: flex; flex-direction: column; gap: 10px; padding: 4px 10px calc(24px + env(safe-area-inset-bottom)); box-sizing: border-box; }
|
|
3746
|
+
.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); }
|
|
3747
|
+
.trm-card { margin: 0; padding: 2px 6px; list-style: none; border-radius: 14px; background: var(--ta-raised); }
|
|
3748
|
+
.trm-card .trm-row { padding: 10px 4px; }
|
|
3749
|
+
.trm-rooms { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
|
|
3750
|
+
.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; }
|
|
1740
3751
|
@media (hover: hover) { .trm-room:hover, .trm-friend:hover, li.trm-member:hover, button.trm-member:hover { background: var(--ta-hover); } }
|
|
1741
3752
|
.trm-room:active { background: var(--ta-hover); }
|
|
1742
3753
|
.trm-room.trm-active { background: var(--ta-selected, var(--ta-hover-strong)); }
|
|
1743
3754
|
.trm-room:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
|
|
1744
|
-
.trm-room-out { opacity: .
|
|
3755
|
+
.trm-room-out { opacity: .55; }
|
|
1745
3756
|
.trm-room-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
|
|
1746
|
-
.trm-room-line { display: flex; align-items:
|
|
1747
|
-
.trm-room-name { flex: 0 1 auto; font-size: calc(
|
|
1748
|
-
.trm-room-time { flex: none; margin-left: auto; padding-left:
|
|
1749
|
-
.trm-room-preview { color: var(--ta-muted); font-size: calc(
|
|
1750
|
-
.trm-
|
|
1751
|
-
.trm-tag-friend { background: var(--ta-
|
|
1752
|
-
.trm-friend { display: flex; align-items: center; gap: 12px; padding:
|
|
3757
|
+
.trm-room-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
3758
|
+
.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)); }
|
|
3759
|
+
.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; }
|
|
3760
|
+
.trm-room-preview { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(17px * var(--ta-font-scale)); }
|
|
3761
|
+
.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)); }
|
|
3762
|
+
.trm-tag-friend { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
|
|
3763
|
+
.trm-friend { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 9px 10px; box-sizing: border-box; border-radius: 12px; }
|
|
1753
3764
|
.trm-hover-only { opacity: 0; transition: opacity 120ms; }
|
|
1754
3765
|
.trm-friend:hover .trm-hover-only, .trm-hover-only:focus-visible { opacity: 1; }
|
|
1755
3766
|
@media (hover: none) { .trm-hover-only { display: none; } }
|
|
@@ -1757,54 +3768,61 @@ var STYLE = `
|
|
|
1757
3768
|
.trm-link { padding: 2px 4px; border: 0; border-radius: 6px; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
|
|
1758
3769
|
.trm-link:hover { background: var(--ta-hover); }
|
|
1759
3770
|
.trm-link.trm-danger { color: var(--ta-red); }
|
|
1760
|
-
/* The faces: of
|
|
3771
|
+
/* The faces: those of channels (ui.Face), or a letter in a circle in an app of before */
|
|
3772
|
+
.ta-face { --ta-face-ring: var(--ta-side); }
|
|
3773
|
+
.trm-chat .ta-face, .trm-panel .ta-face, .trm-head .ta-face { --ta-face-ring: var(--ta-main); }
|
|
1761
3774
|
.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; }
|
|
1762
3775
|
.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); }
|
|
1763
3776
|
.trm-on { background: var(--ta-green); }
|
|
1764
3777
|
.trm-off { background: var(--ta-border-field); }
|
|
1765
|
-
.trm-room-face { position: relative; flex: none; display:
|
|
1766
|
-
.trm-room-face
|
|
1767
|
-
.trm-
|
|
1768
|
-
|
|
1769
|
-
.trm-
|
|
1770
|
-
.trm-
|
|
1771
|
-
.trm-unread { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--ta-yellow); box-shadow: 0 0 0 2px var(--ta-main); }
|
|
1772
|
-
/* Beside each other, on a computer or a tablet */
|
|
1773
|
-
.trm-split { display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); flex: 1; min-height: 0; height: 100%; }
|
|
1774
|
-
.trm-split-list { min-height: 0; overflow-y: auto; overscroll-behavior: none; border-right: 1px solid var(--ta-border-muted); }
|
|
3778
|
+
.trm-room-face { position: relative; flex: none; display: inline-flex; }
|
|
3779
|
+
.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); }
|
|
3780
|
+
.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); }
|
|
3781
|
+
/* Beside each other, on a computer or a tablet: the list on the colour of the sidebar */
|
|
3782
|
+
.trm-split { display: grid; grid-template-columns: 320px minmax(0, 1fr); flex: 1; min-height: 0; height: 100%; }
|
|
3783
|
+
.trm-split-list { min-height: 0; overflow-y: auto; overscroll-behavior: none; background: var(--ta-side); border-right: 1px solid var(--ta-border-muted); }
|
|
1775
3784
|
.trm-split-room { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
|
|
1776
|
-
|
|
1777
|
-
/* A room (room-view.tsx): a group chat, its head and its box */
|
|
3785
|
+
/* A room (room-view.tsx): a group chat, as a channel */
|
|
1778
3786
|
.trm-room-page { display: flex; flex-direction: column; flex: 1; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); }
|
|
1779
|
-
.trm-room-
|
|
1780
|
-
.trm-room-head
|
|
1781
|
-
.trm-room-title { display: flex;
|
|
1782
|
-
.trm-room-title
|
|
1783
|
-
.trm-
|
|
1784
|
-
.trm-room-
|
|
1785
|
-
.trm-room-sub { color: var(--ta-
|
|
1786
|
-
.trm-
|
|
3787
|
+
.trm-room-bar { flex: none; display: flex; align-items: center; gap: 6px; min-height: 52px; padding: 6px 12px; box-sizing: border-box; }
|
|
3788
|
+
.trm-room-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
|
|
3789
|
+
.trm-room-head-title { display: flex; align-items: baseline; gap: 8px; flex: 1; min-width: 0; white-space: nowrap; }
|
|
3790
|
+
.trm-room-head-title strong { font-size: calc(14.5px * var(--ta-font-scale)); font-weight: 600; }
|
|
3791
|
+
.trm-room-head-count { flex: none; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
3792
|
+
.trm-room-head-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ta-green); font-size: calc(12px * var(--ta-font-scale)); }
|
|
3793
|
+
.trm-room-head-sub.trm-quiet { color: var(--ta-muted); }
|
|
3794
|
+
.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; }
|
|
3795
|
+
.trm-faces.trm-on-icon { background: var(--ta-hover); }
|
|
3796
|
+
@media (hover: hover) { .trm-faces:hover { background: var(--ta-hover); } .trm-faces:hover .trm-faces-one { background: var(--ta-hover); } }
|
|
3797
|
+
.trm-faces-one { display: inline-flex; margin-left: -4px; padding: 1px; border-radius: 50%; background: var(--ta-main); }
|
|
3798
|
+
.trm-faces.trm-on-icon .trm-faces-one { background: var(--ta-hover); }
|
|
3799
|
+
.trm-faces-more { margin-left: 4px; font-size: calc(12px * var(--ta-font-scale)); }
|
|
1787
3800
|
.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; }
|
|
1788
|
-
.trm-icon:hover:not(:disabled)
|
|
3801
|
+
.trm-icon:hover:not(:disabled) { background: var(--ta-hover-strong); color: var(--ta-text); }
|
|
1789
3802
|
.trm-icon.trm-danger:hover:not(:disabled) { color: var(--ta-red); }
|
|
1790
|
-
.trm-page-line { flex: none; display: flex; align-items: center; gap: 10px; width: calc(100% -
|
|
3803
|
+
.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; }
|
|
1791
3804
|
.trm-page-line:hover { background: var(--ta-hover); }
|
|
1792
3805
|
.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); }
|
|
1793
3806
|
.trm-page-line-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-secondary); }
|
|
1794
3807
|
.trm-page-line-open { display: inline-flex; align-items: center; gap: 2px; flex: none; color: var(--ta-link); font-weight: 500; }
|
|
1795
3808
|
.trm-chat { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none; overscroll-behavior: none; }
|
|
1796
|
-
.trm-chat-col { display: flex; flex-direction: column; gap: 4px; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding:
|
|
3809
|
+
.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; }
|
|
1797
3810
|
.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; }
|
|
1798
|
-
.trm-chat-empty { margin:
|
|
3811
|
+
.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; }
|
|
3812
|
+
.trm-chat-empty strong { margin-top: 6px; color: var(--ta-text); font-size: calc(16px * var(--ta-font-scale)); }
|
|
3813
|
+
.trm-chat-hint { margin-top: 4px; font-size: calc(12px * var(--ta-font-scale)); line-height: 1.6; }
|
|
1799
3814
|
.trm-mine { margin: 6px 0 2px; }
|
|
1800
3815
|
.trm-msg { display: flex; align-items: flex-start; gap: 10px; }
|
|
1801
3816
|
.trm-msg.trm-first { margin-top: 10px; }
|
|
1802
|
-
.trm-msg-face { display: flex; justify-content: center; width:
|
|
3817
|
+
.trm-msg-face { display: flex; justify-content: center; width: 28px; flex: none; }
|
|
1803
3818
|
.trm-msg-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(84%, var(--ta-col)); }
|
|
1804
3819
|
.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)); }
|
|
1805
3820
|
.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; }
|
|
1806
3821
|
.trm-msg-bubble pre { max-width: 100%; overflow-x: auto; }
|
|
1807
3822
|
.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; }
|
|
3823
|
+
/* Above the keyboard the home indicator is not there: no room for it, as under the box of a conversation. */
|
|
3824
|
+
:root[data-keyboard] .trm-chat-bottom { padding-bottom: 8px; }
|
|
3825
|
+
:root[data-keyboard-moving] .trm-chat-bottom { transition: padding-bottom 450ms cubic-bezier(0.15, 0.75, 0.2, 1); }
|
|
1808
3826
|
/* The members of the room shown (members-view.tsx), in the workbench */
|
|
1809
3827
|
.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)); }
|
|
1810
3828
|
.trm-panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }
|
|
@@ -1847,16 +3865,81 @@ button.trm-member { cursor: pointer; }
|
|
|
1847
3865
|
.trm-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
|
|
1848
3866
|
.trm-center { justify-content: center; }
|
|
1849
3867
|
.trm-join { display: flex; align-items: center; gap: 12px; }
|
|
3868
|
+
.trm-friends-page { max-width: 720px; margin: 0 auto; width: 100%; overflow-y: auto; height: 100%; }
|
|
3869
|
+
.trm-friends-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0 20px; }
|
|
3870
|
+
.trm-friends-other { gap: 18px; padding-top: 4px; }
|
|
3871
|
+
.trm-friends-entry { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--ta-surface, transparent); color: inherit; font: inherit; cursor: pointer; text-align: left; }
|
|
3872
|
+
@media (hover: hover) { .trm-friends-entry:hover { background: var(--ta-hover); } }
|
|
3873
|
+
.trm-friends-entry-label { font-weight: 500; }
|
|
3874
|
+
.trm-grow { flex: 1; }
|
|
3875
|
+
.trm-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ta-amber, #f5a524); }
|
|
3876
|
+
.trm-join-name { font-size: calc(15px * var(--ta-font-scale)); }
|
|
3877
|
+
.trm-dialog .trm-join:has(.trm-join-name) { flex-direction: column; text-align: center; gap: 8px; }
|
|
3878
|
+
.trm-member-friend { color: var(--ta-muted); }
|
|
1850
3879
|
.trm-invite { align-items: stretch; }
|
|
1851
3880
|
.trm-qr { align-self: center; width: 188px; padding: 10px; border-radius: 14px; background: #fff; border: 1px solid var(--ta-border-muted); }
|
|
1852
3881
|
.trm-qr svg { display: block; width: 100%; height: auto; }
|
|
1853
3882
|
.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; }
|
|
1854
3883
|
.trm-dialog .trm-row { padding: 8px 0; }
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
}
|
|
3884
|
+
/* The doubles (docs/design/ta-link.md 4): what a double says, its permissions, its log */
|
|
3885
|
+
.trm-tag-double { margin-left: 6px; background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
|
|
3886
|
+
.trm-double .trm-msg-bubble { border-style: dashed; background: var(--ta-main); }
|
|
3887
|
+
.trm-tag-agent { margin-left: 6px; background: var(--ta-tint-5); color: var(--ta-tint-ink-5); }
|
|
3888
|
+
.trm-member-name .trm-tag-agent { margin-left: 0; }
|
|
3889
|
+
.trm-tag-task { margin-left: 6px; background: var(--ta-tint-0); color: var(--ta-tint-ink-0); }
|
|
3890
|
+
.trm-task-line { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--ta-secondary); font-size: calc(12px * var(--ta-font-scale)); }
|
|
3891
|
+
.trm-task-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ta-secondary); flex: none; }
|
|
3892
|
+
.trm-task-running .trm-task-dot, .trm-task-queued .trm-task-dot, .trm-task-sent .trm-task-dot { background: var(--ta-green); animation: trm-breathe 1.6s ease-in-out infinite; }
|
|
3893
|
+
.trm-task-permission .trm-task-dot { background: var(--ta-yellow); }
|
|
3894
|
+
.trm-task-done .trm-task-dot { background: var(--ta-green); }
|
|
3895
|
+
.trm-task-failed .trm-task-dot, .trm-task-declined .trm-task-dot { background: var(--ta-red); }
|
|
3896
|
+
@keyframes trm-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
|
|
3897
|
+
.trm-task-card { margin: 4px 0; border: 1px solid var(--ta-border); border-radius: 12px; background: var(--ta-card); overflow: hidden; max-width: 560px; }
|
|
3898
|
+
.trm-task-card-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
|
3899
|
+
.trm-task-card-head:hover { background: var(--ta-hover); }
|
|
3900
|
+
.trm-task-card-title { flex: 1; min-width: 0; font-weight: 500; }
|
|
3901
|
+
.trm-task-chip { flex: none; padding: 0 7px; border-radius: 6px; background: var(--ta-chip, var(--ta-hover)); color: var(--ta-secondary); font-size: calc(11px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); }
|
|
3902
|
+
.trm-task-done .trm-task-chip { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
|
|
3903
|
+
.trm-task-failed .trm-task-chip, .trm-task-declined .trm-task-chip { background: color-mix(in srgb, var(--ta-red) 12%, transparent); color: var(--ta-red); }
|
|
3904
|
+
.trm-task-card-text { padding: 0 12px 8px; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); }
|
|
3905
|
+
.trm-task-card-answer { padding: 8px 12px; border-top: 1px solid var(--ta-border); }
|
|
3906
|
+
.trm-try-alone { margin-top: 12px; }
|
|
3907
|
+
.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)); }
|
|
3908
|
+
.trm-agent-pick .trm-member:disabled { cursor: default; opacity: 1; }
|
|
3909
|
+
.trm-agent-pick .trm-member:disabled .trm-member-detail { color: var(--ta-green); }
|
|
3910
|
+
.trm-member-may { color: var(--ta-secondary); }
|
|
3911
|
+
.trm-member-action.trm-on-icon { opacity: 1; color: var(--ta-green); }
|
|
3912
|
+
.trm-double-switch, .trm-grant-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; }
|
|
3913
|
+
.trm-grant-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
|
3914
|
+
.trm-grant-who { display: flex; align-items: center; gap: 12px; }
|
|
3915
|
+
.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; }
|
|
3916
|
+
.trm-grant-list { margin: 0; padding: 4px 0; list-style: none; border: 1px solid var(--ta-border-muted); border-radius: 12px; }
|
|
3917
|
+
.trm-grant-list .trm-grant-item + .trm-grant-item { border-top: 1px solid var(--ta-border-muted); }
|
|
3918
|
+
.trm-grant-field { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
|
3919
|
+
.trm-grant-label { flex: none; width: 56px; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
3920
|
+
.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; }
|
|
3921
|
+
.trm-grant-dir > svg { flex: none; color: var(--ta-muted); }
|
|
3922
|
+
.trm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
3923
|
+
.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; }
|
|
3924
|
+
.trm-chip-on { border-color: var(--ta-green); background: var(--ta-hover); color: var(--ta-text); font-weight: 500; }
|
|
3925
|
+
.trm-panel-note { display: block; margin: 0 10px 8px; }
|
|
3926
|
+
.trm-log-label { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
|
|
3927
|
+
.trm-logs { margin: 0; padding: 0; list-style: none; }
|
|
3928
|
+
.trm-log { display: flex; flex-direction: column; gap: 4px; padding: 10px; border-radius: 12px; }
|
|
3929
|
+
.trm-log + .trm-log { border-top: 1px solid var(--ta-border-muted); border-radius: 0; }
|
|
3930
|
+
.trm-log-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
3931
|
+
.trm-log-who { flex: 1; color: var(--ta-secondary); font-size: calc(12px * var(--ta-font-scale)); }
|
|
3932
|
+
.trm-log-time { flex: none; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
3933
|
+
.trm-log-asked { color: var(--ta-text); line-height: 1.5; overflow-wrap: anywhere; }
|
|
3934
|
+
.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; }
|
|
3935
|
+
.trm-log-meta { color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); }
|
|
3936
|
+
.trm-log-meta.trm-log-bad { color: var(--ta-yellow); }
|
|
3937
|
+
.trm-log-empty { display: flex; flex-direction: column; padding: 12px 0; }
|
|
3938
|
+
[data-layout='compact'] .trm-room-head-sub { display: none; }
|
|
3939
|
+
[data-layout='compact'] .trm-faces.trm-on-icon, [data-layout='compact'] .trm-faces.trm-on-icon .trm-faces-one { background: none; }
|
|
3940
|
+
[data-layout='compact'] .trm-chat-col, [data-layout='compact'] .trm-chat-bottom { padding-left: 12px; padding-right: 12px; }
|
|
3941
|
+
[data-layout='compact'] .trm-msg-col { max-width: calc(100% - 40px); }
|
|
3942
|
+
[data-layout='compact'] .trm-page-line { width: calc(100% - 24px); }
|
|
1860
3943
|
@media (max-width: 480px) { .trm-answers .ta-button { padding-left: 10px; padding-right: 10px; } }
|
|
1861
3944
|
@media (prefers-reduced-motion: reduce) { .trm-room, .trm-page-line { transition: none; } }
|
|
1862
3945
|
`;
|
|
@@ -1896,17 +3979,47 @@ function activate(pi2) {
|
|
|
1896
3979
|
bindPage(pi2);
|
|
1897
3980
|
const removeStyle = injectStyle();
|
|
1898
3981
|
pi2.registerView("rooms", { title: () => t("roomsTitle"), icon: icon("Users"), render: RoomsPage, head: RoomsHead, discover: true, order: 81 });
|
|
3982
|
+
pi2.registerView("friends", { title: () => t("friends"), icon: icon("Contact"), render: FriendsPage, head: FriendsHead, discover: true, order: 79 });
|
|
1899
3983
|
pi2.registerView("members", { title: () => t("membersTitle"), icon: icon("Users"), render: MembersView, location: "panel", order: 90 });
|
|
3984
|
+
pi2.registerView(DOUBLES_VIEW.slice(DOUBLES_VIEW.lastIndexOf("/") + 1), {
|
|
3985
|
+
title: () => dt("logTitle"),
|
|
3986
|
+
icon: icon("Bot"),
|
|
3987
|
+
render: DoublesView,
|
|
3988
|
+
location: "panel",
|
|
3989
|
+
order: 91
|
|
3990
|
+
});
|
|
3991
|
+
pi2.registerSettings(roomsSettings());
|
|
3992
|
+
const home = new RoomsHome;
|
|
3993
|
+
const stopHome = pi2.rooms ? home.start() : () => {
|
|
3994
|
+
return;
|
|
3995
|
+
};
|
|
3996
|
+
if (pi2.rooms) {
|
|
3997
|
+
pi2.registerHomeItems?.(home);
|
|
3998
|
+
}
|
|
3999
|
+
const stopAsks = pi2.rooms ? listenAsks() : () => {
|
|
4000
|
+
return;
|
|
4001
|
+
};
|
|
4002
|
+
if (pi2.rooms) {
|
|
4003
|
+
registerTasks();
|
|
4004
|
+
}
|
|
1900
4005
|
pi2.registerOpener((link) => {
|
|
1901
4006
|
if (link.type !== "url" || !RelayHubUtil.is(link.url)) {
|
|
1902
4007
|
return false;
|
|
1903
4008
|
}
|
|
4009
|
+
if (isFriendLink(link.url)) {
|
|
4010
|
+
return openFriendLink(link.url);
|
|
4011
|
+
}
|
|
4012
|
+
if (RelayHubUtil.parse(link.url).kind) {
|
|
4013
|
+
return false;
|
|
4014
|
+
}
|
|
1904
4015
|
openJoin(link.url);
|
|
1905
4016
|
return true;
|
|
1906
4017
|
}, { specific: true });
|
|
1907
4018
|
const stop = pi2.onRoomEvent?.((event) => {
|
|
1908
4019
|
if (event.type === "request") {
|
|
1909
|
-
book.load().then(() => openRequests());
|
|
4020
|
+
book.load().then(() => book.get().requests.length && openRequests());
|
|
4021
|
+
} else if (event.type === "friend") {
|
|
4022
|
+
book.load().then(() => book.get().friendRequests.length && openFriendRequests());
|
|
1910
4023
|
} else if (event.type === "rooms") {
|
|
1911
4024
|
book.reload();
|
|
1912
4025
|
} else {
|
|
@@ -1923,6 +4036,8 @@ function activate(pi2) {
|
|
|
1923
4036
|
}
|
|
1924
4037
|
return () => {
|
|
1925
4038
|
stop?.();
|
|
4039
|
+
stopAsks();
|
|
4040
|
+
stopHome();
|
|
1926
4041
|
book.onChange = undefined;
|
|
1927
4042
|
removeStyle();
|
|
1928
4043
|
};
|