@celljs/ta-rooms 4.23.0 → 4.24.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/extension/index.mjs +75 -11
- package/host/index.mjs +418 -97
- package/package.json +4 -4
- package/web/index.js +332 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-rooms",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.24.0",
|
|
4
4
|
"description": "A pi package for Ta: rooms shared with other Ta through the relay, end to end: who asks to join and the owner's answer, your rooms and their members, your Ta friends, and links that invite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-relay": "4.
|
|
32
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.24.0",
|
|
31
|
+
"@celljs/ta-relay": "4.24.0",
|
|
32
|
+
"@celljs/ta-web": "4.24.0",
|
|
33
33
|
"@types/react": "^19.3.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
package/web/index.js
CHANGED
|
@@ -1313,6 +1313,23 @@ var EN = {
|
|
|
1313
1313
|
unsent: "Not sent: too long",
|
|
1314
1314
|
chatEmpty: "Nothing said yet. Only those in the group chat read it: the relay keeps it sealed.",
|
|
1315
1315
|
chatPlaceholder: "Message",
|
|
1316
|
+
storageTitle: "Storage",
|
|
1317
|
+
storageLead: "Chats on this computer",
|
|
1318
|
+
storageHint: "Pictures and files others sent come again from them when you open them. What you sent stays: others get it from you.",
|
|
1319
|
+
storageTotal: "In all",
|
|
1320
|
+
storageParts: "Messages {said} · pictures and files {media}",
|
|
1321
|
+
storageClearMedia: "Clear pictures and files others sent ({size})",
|
|
1322
|
+
storageOlder: "Clear earlier history",
|
|
1323
|
+
storageOlderTitle: "Clear earlier history with {name}",
|
|
1324
|
+
storageOlderHint: "What was said before then goes from this computer only, a month at a time; the others keep theirs.",
|
|
1325
|
+
storageOlderMonths: "Older than {n} month(s)",
|
|
1326
|
+
storageOlderYear: "Older than a year",
|
|
1327
|
+
storageOlderNone: "Nothing",
|
|
1328
|
+
storageClear: "Clear chat history",
|
|
1329
|
+
storageClearTitle: "Clear the chat history with {name}?",
|
|
1330
|
+
storageClearHint: "It goes from this computer only; the others keep theirs, and it does not come back.",
|
|
1331
|
+
storageFreed: "{size} freed",
|
|
1332
|
+
storageNone: "No chats yet",
|
|
1316
1333
|
file: "[File]",
|
|
1317
1334
|
voice: "[Voice]",
|
|
1318
1335
|
video: "[Video]",
|
|
@@ -1483,6 +1500,23 @@ var ZH = {
|
|
|
1483
1500
|
unsent: "未发出:内容太长",
|
|
1484
1501
|
chatEmpty: "还没有人说话。只有群里的人能看到,中继保存的是密文。",
|
|
1485
1502
|
chatPlaceholder: "发消息",
|
|
1503
|
+
storageTitle: "存储空间",
|
|
1504
|
+
storageLead: "本机的聊天",
|
|
1505
|
+
storageHint: "别人发的图片和文件,清理后再打开会重新从对方那里取;你发的会保留,别人要从你这里取。",
|
|
1506
|
+
storageTotal: "共计",
|
|
1507
|
+
storageParts: "消息 {said} · 图片和文件 {media}",
|
|
1508
|
+
storageClearMedia: "清理别人发的图片和文件({size})",
|
|
1509
|
+
storageOlder: "清理更早的聊天记录",
|
|
1510
|
+
storageOlderTitle: "清理与{name}更早的聊天记录",
|
|
1511
|
+
storageOlderHint: "按月清理,只删本机的,其他人的不受影响,删了不能恢复。",
|
|
1512
|
+
storageOlderMonths: "{n} 个月以前",
|
|
1513
|
+
storageOlderYear: "一年以前",
|
|
1514
|
+
storageOlderNone: "没有",
|
|
1515
|
+
storageClear: "清空聊天记录",
|
|
1516
|
+
storageClearTitle: "清空与{name}的聊天记录?",
|
|
1517
|
+
storageClearHint: "只删本机的,其他人的不受影响,删了不能恢复。",
|
|
1518
|
+
storageFreed: "已释放 {size}",
|
|
1519
|
+
storageNone: "还没有聊天",
|
|
1486
1520
|
file: "[文件]",
|
|
1487
1521
|
voice: "[语音]",
|
|
1488
1522
|
video: "[视频]",
|
|
@@ -1653,6 +1687,23 @@ var ZH_TW = {
|
|
|
1653
1687
|
unsent: "未送出:內容太長",
|
|
1654
1688
|
chatEmpty: "還沒有人說話。只有群裡的人能看到,中繼儲存的是密文。",
|
|
1655
1689
|
chatPlaceholder: "發訊息",
|
|
1690
|
+
storageTitle: "儲存空間",
|
|
1691
|
+
storageLead: "本機的聊天",
|
|
1692
|
+
storageHint: "別人傳的圖片和檔案,清理後再打開會重新從對方那裡取;你傳的會保留,別人要從你這裡取。",
|
|
1693
|
+
storageTotal: "共計",
|
|
1694
|
+
storageParts: "訊息 {said} · 圖片和檔案 {media}",
|
|
1695
|
+
storageClearMedia: "清理別人傳的圖片和檔案({size})",
|
|
1696
|
+
storageOlder: "清理更早的聊天記錄",
|
|
1697
|
+
storageOlderTitle: "清理與{name}更早的聊天記錄",
|
|
1698
|
+
storageOlderHint: "按月清理,只刪本機的,其他人的不受影響,刪了不能恢復。",
|
|
1699
|
+
storageOlderMonths: "{n} 個月以前",
|
|
1700
|
+
storageOlderYear: "一年以前",
|
|
1701
|
+
storageOlderNone: "沒有",
|
|
1702
|
+
storageClear: "清空聊天記錄",
|
|
1703
|
+
storageClearTitle: "清空與{name}的聊天記錄?",
|
|
1704
|
+
storageClearHint: "只刪本機的,其他人的不受影響,刪了不能恢復。",
|
|
1705
|
+
storageFreed: "已釋放 {size}",
|
|
1706
|
+
storageNone: "還沒有聊天",
|
|
1656
1707
|
file: "[檔案]",
|
|
1657
1708
|
voice: "[語音]",
|
|
1658
1709
|
video: "[影片]",
|
|
@@ -1823,6 +1874,23 @@ var JA = {
|
|
|
1823
1874
|
unsent: "送信できませんでした:長すぎます",
|
|
1824
1875
|
chatEmpty: "まだ何も言われていません。グループ内の人だけが見ることができます。リレーは暗号化されて保存します。",
|
|
1825
1876
|
chatPlaceholder: "メッセージ",
|
|
1877
|
+
storageTitle: "ストレージ",
|
|
1878
|
+
storageLead: "このコンピュータのチャット",
|
|
1879
|
+
storageHint: "他の人が送った画像やファイルは、消しても開くとその人から取り直します。自分が送ったものは残ります(他の人があなたから取ります)。",
|
|
1880
|
+
storageTotal: "合計",
|
|
1881
|
+
storageParts: "メッセージ {said} · 画像とファイル {media}",
|
|
1882
|
+
storageClearMedia: "他の人が送った画像とファイルを消す({size})",
|
|
1883
|
+
storageOlder: "以前の履歴を消す",
|
|
1884
|
+
storageOlderTitle: "{name}との以前の履歴を消す",
|
|
1885
|
+
storageOlderHint: "月ごとに、このコンピュータからだけ消えます。他の人の分はそのままで、元に戻せません。",
|
|
1886
|
+
storageOlderMonths: "{n} か月より前",
|
|
1887
|
+
storageOlderYear: "1 年より前",
|
|
1888
|
+
storageOlderNone: "なし",
|
|
1889
|
+
storageClear: "チャット履歴を消す",
|
|
1890
|
+
storageClearTitle: "{name}とのチャット履歴を消しますか?",
|
|
1891
|
+
storageClearHint: "このコンピュータからだけ消えます。他の人の分はそのままで、元に戻せません。",
|
|
1892
|
+
storageFreed: "{size} を空けました",
|
|
1893
|
+
storageNone: "まだチャットはありません",
|
|
1826
1894
|
file: "[ファイル]",
|
|
1827
1895
|
voice: "[ボイス]",
|
|
1828
1896
|
video: "[動画]",
|
|
@@ -2430,7 +2498,9 @@ class DirectBook {
|
|
|
2430
2498
|
};
|
|
2431
2499
|
}
|
|
2432
2500
|
async keep(friend, room) {
|
|
2433
|
-
|
|
2501
|
+
if (!this.loaded) {
|
|
2502
|
+
await this.read();
|
|
2503
|
+
}
|
|
2434
2504
|
if (this.kept[friend] !== room) {
|
|
2435
2505
|
this.put({ ...this.kept, [friend]: room });
|
|
2436
2506
|
await pi.storage.set(DIRECT_KEY, this.kept);
|
|
@@ -2488,38 +2558,47 @@ function openDirect(friend) {
|
|
|
2488
2558
|
return open;
|
|
2489
2559
|
}
|
|
2490
2560
|
var opening = new Map;
|
|
2561
|
+
function known(friend) {
|
|
2562
|
+
const list = book.get().rooms;
|
|
2563
|
+
return list && directs.loaded ? DirectUtil.find(list, directs.get(), friend) : undefined;
|
|
2564
|
+
}
|
|
2491
2565
|
async function openOrMake(friend) {
|
|
2492
2566
|
const server = rooms();
|
|
2493
2567
|
if (!server?.inviteFriends) {
|
|
2494
2568
|
return;
|
|
2495
2569
|
}
|
|
2496
2570
|
try {
|
|
2497
|
-
|
|
2498
|
-
const { rooms: list = [] } = book.get();
|
|
2499
|
-
let room = DirectUtil.find(list, directs.get(), friend.id);
|
|
2500
|
-
const invite = !room ? (await server.listGroupInvites().catch(() => [])).find((each) => each.kind === DIRECT_KIND && each.by.id === friend.id) : undefined;
|
|
2501
|
-
if (invite) {
|
|
2502
|
-
await server.answerGroupInvite(invite.room, true);
|
|
2503
|
-
room = (await server.listRooms()).find((each) => each.id === invite.room && each.status === "member");
|
|
2504
|
-
}
|
|
2571
|
+
let room = known(friend.id);
|
|
2505
2572
|
if (!room) {
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
return;
|
|
2509
|
-
});
|
|
2510
|
-
await server.inviteFriends(room.id, [friend.id]);
|
|
2511
|
-
} else if (room.owner && !DirectUtil.peer(room)) {
|
|
2512
|
-
await server.inviteFriends(room.id, [friend.id]).catch(() => {
|
|
2513
|
-
return;
|
|
2514
|
-
});
|
|
2573
|
+
await book.load();
|
|
2574
|
+
room = DirectUtil.find(book.get().rooms ?? [], directs.get(), friend.id) ?? await joinOrMake(server, friend);
|
|
2515
2575
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2576
|
+
directs.keep(friend.id, room.id).catch(() => {
|
|
2577
|
+
return;
|
|
2578
|
+
});
|
|
2579
|
+
book.chat(room.id);
|
|
2580
|
+
await openRoom(room.id, true);
|
|
2519
2581
|
} catch (error) {
|
|
2520
2582
|
pi.ui.notify(message(error), "error");
|
|
2521
2583
|
}
|
|
2522
2584
|
}
|
|
2585
|
+
async function joinOrMake(server, friend) {
|
|
2586
|
+
const invite = (await server.listGroupInvites().catch(() => [])).find((each) => each.kind === DIRECT_KIND && each.by.id === friend.id);
|
|
2587
|
+
let room;
|
|
2588
|
+
if (invite) {
|
|
2589
|
+
await server.answerGroupInvite(invite.room, true);
|
|
2590
|
+
room = (await server.listRooms()).find((each) => each.id === invite.room && each.status === "member");
|
|
2591
|
+
}
|
|
2592
|
+
if (!room) {
|
|
2593
|
+
room = await server.createRoom({ kind: DIRECT_KIND, title: friend.name });
|
|
2594
|
+
await server.configureRoom(room.id, { members: 2 }).catch(() => {
|
|
2595
|
+
return;
|
|
2596
|
+
});
|
|
2597
|
+
await server.inviteFriends?.(room.id, [friend.id]);
|
|
2598
|
+
}
|
|
2599
|
+
await book.load();
|
|
2600
|
+
return room;
|
|
2601
|
+
}
|
|
2523
2602
|
var tidied = new Set;
|
|
2524
2603
|
function tidyDirects(list) {
|
|
2525
2604
|
const server = rooms();
|
|
@@ -3177,8 +3256,8 @@ class DoublesStore {
|
|
|
3177
3256
|
});
|
|
3178
3257
|
this.replyValue = replyValue;
|
|
3179
3258
|
next.reply = ReplyPolicyUtil.parse(replyValue, next.quiet);
|
|
3180
|
-
const
|
|
3181
|
-
const fresh = keys.includes(DoubleKeys.ASKS) ? next.asks.filter((ask) => !
|
|
3259
|
+
const known2 = new Set(this.state.asks.map((ask) => ask.id));
|
|
3260
|
+
const fresh = keys.includes(DoubleKeys.ASKS) ? next.asks.filter((ask) => !known2.has(ask.id)) : [];
|
|
3182
3261
|
this.state = next;
|
|
3183
3262
|
for (const listener of this.listeners) {
|
|
3184
3263
|
listener();
|
|
@@ -4004,14 +4083,16 @@ async function setReply(change) {
|
|
|
4004
4083
|
pi.ui.notify(message(error), "error");
|
|
4005
4084
|
}
|
|
4006
4085
|
}
|
|
4086
|
+
var SETTING_SELECT = "ta-input ta-select";
|
|
4007
4087
|
function ModeSelect({
|
|
4008
4088
|
value,
|
|
4009
4089
|
onChange,
|
|
4010
4090
|
inherit,
|
|
4011
|
-
label
|
|
4091
|
+
label,
|
|
4092
|
+
className = "trm-field"
|
|
4012
4093
|
}) {
|
|
4013
4094
|
return /* @__PURE__ */ React.createElement("select", {
|
|
4014
|
-
className
|
|
4095
|
+
className,
|
|
4015
4096
|
"aria-label": label,
|
|
4016
4097
|
value: value ?? "",
|
|
4017
4098
|
onChange: (event) => onChange(ReplyPolicyUtil.isMode(event.target.value) ? event.target.value : undefined)
|
|
@@ -4058,6 +4139,7 @@ function ReplyHere({ room }) {
|
|
|
4058
4139
|
function DefaultMode() {
|
|
4059
4140
|
const { reply } = useDoubles();
|
|
4060
4141
|
return /* @__PURE__ */ React.createElement(ModeSelect, {
|
|
4142
|
+
className: SETTING_SELECT,
|
|
4061
4143
|
value: reply.mode,
|
|
4062
4144
|
label: rt("replyDefault"),
|
|
4063
4145
|
onChange: (mode) => mode && void setReply((policy) => ({ ...policy, mode }))
|
|
@@ -4067,7 +4149,7 @@ function AwayMinutes() {
|
|
|
4067
4149
|
const { reply } = useDoubles();
|
|
4068
4150
|
const choices = AWAY_MINUTES.includes(reply.awayMinutes) ? AWAY_MINUTES : [...AWAY_MINUTES, reply.awayMinutes].sort((a, b) => a - b);
|
|
4069
4151
|
return /* @__PURE__ */ React.createElement("select", {
|
|
4070
|
-
className:
|
|
4152
|
+
className: SETTING_SELECT,
|
|
4071
4153
|
"aria-label": rt("replyAway"),
|
|
4072
4154
|
value: reply.awayMinutes,
|
|
4073
4155
|
onChange: (event) => void setReply((policy) => ({ ...policy, awayMinutes: Number(event.target.value) }))
|
|
@@ -4079,6 +4161,7 @@ function AwayMinutes() {
|
|
|
4079
4161
|
function StrangersMode() {
|
|
4080
4162
|
const { reply } = useDoubles();
|
|
4081
4163
|
return /* @__PURE__ */ React.createElement(ModeSelect, {
|
|
4164
|
+
className: SETTING_SELECT,
|
|
4082
4165
|
value: reply.strangers,
|
|
4083
4166
|
label: rt("replyStrangers"),
|
|
4084
4167
|
onChange: (mode) => mode && void setReply((policy) => ({ ...policy, strangers: mode }))
|
|
@@ -4160,9 +4243,10 @@ function OwnList() {
|
|
|
4160
4243
|
})
|
|
4161
4244
|
];
|
|
4162
4245
|
if (!rows.length) {
|
|
4163
|
-
return /* @__PURE__ */ React.createElement(
|
|
4164
|
-
|
|
4165
|
-
|
|
4246
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4247
|
+
compact: true,
|
|
4248
|
+
title: rt("replyOwnNone")
|
|
4249
|
+
});
|
|
4166
4250
|
}
|
|
4167
4251
|
return /* @__PURE__ */ React.createElement("ul", {
|
|
4168
4252
|
className: "trm-reply-own"
|
|
@@ -4206,7 +4290,7 @@ function Choice({
|
|
|
4206
4290
|
onChange
|
|
4207
4291
|
}) {
|
|
4208
4292
|
return /* @__PURE__ */ React.createElement("select", {
|
|
4209
|
-
className:
|
|
4293
|
+
className: SETTING_SELECT,
|
|
4210
4294
|
"aria-label": label,
|
|
4211
4295
|
value,
|
|
4212
4296
|
onChange: (event) => onChange(event.target.value)
|
|
@@ -4508,7 +4592,7 @@ var THUMB_SIDE = 16;
|
|
|
4508
4592
|
var FilesUtil;
|
|
4509
4593
|
((FilesUtil) => {
|
|
4510
4594
|
function size(bytes) {
|
|
4511
|
-
return bytes < 1024 * 1024 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4595
|
+
return bytes <= 0 ? "0 KB" : bytes < 1024 * 1024 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4512
4596
|
}
|
|
4513
4597
|
FilesUtil.size = size;
|
|
4514
4598
|
function seconds(ms = 0) {
|
|
@@ -4542,9 +4626,9 @@ class FileStore {
|
|
|
4542
4626
|
}
|
|
4543
4627
|
async open(room, file) {
|
|
4544
4628
|
const key = `${room}:${file.id}`;
|
|
4545
|
-
const
|
|
4546
|
-
if (
|
|
4547
|
-
return
|
|
4629
|
+
const known2 = this.urls.get(key);
|
|
4630
|
+
if (known2) {
|
|
4631
|
+
return known2;
|
|
4548
4632
|
}
|
|
4549
4633
|
const parts = [];
|
|
4550
4634
|
for (let offset = 0;offset < file.bytes; ) {
|
|
@@ -4756,7 +4840,7 @@ class Uploads {
|
|
|
4756
4840
|
}
|
|
4757
4841
|
}
|
|
4758
4842
|
var uploads = new Uploads;
|
|
4759
|
-
async function sendFile(room, blob, kind, name,
|
|
4843
|
+
async function sendFile(room, blob, kind, name, known2 = {}) {
|
|
4760
4844
|
const most = RELAY_CHAT_FILE_BYTES[kind];
|
|
4761
4845
|
if (blob.size > most) {
|
|
4762
4846
|
throw new Error(t("fileTooLarge", { mb: Math.round(most / (1024 * 1024)) }));
|
|
@@ -4776,7 +4860,7 @@ async function sendFile(room, blob, kind, name, known = {}) {
|
|
|
4776
4860
|
uploads.going.set(upload, { room: room.id, name, done: Math.min(1, (offset + bytes.length) / blob.size) });
|
|
4777
4861
|
uploads.tell();
|
|
4778
4862
|
}
|
|
4779
|
-
return await callDoubles({ kind: "fileFinish", upload, name, ...look, ...
|
|
4863
|
+
return await callDoubles({ kind: "fileFinish", upload, name, ...look, ...known2 });
|
|
4780
4864
|
} finally {
|
|
4781
4865
|
uploads.going.delete(upload);
|
|
4782
4866
|
uploads.tell();
|
|
@@ -4898,9 +4982,9 @@ function VoiceRecorder({ close, onDone }) {
|
|
|
4898
4982
|
}, t("voiceSend")))));
|
|
4899
4983
|
}
|
|
4900
4984
|
function fileActions(room, said) {
|
|
4901
|
-
const sendOne = async (blob, kind, name,
|
|
4985
|
+
const sendOne = async (blob, kind, name, known2 = {}) => {
|
|
4902
4986
|
try {
|
|
4903
|
-
await said([await sendFile(room, blob, kind, name,
|
|
4987
|
+
await said([await sendFile(room, blob, kind, name, known2)]);
|
|
4904
4988
|
} catch (error) {
|
|
4905
4989
|
pi.ui.notify(message(error), "error");
|
|
4906
4990
|
}
|
|
@@ -5979,7 +6063,7 @@ function FriendLinkDialog({ text, close }) {
|
|
|
5979
6063
|
const link = RelayHubUtil.parse(text);
|
|
5980
6064
|
const { identity, friends } = useBook();
|
|
5981
6065
|
const [busy, run] = useRun();
|
|
5982
|
-
const
|
|
6066
|
+
const known2 = friends?.find((friend) => friend.id === link.owner && friend.status === "friend");
|
|
5983
6067
|
const own = identity?.id === link.owner;
|
|
5984
6068
|
const add = () => void run(async () => {
|
|
5985
6069
|
await rooms()?.addFriend(text);
|
|
@@ -6002,13 +6086,13 @@ function FriendLinkDialog({ text, close }) {
|
|
|
6002
6086
|
className: "trm-join-name"
|
|
6003
6087
|
}, link.by || "…"), /* @__PURE__ */ React.createElement("p", {
|
|
6004
6088
|
className: "trm-lead"
|
|
6005
|
-
}, own ? t("addFriendOwn") :
|
|
6089
|
+
}, own ? t("addFriendOwn") : known2 ? t("addFriendKnown", { name: link.by }) : t("addFriendBody", { name: link.by || "…" }))), /* @__PURE__ */ React.createElement("div", {
|
|
6006
6090
|
className: "trm-actions"
|
|
6007
6091
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
6008
6092
|
type: "button",
|
|
6009
6093
|
className: "ta-button",
|
|
6010
6094
|
onClick: close
|
|
6011
|
-
}, t("later")), !own && !
|
|
6095
|
+
}, t("later")), !own && !known2 && /* @__PURE__ */ React.createElement("button", {
|
|
6012
6096
|
type: "button",
|
|
6013
6097
|
className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
|
|
6014
6098
|
disabled: busy,
|
|
@@ -6302,9 +6386,9 @@ function openJoin(text) {
|
|
|
6302
6386
|
return;
|
|
6303
6387
|
}
|
|
6304
6388
|
const link = RelayHubUtil.parse(text);
|
|
6305
|
-
const
|
|
6389
|
+
const known2 = () => book.get().rooms?.find((room) => room.id === link.room && room.status === "member");
|
|
6306
6390
|
const go = () => {
|
|
6307
|
-
const room =
|
|
6391
|
+
const room = known2();
|
|
6308
6392
|
if (!room) {
|
|
6309
6393
|
show(({ close }) => /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
6310
6394
|
link,
|
|
@@ -6317,7 +6401,7 @@ function openJoin(text) {
|
|
|
6317
6401
|
openRoom(room.id);
|
|
6318
6402
|
}
|
|
6319
6403
|
};
|
|
6320
|
-
if (
|
|
6404
|
+
if (known2()) {
|
|
6321
6405
|
go();
|
|
6322
6406
|
} else {
|
|
6323
6407
|
book.load().then(go, go);
|
|
@@ -8288,6 +8372,202 @@ function RoomFaceOf({ id, size }) {
|
|
|
8288
8372
|
}) : null;
|
|
8289
8373
|
}
|
|
8290
8374
|
|
|
8375
|
+
// web-src/storage-view.tsx
|
|
8376
|
+
var total = (each) => each.said + each.media.mine + each.media.others;
|
|
8377
|
+
var MONTHS = [1, 3, 6, 12];
|
|
8378
|
+
function monthsAgo(months, now = new Date) {
|
|
8379
|
+
return new Date(now.getFullYear(), now.getMonth() - months, 1).getTime();
|
|
8380
|
+
}
|
|
8381
|
+
function ClearOlder({ room, name, close, onDone }) {
|
|
8382
|
+
const [freed, setFreed] = React.useState({});
|
|
8383
|
+
const [busy, setBusy] = React.useState(false);
|
|
8384
|
+
React.useEffect(() => {
|
|
8385
|
+
(async () => {
|
|
8386
|
+
const read = {};
|
|
8387
|
+
for (const months of MONTHS) {
|
|
8388
|
+
read[months] = (await rooms()?.chatUsage?.(monthsAgo(months)).catch(() => {
|
|
8389
|
+
return;
|
|
8390
|
+
}))?.[room.id] ?? 0;
|
|
8391
|
+
}
|
|
8392
|
+
setFreed(read);
|
|
8393
|
+
})();
|
|
8394
|
+
}, [room.id]);
|
|
8395
|
+
const clear = async (months) => {
|
|
8396
|
+
setBusy(true);
|
|
8397
|
+
try {
|
|
8398
|
+
await rooms()?.clearChat(room.id, monthsAgo(months));
|
|
8399
|
+
pi.ui.notify(t("storageFreed", { size: FilesUtil.size(freed[months] ?? 0) }));
|
|
8400
|
+
book.chat(room.id)?.load();
|
|
8401
|
+
onDone();
|
|
8402
|
+
close();
|
|
8403
|
+
} catch (error) {
|
|
8404
|
+
pi.ui.notify(message(error), "error");
|
|
8405
|
+
setBusy(false);
|
|
8406
|
+
}
|
|
8407
|
+
};
|
|
8408
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
8409
|
+
title: t("storageOlderTitle", { name }),
|
|
8410
|
+
onClose: close
|
|
8411
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
8412
|
+
className: "trm-note"
|
|
8413
|
+
}, t("storageOlderHint")), /* @__PURE__ */ React.createElement("ul", {
|
|
8414
|
+
className: "trm-panel-members trm-older"
|
|
8415
|
+
}, MONTHS.map((months) => /* @__PURE__ */ React.createElement("li", {
|
|
8416
|
+
key: months
|
|
8417
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
8418
|
+
type: "button",
|
|
8419
|
+
className: `trm-member${busy ? " ta-pending" : ""}`,
|
|
8420
|
+
disabled: busy || freed[months] === 0,
|
|
8421
|
+
onClick: () => void clear(months)
|
|
8422
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
8423
|
+
className: "trm-member-text"
|
|
8424
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
8425
|
+
className: "trm-member-name"
|
|
8426
|
+
}, t(months === 12 ? "storageOlderYear" : "storageOlderMonths", { n: months }))), /* @__PURE__ */ React.createElement("span", {
|
|
8427
|
+
className: "trm-storage-size"
|
|
8428
|
+
}, freed[months] === undefined ? "…" : freed[months] ? FilesUtil.size(freed[months]) : t("storageOlderNone")))))));
|
|
8429
|
+
}
|
|
8430
|
+
function useUsage() {
|
|
8431
|
+
const { rooms: list, friends } = useBook();
|
|
8432
|
+
const [usage, setUsage] = React.useState();
|
|
8433
|
+
const [again, setAgain] = React.useState(0);
|
|
8434
|
+
const chats = (list ?? []).filter((room) => !room.unlisted && room.status === "member");
|
|
8435
|
+
const ids = chats.map((room) => room.id).join(",");
|
|
8436
|
+
React.useEffect(() => {
|
|
8437
|
+
let gone = false;
|
|
8438
|
+
(async () => {
|
|
8439
|
+
const said = await rooms()?.chatUsage?.().catch(() => {
|
|
8440
|
+
return;
|
|
8441
|
+
}) ?? {};
|
|
8442
|
+
const read = [];
|
|
8443
|
+
for (const room of chats) {
|
|
8444
|
+
const media = await callDoubles({ kind: "mediaUsage", room: room.id }).catch(() => {
|
|
8445
|
+
return;
|
|
8446
|
+
}) ?? {
|
|
8447
|
+
mine: 0,
|
|
8448
|
+
others: 0
|
|
8449
|
+
};
|
|
8450
|
+
read.push({ room, said: said[room.id] ?? 0, media });
|
|
8451
|
+
}
|
|
8452
|
+
if (!gone) {
|
|
8453
|
+
setUsage(read.sort((a, b) => total(b) - total(a)));
|
|
8454
|
+
}
|
|
8455
|
+
})();
|
|
8456
|
+
return () => {
|
|
8457
|
+
gone = true;
|
|
8458
|
+
};
|
|
8459
|
+
}, [ids, again, friends?.length]);
|
|
8460
|
+
return { usage, load: () => setAgain((n) => n + 1) };
|
|
8461
|
+
}
|
|
8462
|
+
function nameOf(room) {
|
|
8463
|
+
return DirectUtil.is(room) ? directPeer(room, book.get().friends).name : room.title;
|
|
8464
|
+
}
|
|
8465
|
+
function ChatRow({ each, onChanged }) {
|
|
8466
|
+
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
8467
|
+
const [busy, run] = (pi.ui.useBusy ?? (() => [false, async (action) => action()]))();
|
|
8468
|
+
const Chevron = icon("ChevronRight");
|
|
8469
|
+
const name = nameOf(each.room);
|
|
8470
|
+
const clearMedia = () => void run(async () => {
|
|
8471
|
+
try {
|
|
8472
|
+
const freed = await callDoubles({ kind: "clearMedia", room: each.room.id });
|
|
8473
|
+
pi.ui.notify(t("storageFreed", { size: FilesUtil.size(freed) }));
|
|
8474
|
+
} catch (error) {
|
|
8475
|
+
pi.ui.notify(message(error), "error");
|
|
8476
|
+
}
|
|
8477
|
+
onChanged();
|
|
8478
|
+
});
|
|
8479
|
+
const clearChat = () => void run(async () => {
|
|
8480
|
+
const sure = await pi.ui.confirm(t("storageClearTitle", { name }), t("storageClearHint"), { confirmLabel: t("storageClear"), danger: true });
|
|
8481
|
+
if (!sure) {
|
|
8482
|
+
return;
|
|
8483
|
+
}
|
|
8484
|
+
try {
|
|
8485
|
+
await rooms()?.clearChat(each.room.id);
|
|
8486
|
+
book.chat(each.room.id)?.load();
|
|
8487
|
+
} catch (error) {
|
|
8488
|
+
pi.ui.notify(message(error), "error");
|
|
8489
|
+
}
|
|
8490
|
+
onChanged();
|
|
8491
|
+
});
|
|
8492
|
+
const open = (event) => openMenu(event, [
|
|
8493
|
+
[
|
|
8494
|
+
{
|
|
8495
|
+
key: "media",
|
|
8496
|
+
label: t("storageClearMedia", { size: FilesUtil.size(each.media.others) }),
|
|
8497
|
+
icon: icon("Image"),
|
|
8498
|
+
...each.media.others ? {} : { disabled: true },
|
|
8499
|
+
run: clearMedia
|
|
8500
|
+
},
|
|
8501
|
+
{
|
|
8502
|
+
key: "older",
|
|
8503
|
+
label: t("storageOlder"),
|
|
8504
|
+
icon: icon("Calendar"),
|
|
8505
|
+
...each.said ? {} : { disabled: true },
|
|
8506
|
+
run: () => void show(({ close }) => /* @__PURE__ */ React.createElement(ClearOlder, {
|
|
8507
|
+
room: each.room,
|
|
8508
|
+
name,
|
|
8509
|
+
close,
|
|
8510
|
+
onDone: onChanged
|
|
8511
|
+
}))
|
|
8512
|
+
},
|
|
8513
|
+
{ key: "chat", label: t("storageClear"), icon: icon("Trash2"), danger: true, run: clearChat }
|
|
8514
|
+
]
|
|
8515
|
+
]);
|
|
8516
|
+
return /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
8517
|
+
type: "button",
|
|
8518
|
+
className: `trm-member${busy ? " ta-pending" : ""}`,
|
|
8519
|
+
onClick: open
|
|
8520
|
+
}, DirectUtil.is(each.room) ? /* @__PURE__ */ React.createElement(DirectFace, {
|
|
8521
|
+
room: each.room,
|
|
8522
|
+
size: 34
|
|
8523
|
+
}) : /* @__PURE__ */ React.createElement(RoomFace, {
|
|
8524
|
+
room: each.room,
|
|
8525
|
+
size: 34
|
|
8526
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
8527
|
+
className: "trm-member-text"
|
|
8528
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
8529
|
+
className: "trm-member-name trm-ellipsis"
|
|
8530
|
+
}, name), /* @__PURE__ */ React.createElement("span", {
|
|
8531
|
+
className: "trm-note trm-ellipsis"
|
|
8532
|
+
}, t("storageParts", { said: FilesUtil.size(each.said), media: FilesUtil.size(each.media.mine + each.media.others) }))), /* @__PURE__ */ React.createElement("span", {
|
|
8533
|
+
className: "trm-storage-size"
|
|
8534
|
+
}, FilesUtil.size(total(each))), /* @__PURE__ */ React.createElement(Chevron, {
|
|
8535
|
+
size: 15
|
|
8536
|
+
})), menu);
|
|
8537
|
+
}
|
|
8538
|
+
function StorageList() {
|
|
8539
|
+
const { usage, load } = useUsage();
|
|
8540
|
+
if (!usage) {
|
|
8541
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Loading, null);
|
|
8542
|
+
}
|
|
8543
|
+
if (!usage.length) {
|
|
8544
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
8545
|
+
compact: true,
|
|
8546
|
+
title: t("storageNone")
|
|
8547
|
+
});
|
|
8548
|
+
}
|
|
8549
|
+
const all = usage.reduce((sum, each) => sum + total(each), 0);
|
|
8550
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
8551
|
+
className: "trm-storage"
|
|
8552
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
8553
|
+
className: "trm-storage-total"
|
|
8554
|
+
}, /* @__PURE__ */ React.createElement("span", null, t("storageTotal")), /* @__PURE__ */ React.createElement("strong", null, FilesUtil.size(all))), /* @__PURE__ */ React.createElement("ul", {
|
|
8555
|
+
className: "trm-panel-members"
|
|
8556
|
+
}, usage.map((each) => /* @__PURE__ */ React.createElement(ChatRow, {
|
|
8557
|
+
key: each.room.id,
|
|
8558
|
+
each,
|
|
8559
|
+
onChanged: load
|
|
8560
|
+
}))));
|
|
8561
|
+
}
|
|
8562
|
+
function storageSettings() {
|
|
8563
|
+
return {
|
|
8564
|
+
title: () => t("storageTitle"),
|
|
8565
|
+
icon: icon("HardDrive"),
|
|
8566
|
+
group: "general",
|
|
8567
|
+
rows: [{ key: "chat-storage", label: () => t("storageLead"), description: () => t("storageHint"), render: StorageList, stacked: true }]
|
|
8568
|
+
};
|
|
8569
|
+
}
|
|
8570
|
+
|
|
8291
8571
|
// web-src/style.ts
|
|
8292
8572
|
var STYLE = `
|
|
8293
8573
|
.trm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -8444,6 +8724,12 @@ var STYLE = `
|
|
|
8444
8724
|
.trm-panel-title span { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
8445
8725
|
.trm-panel-label { padding: 10px 10px 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
8446
8726
|
.trm-panel-members { margin: 0; padding: 0; list-style: none; }
|
|
8727
|
+
.trm-storage { width: 100%; align-self: stretch; }
|
|
8728
|
+
.trm-storage-total { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 10px 10px; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); }
|
|
8729
|
+
.trm-storage-total strong { color: var(--ta-text); font-size: calc(20px * var(--ta-font-scale)); font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
8730
|
+
.trm-older { margin-top: 6px; }
|
|
8731
|
+
.trm-older .trm-member:disabled { opacity: 0.45; cursor: default; }
|
|
8732
|
+
.trm-storage-size { flex: none; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
8447
8733
|
.trm-member { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; box-sizing: border-box; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; }
|
|
8448
8734
|
button.trm-member { cursor: pointer; }
|
|
8449
8735
|
.trm-member-plus { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--ta-hover); color: var(--ta-secondary); }
|
|
@@ -8660,6 +8946,7 @@ function activate(pi2) {
|
|
|
8660
8946
|
icon: icon("Users"),
|
|
8661
8947
|
render: MembersView,
|
|
8662
8948
|
location: "panel",
|
|
8949
|
+
navigation: false,
|
|
8663
8950
|
order: 90
|
|
8664
8951
|
});
|
|
8665
8952
|
pi2.registerView(DOUBLES_VIEW.slice(DOUBLES_VIEW.lastIndexOf("/") + 1), {
|
|
@@ -8674,6 +8961,7 @@ function activate(pi2) {
|
|
|
8674
8961
|
}
|
|
8675
8962
|
if (pi2.rooms) {
|
|
8676
8963
|
pi2.registerSettings(replySettings());
|
|
8964
|
+
pi2.registerSettings(storageSettings());
|
|
8677
8965
|
}
|
|
8678
8966
|
const stopDirects = pi2.rooms ? directs.start() : () => {
|
|
8679
8967
|
return;
|