@celljs/ta-rooms 4.21.0 → 4.23.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 +276 -12
- package/host/index.mjs +2823 -1451
- package/package.json +4 -4
- package/web/index.js +1798 -202
package/web/index.js
CHANGED
|
@@ -67,6 +67,8 @@ var RELAY_ROOM_PATH = "/r";
|
|
|
67
67
|
var RELAY_HUB_MAX_VALUE = 96 * 1024;
|
|
68
68
|
var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
69
69
|
var RELAY_PICTURE_MAX_CHARS = 16 * 1024;
|
|
70
|
+
var RELAY_HUB_LOG_CHARS = 4 * 1024 * 1024;
|
|
71
|
+
var RELAY_HUB_HISTORY_MAX = 500;
|
|
70
72
|
|
|
71
73
|
// ../ta-relay/esm/common/relay-identity.js
|
|
72
74
|
var encoder = new TextEncoder;
|
|
@@ -221,12 +223,14 @@ var RelayHubCharterUtil;
|
|
|
221
223
|
return;
|
|
222
224
|
}
|
|
223
225
|
const capacity = Math.round(Number(body.capacity));
|
|
226
|
+
const history = Math.min(Math.round(Number(body.history) || 0), RELAY_HUB_HISTORY_MAX);
|
|
224
227
|
return {
|
|
225
228
|
room,
|
|
226
229
|
v: Number(body.v),
|
|
227
230
|
admins: body.admins.filter((admin) => admin && typeof admin.member === "string" && typeof admin.id === "string").slice(0, RELAY_HUB_MAX_ADMINS).map((admin) => ({ member: admin.member, id: admin.id })),
|
|
228
231
|
rules: rules(body.rules),
|
|
229
|
-
...capacity >= 2 ? { capacity } : {}
|
|
232
|
+
...capacity >= 2 ? { capacity } : {},
|
|
233
|
+
...history > 0 ? { history } : {}
|
|
230
234
|
};
|
|
231
235
|
} catch (_a) {
|
|
232
236
|
return;
|
|
@@ -653,9 +657,77 @@ var RelayFriendsUtil;
|
|
|
653
657
|
RelayFriendsUtil2.migrate = migrate;
|
|
654
658
|
})(RelayFriendsUtil || (RelayFriendsUtil = {}));
|
|
655
659
|
|
|
660
|
+
// ../ta-relay/esm/common/relay-room-app.js
|
|
661
|
+
var ROOM_AGENTS_KEY = "agents:";
|
|
662
|
+
var ROOM_APP_STALE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
663
|
+
var HOUR_MS = 60 * 60 * 1000;
|
|
664
|
+
var RoomAppUtil;
|
|
665
|
+
(function(RoomAppUtil2) {
|
|
666
|
+
function quote(text) {
|
|
667
|
+
return text.replace(/</g, "<").replace(/>/g, ">");
|
|
668
|
+
}
|
|
669
|
+
RoomAppUtil2.quote = quote;
|
|
670
|
+
function fresh(lines, self, since, now, staleMs = ROOM_APP_STALE_MS) {
|
|
671
|
+
return lines.filter((line) => {
|
|
672
|
+
var _a;
|
|
673
|
+
return line.from !== self && line.at > since && now - line.at < staleMs && !((_a = line.to) === null || _a === undefined ? undefined : _a.length) && !line.double && !line.agent;
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
RoomAppUtil2.fresh = fresh;
|
|
677
|
+
function within(times, now, most) {
|
|
678
|
+
return times.filter((at) => now - at < HOUR_MS).length < most;
|
|
679
|
+
}
|
|
680
|
+
RoomAppUtil2.within = within;
|
|
681
|
+
function mentions(names) {
|
|
682
|
+
return [...new Set(names)].map((name) => `@${name}`).join(" ");
|
|
683
|
+
}
|
|
684
|
+
RoomAppUtil2.mentions = mentions;
|
|
685
|
+
})(RoomAppUtil || (RoomAppUtil = {}));
|
|
686
|
+
var RELAY_BOARD_KEY = "board:";
|
|
687
|
+
var RELAY_BOARD_MAX = 30;
|
|
688
|
+
var STATES = ["doing", "waiting", "done", "closed"];
|
|
689
|
+
var RelayBoardUtil;
|
|
690
|
+
(function(RelayBoardUtil2) {
|
|
691
|
+
function key(app, member) {
|
|
692
|
+
return `${RELAY_BOARD_KEY}${app}:${member}`;
|
|
693
|
+
}
|
|
694
|
+
RelayBoardUtil2.key = key;
|
|
695
|
+
function read(key2, value, by, owner) {
|
|
696
|
+
if (!owner || by !== owner || !key2.startsWith(RELAY_BOARD_KEY) || !key2.endsWith(`:${owner}`) || !value || typeof value !== "object") {
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
const { title, items } = value;
|
|
700
|
+
if (typeof title !== "string" || !Array.isArray(items)) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
title: cut(title, 40),
|
|
705
|
+
items: items.filter((item) => item && Number.isInteger(item.n) && typeof item.title === "string" && STATES.includes(item.state) && typeof item.label === "string" && typeof item.at === "number").slice(-RELAY_BOARD_MAX).map((item) => ({
|
|
706
|
+
n: item.n,
|
|
707
|
+
title: cut(item.title, 80),
|
|
708
|
+
state: item.state,
|
|
709
|
+
label: cut(item.label, 30),
|
|
710
|
+
people: Array.isArray(item.people) ? item.people.filter((name) => typeof name === "string").slice(0, 5) : [],
|
|
711
|
+
at: item.at
|
|
712
|
+
}))
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
RelayBoardUtil2.read = read;
|
|
716
|
+
function counts(board) {
|
|
717
|
+
return {
|
|
718
|
+
open: board.items.filter((item) => item.state === "doing" || item.state === "waiting").length,
|
|
719
|
+
done: board.items.filter((item) => item.state === "done").length
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
RelayBoardUtil2.counts = counts;
|
|
723
|
+
function cut(text, max) {
|
|
724
|
+
const one = text.replace(/\s+/g, " ").trim();
|
|
725
|
+
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
726
|
+
}
|
|
727
|
+
})(RelayBoardUtil || (RelayBoardUtil = {}));
|
|
728
|
+
|
|
656
729
|
// web-src/double-protocol.ts
|
|
657
730
|
var DIRECT_KIND = "ta-direct";
|
|
658
|
-
var ROOM_AGENTS_KEY = "agents:";
|
|
659
731
|
var RoomAgentsUtil;
|
|
660
732
|
((RoomAgentsUtil) => {
|
|
661
733
|
function key(member) {
|
|
@@ -733,6 +805,8 @@ var TASK_MESSAGE_TYPE = "ta-rooms:task";
|
|
|
733
805
|
var ROOM_CAPABILITIES = ["files", "commands"];
|
|
734
806
|
var DoubleKeys;
|
|
735
807
|
((DoubleKeys) => {
|
|
808
|
+
DoubleKeys.PICTURES = "pictures.came";
|
|
809
|
+
DoubleKeys.FILES = "files.came";
|
|
736
810
|
DoubleKeys.QUIET = "doubles.quiet";
|
|
737
811
|
DoubleKeys.REPLY = "doubles.reply";
|
|
738
812
|
DoubleKeys.DRAFTS = "doubles.drafts";
|
|
@@ -771,16 +845,37 @@ var DirectUtil;
|
|
|
771
845
|
DirectUtil.friendOf = friendOf;
|
|
772
846
|
function find(rooms, kept, friend) {
|
|
773
847
|
const mine = rooms.filter((room) => is(room) && room.status === "member");
|
|
774
|
-
return mine.find((room) => room.id === kept[friend]) ?? mine.
|
|
848
|
+
return mine.find((room) => room.id === kept[friend]) ?? mine.filter((room) => peer(room)?.id === friend).sort((a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id))[0];
|
|
775
849
|
}
|
|
776
850
|
DirectUtil.find = find;
|
|
851
|
+
function extra(rooms, kept) {
|
|
852
|
+
const mine = rooms.filter((room) => is(room) && room.status === "member");
|
|
853
|
+
const shown = new Set;
|
|
854
|
+
for (const friend of new Set(mine.map((room) => friendOf(room, kept)))) {
|
|
855
|
+
const room = friend ? find(rooms, kept, friend) : undefined;
|
|
856
|
+
if (room) {
|
|
857
|
+
shown.add(room.id);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return mine.filter((room) => !shown.has(room.id));
|
|
861
|
+
}
|
|
862
|
+
DirectUtil.extra = extra;
|
|
777
863
|
})(DirectUtil ||= {});
|
|
778
864
|
|
|
779
865
|
// ../ta-relay/esm/common/relay-room-chat.js
|
|
866
|
+
var RELAY_CHAT_FILE_BYTES = { file: 50 * 1024 * 1024, video: 30 * 1024 * 1024, voice: 2 * 1024 * 1024 };
|
|
867
|
+
var RELAY_CHAT_VOICE_MS = 60000;
|
|
868
|
+
var RELAY_CHAT_VIDEO_MS = 3 * 60000;
|
|
869
|
+
var RELAY_CHAT_FILES = 9;
|
|
780
870
|
var RELAY_CHAT_KEY = "chat:";
|
|
781
871
|
var RELAY_CHAT_PART_BYTES = 8 * 1024;
|
|
782
872
|
var RELAY_CHAT_PARTS = 6;
|
|
783
873
|
var RELAY_CHAT_TEXT_MAX = 2000;
|
|
874
|
+
var RELAY_CHAT_IMAGES = 9;
|
|
875
|
+
var RELAY_CHAT_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
876
|
+
var RELAY_CHAT_THUMB_CHARS = 900;
|
|
877
|
+
var IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
878
|
+
var RELAY_CHAT_WINDOW = 500;
|
|
784
879
|
var TRIES = 6;
|
|
785
880
|
var RelayRoomChatUtil;
|
|
786
881
|
(function(RelayRoomChatUtil2) {
|
|
@@ -815,18 +910,99 @@ var RelayRoomChatUtil;
|
|
|
815
910
|
...to.length ? { to } : {},
|
|
816
911
|
...line.person === true && to.length && line.double !== true && !line.agent ? { person: true } : {},
|
|
817
912
|
...typeof line.re === "string" ? { re: line.re } : {},
|
|
818
|
-
...line.task === true && to.length ? { task: true } : {}
|
|
913
|
+
...line.task === true && to.length ? { task: true } : {},
|
|
914
|
+
...images(line.images),
|
|
915
|
+
...files(line.files)
|
|
819
916
|
};
|
|
820
917
|
}
|
|
821
918
|
RelayRoomChatUtil2.extra = extra;
|
|
919
|
+
function files(value) {
|
|
920
|
+
if (!Array.isArray(value)) {
|
|
921
|
+
return {};
|
|
922
|
+
}
|
|
923
|
+
const files2 = [];
|
|
924
|
+
for (const file of value.slice(0, RELAY_CHAT_FILES)) {
|
|
925
|
+
const kind = file === null || file === undefined ? undefined : file.kind;
|
|
926
|
+
if (!file || kind !== "file" && kind !== "voice" && kind !== "video" || typeof file.id !== "string" || !/^[a-f0-9]{24}$/.test(file.id) || typeof file.sha !== "string" || !/^[0-9a-f]{64}$/.test(file.sha) || !Number.isInteger(file.bytes) || file.bytes <= 0 || file.bytes > RELAY_CHAT_FILE_BYTES[kind]) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const name = [...typeof file.name === "string" ? file.name : ""].filter((char) => char.charCodeAt(0) >= 32 && char !== "/" && char !== "\\").join("").slice(0, 120) || kind;
|
|
930
|
+
const type = typeof file.type === "string" && /^[\w.+-]+\/[\w.+-]+$/.test(file.type) ? file.type.slice(0, 100) : "application/octet-stream";
|
|
931
|
+
const most = kind === "voice" ? RELAY_CHAT_VOICE_MS : RELAY_CHAT_VIDEO_MS;
|
|
932
|
+
const ms = kind !== "file" && Number.isFinite(file.ms) ? Math.min(Math.max(Math.round(file.ms), 0), most) : undefined;
|
|
933
|
+
const size = kind === "video" && Number.isInteger(file.w) && Number.isInteger(file.h) && file.w > 0 && file.h > 0;
|
|
934
|
+
const thumb = kind === "video" && typeof file.thumb === "string" && file.thumb.length <= RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(file.thumb) ? file.thumb : undefined;
|
|
935
|
+
files2.push({
|
|
936
|
+
id: file.id,
|
|
937
|
+
kind,
|
|
938
|
+
name,
|
|
939
|
+
type,
|
|
940
|
+
bytes: file.bytes,
|
|
941
|
+
sha: file.sha,
|
|
942
|
+
...ms !== undefined ? { ms } : {},
|
|
943
|
+
...size ? { w: file.w, h: file.h } : {},
|
|
944
|
+
...thumb ? { thumb } : {}
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
return files2.length ? { files: files2 } : {};
|
|
948
|
+
}
|
|
949
|
+
RelayRoomChatUtil2.files = files;
|
|
950
|
+
function images(value) {
|
|
951
|
+
if (!Array.isArray(value)) {
|
|
952
|
+
return {};
|
|
953
|
+
}
|
|
954
|
+
const images2 = [];
|
|
955
|
+
for (const image of value.slice(0, RELAY_CHAT_IMAGES)) {
|
|
956
|
+
if (image && typeof image.id === "string" && /^[A-Za-z0-9-]{8,64}$/.test(image.id) && typeof image.type === "string" && IMAGE_TYPES.includes(image.type) && typeof image.sha === "string" && /^[0-9a-f]{64}$/.test(image.sha) && Number.isInteger(image.w) && Number.isInteger(image.h) && Number.isInteger(image.bytes) && image.w > 0 && image.h > 0 && image.bytes > 0 && image.bytes <= RELAY_CHAT_IMAGE_BYTES) {
|
|
957
|
+
const thumb = typeof image.thumb === "string" && image.thumb.length <= RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(image.thumb) ? image.thumb : undefined;
|
|
958
|
+
const blob = image.blob;
|
|
959
|
+
const ok = !!blob && typeof blob.id === "string" && /^[A-Za-z0-9_-]{16,64}$/.test(blob.id) && typeof blob.read === "string" && /^[A-Za-z0-9_-]{43}$/.test(blob.read) && typeof blob.key === "string" && /^[A-Za-z0-9_-]{43}$/.test(blob.key) && Number.isFinite(blob.until);
|
|
960
|
+
images2.push({
|
|
961
|
+
id: image.id,
|
|
962
|
+
type: image.type,
|
|
963
|
+
w: image.w,
|
|
964
|
+
h: image.h,
|
|
965
|
+
bytes: image.bytes,
|
|
966
|
+
sha: image.sha,
|
|
967
|
+
...thumb ? { thumb } : {},
|
|
968
|
+
...ok && blob ? { blob: { id: blob.id, read: blob.read, key: blob.key, until: blob.until } } : {}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return images2.length ? { images: images2 } : {};
|
|
973
|
+
}
|
|
974
|
+
function preview(line, picture, words = { file: "[file]", voice: "[voice]", video: "[video]" }) {
|
|
975
|
+
var _a;
|
|
976
|
+
var _b;
|
|
977
|
+
const pictures = ((_a = line.images) === null || _a === undefined ? undefined : _a.length) ? line.images.length > 1 ? `${picture}×${line.images.length}` : picture : "";
|
|
978
|
+
const files2 = ((_b = line.files) !== null && _b !== undefined ? _b : []).map((file) => file.kind === "file" ? `${words.file} ${file.name}` : words[file.kind]);
|
|
979
|
+
return [pictures, ...files2, line.text].filter(Boolean).join(" ");
|
|
980
|
+
}
|
|
981
|
+
RelayRoomChatUtil2.preview = preview;
|
|
822
982
|
function stored(lines2) {
|
|
823
|
-
return lines2.map(({ from: _from, ...line }) => line);
|
|
983
|
+
return lines2.map(({ from: _from, seq: _seq, pending: _pending, failed: _failed, ...line }) => line);
|
|
824
984
|
}
|
|
825
985
|
RelayRoomChatUtil2.stored = stored;
|
|
986
|
+
function signed(member, value, seq) {
|
|
987
|
+
const line = value;
|
|
988
|
+
if (!line || typeof line.id !== "string" || typeof line.text !== "string" || typeof line.at !== "number") {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const name = typeof line.name === "string" ? line.name.slice(0, 64) : "";
|
|
992
|
+
const text = line.text.slice(0, RELAY_CHAT_TEXT_MAX);
|
|
993
|
+
return { id: line.id.slice(0, 40), from: member, name, text, at: line.at, ...extra(line), ...seq ? { seq } : {} };
|
|
994
|
+
}
|
|
995
|
+
RelayRoomChatUtil2.signed = signed;
|
|
826
996
|
function bytes(lines2) {
|
|
827
997
|
return new TextEncoder().encode(JSON.stringify(lines2)).length;
|
|
828
998
|
}
|
|
829
999
|
RelayRoomChatUtil2.bytes = bytes;
|
|
1000
|
+
function unknownMethod(error) {
|
|
1001
|
+
var _a;
|
|
1002
|
+
const found = error;
|
|
1003
|
+
return (found === null || found === undefined ? undefined : found.code) === -32601 || /method not found|not a function|unknown method|no such method/i.test(String((_a = found === null || found === undefined ? undefined : found.message) !== null && _a !== undefined ? _a : error));
|
|
1004
|
+
}
|
|
1005
|
+
RelayRoomChatUtil2.unknownMethod = unknownMethod;
|
|
830
1006
|
function id() {
|
|
831
1007
|
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
832
1008
|
}
|
|
@@ -840,6 +1016,8 @@ class RelayRoomChat {
|
|
|
840
1016
|
this.parts = new Map;
|
|
841
1017
|
this.listeners = new Set;
|
|
842
1018
|
this.all = [];
|
|
1019
|
+
this.olderKept = false;
|
|
1020
|
+
this.log = typeof rooms.readChat === "function" && typeof rooms.say === "function";
|
|
843
1021
|
}
|
|
844
1022
|
get lines() {
|
|
845
1023
|
return this.all;
|
|
@@ -848,7 +1026,25 @@ class RelayRoomChat {
|
|
|
848
1026
|
this.listeners.add(listener);
|
|
849
1027
|
return () => this.listeners.delete(listener);
|
|
850
1028
|
}
|
|
1029
|
+
get more() {
|
|
1030
|
+
return this.olderKept;
|
|
1031
|
+
}
|
|
851
1032
|
async load() {
|
|
1033
|
+
if (this.log && this.rooms.readChat) {
|
|
1034
|
+
const read = await this.rooms.readChat(this.room, { limit: RELAY_CHAT_WINDOW }).catch((error) => {
|
|
1035
|
+
if (!RelayRoomChatUtil.unknownMethod(error)) {
|
|
1036
|
+
throw error;
|
|
1037
|
+
}
|
|
1038
|
+
this.log = false;
|
|
1039
|
+
return;
|
|
1040
|
+
});
|
|
1041
|
+
if (read) {
|
|
1042
|
+
this.olderKept = read.more;
|
|
1043
|
+
this.all = Array.isArray(read.lines) ? read.lines : [];
|
|
1044
|
+
this.tell();
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
852
1048
|
const state = await this.rooms.getState(this.room, RELAY_CHAT_KEY);
|
|
853
1049
|
this.parts.clear();
|
|
854
1050
|
for (const [key, value] of Object.entries(state)) {
|
|
@@ -856,7 +1052,51 @@ class RelayRoomChat {
|
|
|
856
1052
|
}
|
|
857
1053
|
this.changed();
|
|
858
1054
|
}
|
|
1055
|
+
async older(limit = 100) {
|
|
1056
|
+
const first = this.all[0];
|
|
1057
|
+
if (!this.log || !this.rooms.readChat || !first || !this.olderKept) {
|
|
1058
|
+
return 0;
|
|
1059
|
+
}
|
|
1060
|
+
const read = await this.rooms.readChat(this.room, { before: first.id, limit });
|
|
1061
|
+
const known = new Set(this.all.map((line) => line.id));
|
|
1062
|
+
const lines = read.lines.filter((line) => !known.has(line.id));
|
|
1063
|
+
this.olderKept = read.more;
|
|
1064
|
+
this.all = [...lines, ...this.all];
|
|
1065
|
+
this.tell();
|
|
1066
|
+
return lines.length;
|
|
1067
|
+
}
|
|
1068
|
+
hear(event) {
|
|
1069
|
+
if (event.room !== undefined && event.room !== this.room) {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
if (event.type === "chat" && event.line) {
|
|
1073
|
+
this.heardLine(event.line);
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1076
|
+
return event.type === "state" && typeof event.key === "string" && this.heard(event.key, event);
|
|
1077
|
+
}
|
|
1078
|
+
heardLine(line) {
|
|
1079
|
+
const index = this.all.findIndex((each) => each.id === line.id);
|
|
1080
|
+
if (index >= 0) {
|
|
1081
|
+
const next = [...this.all];
|
|
1082
|
+
next[index] = line;
|
|
1083
|
+
this.all = next;
|
|
1084
|
+
} else {
|
|
1085
|
+
const next = [...this.all, line];
|
|
1086
|
+
const pending = next.findIndex((each) => each.pending);
|
|
1087
|
+
if (pending >= 0 && !line.pending) {
|
|
1088
|
+
next.splice(next.length - 1, 1);
|
|
1089
|
+
next.splice(pending, 0, line);
|
|
1090
|
+
}
|
|
1091
|
+
this.all = next.length > RELAY_CHAT_WINDOW * 2 ? next.slice(-RELAY_CHAT_WINDOW) : next;
|
|
1092
|
+
this.olderKept || (this.olderKept = next.length > this.all.length);
|
|
1093
|
+
}
|
|
1094
|
+
this.tell();
|
|
1095
|
+
}
|
|
859
1096
|
heard(key, value) {
|
|
1097
|
+
if (this.log) {
|
|
1098
|
+
return !!RelayRoomChatUtil.parse(key);
|
|
1099
|
+
}
|
|
860
1100
|
if (!RelayRoomChatUtil.parse(key)) {
|
|
861
1101
|
return false;
|
|
862
1102
|
}
|
|
@@ -869,16 +1109,23 @@ class RelayRoomChat {
|
|
|
869
1109
|
return true;
|
|
870
1110
|
}
|
|
871
1111
|
async say(text, self, extra = {}) {
|
|
872
|
-
var _a;
|
|
873
|
-
var
|
|
1112
|
+
var _a, _b, _c;
|
|
1113
|
+
var _d, _e;
|
|
874
1114
|
const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
|
|
875
|
-
if (!said) {
|
|
1115
|
+
if (!said && !((_a = extra.images) === null || _a === undefined ? undefined : _a.length) && !((_b = extra.files) === null || _b === undefined ? undefined : _b.length)) {
|
|
876
1116
|
return;
|
|
877
1117
|
}
|
|
1118
|
+
if (this.log && this.rooms.say) {
|
|
1119
|
+
const line = await this.rooms.say(this.room, said, RelayRoomChatUtil.extra(extra));
|
|
1120
|
+
if (line) {
|
|
1121
|
+
this.heardLine(line);
|
|
1122
|
+
}
|
|
1123
|
+
return line;
|
|
1124
|
+
}
|
|
878
1125
|
for (let tries = 0;tries < TRIES; tries++) {
|
|
879
1126
|
const latest = this.latest(self.member);
|
|
880
1127
|
const last = latest === null || latest === undefined ? undefined : latest.lines[latest.lines.length - 1];
|
|
881
|
-
const at = Math.max(Date.now(), ((
|
|
1128
|
+
const at = Math.max(Date.now(), ((_d = last === null || last === undefined ? undefined : last.at) !== null && _d !== undefined ? _d : 0) + 1);
|
|
882
1129
|
const line = {
|
|
883
1130
|
id: RelayRoomChatUtil.id(),
|
|
884
1131
|
from: self.member,
|
|
@@ -892,7 +1139,7 @@ class RelayRoomChat {
|
|
|
892
1139
|
const lines = fits && latest ? [...latest.lines, line] : [line];
|
|
893
1140
|
const key = RelayRoomChatUtil.key(self.member, part);
|
|
894
1141
|
const value = RelayRoomChatUtil.stored(lines);
|
|
895
|
-
const result = await this.rooms.setState(this.room, key, value, (
|
|
1142
|
+
const result = await this.rooms.setState(this.room, key, value, (_e = (_c = this.parts.get(key)) === null || _c === undefined ? undefined : _c.version) !== null && _e !== undefined ? _e : 0);
|
|
896
1143
|
if (result.ok) {
|
|
897
1144
|
this.put(key, { value, version: result.version, by: self.member });
|
|
898
1145
|
this.changed();
|
|
@@ -933,6 +1180,9 @@ class RelayRoomChat {
|
|
|
933
1180
|
}
|
|
934
1181
|
changed() {
|
|
935
1182
|
this.all = [...this.parts.values()].flatMap((part) => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
1183
|
+
this.tell();
|
|
1184
|
+
}
|
|
1185
|
+
tell() {
|
|
936
1186
|
for (const listener of this.listeners) {
|
|
937
1187
|
listener();
|
|
938
1188
|
}
|
|
@@ -1060,8 +1310,28 @@ var EN = {
|
|
|
1060
1310
|
openPage: "Open {name}",
|
|
1061
1311
|
apps: "Apps",
|
|
1062
1312
|
pageLine: "A group chat of {name}: play in it together",
|
|
1313
|
+
unsent: "Not sent: too long",
|
|
1063
1314
|
chatEmpty: "Nothing said yet. Only those in the group chat read it: the relay keeps it sealed.",
|
|
1064
1315
|
chatPlaceholder: "Message",
|
|
1316
|
+
file: "[File]",
|
|
1317
|
+
voice: "[Voice]",
|
|
1318
|
+
video: "[Video]",
|
|
1319
|
+
sendFile: "File",
|
|
1320
|
+
sendVideo: "Video",
|
|
1321
|
+
sendVoice: "Voice",
|
|
1322
|
+
fileTooLarge: "Too large to send: {mb} MB at most",
|
|
1323
|
+
videoTooLong: "A video is 3 minutes at most",
|
|
1324
|
+
fileComing: "Receiving {percent}%",
|
|
1325
|
+
fileWait: "Opens once {name} is online",
|
|
1326
|
+
fileSending: "Sending {name} {percent}%",
|
|
1327
|
+
voiceTitle: "Voice message",
|
|
1328
|
+
voiceLong: "60 seconds at most",
|
|
1329
|
+
voiceCancel: "Cancel",
|
|
1330
|
+
voiceSend: "Send",
|
|
1331
|
+
voiceNoMic: "The microphone cannot be used",
|
|
1332
|
+
picture: "[Picture]",
|
|
1333
|
+
pictureAlt: "A picture from {name}",
|
|
1334
|
+
pictureWait: "Comes once {name} is online",
|
|
1065
1335
|
showOnHome: "Show group chats on the double's home",
|
|
1066
1336
|
showOnHomeHint: "With group chats, the double's home has a Group chats section, beside members and channels.",
|
|
1067
1337
|
friendsDetail: "{n} friends",
|
|
@@ -1071,6 +1341,17 @@ var EN = {
|
|
|
1071
1341
|
inviteFriendsTitle: "Invite friends into “{title}”",
|
|
1072
1342
|
inviteFriendsLead: "Each friend you tap finds the group chat in their Ta: once they join, they are in, without your saying yes again.",
|
|
1073
1343
|
inviteFriendsNone: "All your friends are in, or you have none yet",
|
|
1344
|
+
groupPickLead: "Pick one friend to chat with them, two or more for a group chat.",
|
|
1345
|
+
groupPickLeadFrom: "Pick who else joins you and {name}: a new group chat; this chat stays as it is.",
|
|
1346
|
+
groupPickNone: "No friends yet: invite people by a link",
|
|
1347
|
+
groupPickChat: "Message",
|
|
1348
|
+
groupPickDone: "Start ({n})",
|
|
1349
|
+
groupByLink: "Invite by link or QR code",
|
|
1350
|
+
groupByLinkLine: "For people who are not your friends yet",
|
|
1351
|
+
groupNameSep: ", ",
|
|
1352
|
+
groupNameMore: "{names} and others",
|
|
1353
|
+
directGroup: "Start a group chat",
|
|
1354
|
+
directGroupLine: "With {name} and others, a new chat",
|
|
1074
1355
|
inviteFriendsOld: "Update Ta on this computer to invite friends",
|
|
1075
1356
|
invitedFriend: "Invited",
|
|
1076
1357
|
groupInviteTitle: "Invited to a group chat",
|
|
@@ -1192,15 +1473,35 @@ var ZH = {
|
|
|
1192
1473
|
closedNotice: "「{title}」已被群主解散。",
|
|
1193
1474
|
oldApp: "请更新 Ta 应用后再使用群聊。",
|
|
1194
1475
|
room: "群聊",
|
|
1195
|
-
newRoom: "
|
|
1476
|
+
newRoom: "发起群聊",
|
|
1196
1477
|
newRoomPlaceholder: "群聊名,受邀的人能看到",
|
|
1197
1478
|
roomOfName: "{name}的群聊",
|
|
1198
1479
|
back: "返回",
|
|
1199
1480
|
openPage: "打开{name}",
|
|
1200
1481
|
apps: "应用",
|
|
1201
1482
|
pageLine: "{name}的群聊,大家可以一起玩",
|
|
1483
|
+
unsent: "未发出:内容太长",
|
|
1202
1484
|
chatEmpty: "还没有人说话。只有群里的人能看到,中继保存的是密文。",
|
|
1203
1485
|
chatPlaceholder: "发消息",
|
|
1486
|
+
file: "[文件]",
|
|
1487
|
+
voice: "[语音]",
|
|
1488
|
+
video: "[视频]",
|
|
1489
|
+
sendFile: "文件",
|
|
1490
|
+
sendVideo: "视频",
|
|
1491
|
+
sendVoice: "语音",
|
|
1492
|
+
fileTooLarge: "文件太大,最多 {mb} MB",
|
|
1493
|
+
videoTooLong: "视频最长 3 分钟",
|
|
1494
|
+
fileComing: "正在接收 {percent}%",
|
|
1495
|
+
fileWait: "等{name}上线后可以打开",
|
|
1496
|
+
fileSending: "正在发送 {name} {percent}%",
|
|
1497
|
+
voiceTitle: "语音消息",
|
|
1498
|
+
voiceLong: "最长 60 秒",
|
|
1499
|
+
voiceCancel: "取消",
|
|
1500
|
+
voiceSend: "发送",
|
|
1501
|
+
voiceNoMic: "无法使用麦克风",
|
|
1502
|
+
picture: "[图片]",
|
|
1503
|
+
pictureAlt: "{name}发的图片",
|
|
1504
|
+
pictureWait: "等{name}上线后显示",
|
|
1204
1505
|
showOnHome: "在分身首页显示群聊",
|
|
1205
1506
|
showOnHomeHint: "有群聊时,分身首页多一个“群聊”分类,和成员、频道放在一起。",
|
|
1206
1507
|
friendsDetail: "{n} 位好友",
|
|
@@ -1210,6 +1511,17 @@ var ZH = {
|
|
|
1210
1511
|
inviteFriendsTitle: "邀请好友进「{title}」",
|
|
1211
1512
|
inviteFriendsLead: "点一位好友,对方就会在自己的 Ta 里看到这个群聊;对方点加入就直接进来,不用你再同意。",
|
|
1212
1513
|
inviteFriendsNone: "好友都在群里了,或者还没有好友",
|
|
1514
|
+
groupPickLead: "选一位好友就是私聊,选两位以上建群聊。",
|
|
1515
|
+
groupPickLeadFrom: "选要拉进来的人,和你、{name}另建一个群聊;这个私聊不变。",
|
|
1516
|
+
groupPickNone: "还没有好友,可以用链接邀请",
|
|
1517
|
+
groupPickChat: "发消息",
|
|
1518
|
+
groupPickDone: "完成({n})",
|
|
1519
|
+
groupByLink: "用链接或二维码邀请",
|
|
1520
|
+
groupByLinkLine: "邀请还不是好友的人",
|
|
1521
|
+
groupNameSep: "、",
|
|
1522
|
+
groupNameMore: "{names}等",
|
|
1523
|
+
directGroup: "发起群聊",
|
|
1524
|
+
directGroupLine: "拉上别人和{name}另建一个群",
|
|
1213
1525
|
inviteFriendsOld: "先把这台电脑上的 Ta 更新到新版,才能邀请好友",
|
|
1214
1526
|
invitedFriend: "已邀请",
|
|
1215
1527
|
groupInviteTitle: "群聊邀请",
|
|
@@ -1331,15 +1643,35 @@ var ZH_TW = {
|
|
|
1331
1643
|
closedNotice: "「{title}」已被群主解散。",
|
|
1332
1644
|
oldApp: "請更新 Ta 應用後再使用群聊。",
|
|
1333
1645
|
room: "群聊",
|
|
1334
|
-
newRoom: "
|
|
1646
|
+
newRoom: "發起群聊",
|
|
1335
1647
|
newRoomPlaceholder: "群聊名,受邀的人能看到",
|
|
1336
1648
|
roomOfName: "{name}的群聊",
|
|
1337
1649
|
back: "返回",
|
|
1338
1650
|
openPage: "開啟{name}",
|
|
1339
1651
|
apps: "應用",
|
|
1340
1652
|
pageLine: "{name}的群聊,大家可以一起玩",
|
|
1653
|
+
unsent: "未送出:內容太長",
|
|
1341
1654
|
chatEmpty: "還沒有人說話。只有群裡的人能看到,中繼儲存的是密文。",
|
|
1342
1655
|
chatPlaceholder: "發訊息",
|
|
1656
|
+
file: "[檔案]",
|
|
1657
|
+
voice: "[語音]",
|
|
1658
|
+
video: "[影片]",
|
|
1659
|
+
sendFile: "檔案",
|
|
1660
|
+
sendVideo: "影片",
|
|
1661
|
+
sendVoice: "語音",
|
|
1662
|
+
fileTooLarge: "檔案太大,最多 {mb} MB",
|
|
1663
|
+
videoTooLong: "影片最長 3 分鐘",
|
|
1664
|
+
fileComing: "正在接收 {percent}%",
|
|
1665
|
+
fileWait: "等{name}上線後可以打開",
|
|
1666
|
+
fileSending: "正在傳送 {name} {percent}%",
|
|
1667
|
+
voiceTitle: "語音訊息",
|
|
1668
|
+
voiceLong: "最長 60 秒",
|
|
1669
|
+
voiceCancel: "取消",
|
|
1670
|
+
voiceSend: "傳送",
|
|
1671
|
+
voiceNoMic: "無法使用麥克風",
|
|
1672
|
+
picture: "[圖片]",
|
|
1673
|
+
pictureAlt: "{name}傳的圖片",
|
|
1674
|
+
pictureWait: "等{name}上線後顯示",
|
|
1343
1675
|
showOnHome: "在分身首頁顯示群聊",
|
|
1344
1676
|
showOnHomeHint: "有群聊時,分身首頁多一個「群聊」分類,和成員、頻道放在一起。",
|
|
1345
1677
|
friendsDetail: "{n} 位好友",
|
|
@@ -1349,6 +1681,17 @@ var ZH_TW = {
|
|
|
1349
1681
|
inviteFriendsTitle: "邀請好友進「{title}」",
|
|
1350
1682
|
inviteFriendsLead: "點一位好友,對方就會在自己的 Ta 裡看到這個群聊;對方點加入就直接進來,不用你再同意。",
|
|
1351
1683
|
inviteFriendsNone: "好友都在群裡了,或者還沒有好友",
|
|
1684
|
+
groupPickLead: "選一位好友就是私聊,選兩位以上建群聊。",
|
|
1685
|
+
groupPickLeadFrom: "選要拉進來的人,和你、{name}另建一個群聊;這個私聊不變。",
|
|
1686
|
+
groupPickNone: "還沒有好友,可以用連結邀請",
|
|
1687
|
+
groupPickChat: "發訊息",
|
|
1688
|
+
groupPickDone: "完成({n})",
|
|
1689
|
+
groupByLink: "用連結或 QR 碼邀請",
|
|
1690
|
+
groupByLinkLine: "邀請還不是好友的人",
|
|
1691
|
+
groupNameSep: "、",
|
|
1692
|
+
groupNameMore: "{names}等",
|
|
1693
|
+
directGroup: "發起群聊",
|
|
1694
|
+
directGroupLine: "拉上別人和{name}另建一個群",
|
|
1352
1695
|
inviteFriendsOld: "先把這台電腦上的 Ta 更新到新版,才能邀請好友",
|
|
1353
1696
|
invitedFriend: "已邀請",
|
|
1354
1697
|
groupInviteTitle: "群聊邀請",
|
|
@@ -1477,8 +1820,28 @@ var JA = {
|
|
|
1477
1820
|
openPage: "{name} を開く",
|
|
1478
1821
|
apps: "アプリ",
|
|
1479
1822
|
pageLine: "{name} のグループチャット:一緒にプレイします",
|
|
1823
|
+
unsent: "送信できませんでした:長すぎます",
|
|
1480
1824
|
chatEmpty: "まだ何も言われていません。グループ内の人だけが見ることができます。リレーは暗号化されて保存します。",
|
|
1481
1825
|
chatPlaceholder: "メッセージ",
|
|
1826
|
+
file: "[ファイル]",
|
|
1827
|
+
voice: "[ボイス]",
|
|
1828
|
+
video: "[動画]",
|
|
1829
|
+
sendFile: "ファイル",
|
|
1830
|
+
sendVideo: "動画",
|
|
1831
|
+
sendVoice: "ボイス",
|
|
1832
|
+
fileTooLarge: "大きすぎます(最大 {mb} MB)",
|
|
1833
|
+
videoTooLong: "動画は最長 3 分です",
|
|
1834
|
+
fileComing: "受信中 {percent}%",
|
|
1835
|
+
fileWait: "{name}がオンラインになると開けます",
|
|
1836
|
+
fileSending: "{name} を送信中 {percent}%",
|
|
1837
|
+
voiceTitle: "ボイスメッセージ",
|
|
1838
|
+
voiceLong: "最長 60 秒",
|
|
1839
|
+
voiceCancel: "キャンセル",
|
|
1840
|
+
voiceSend: "送信",
|
|
1841
|
+
voiceNoMic: "マイクを使えません",
|
|
1842
|
+
picture: "[画像]",
|
|
1843
|
+
pictureAlt: "{name}からの画像",
|
|
1844
|
+
pictureWait: "{name}がオンラインになると表示",
|
|
1482
1845
|
showOnHome: "分身のホームにグループチャットを表示",
|
|
1483
1846
|
showOnHomeHint: "グループチャットがあると、分身のホームに「グループチャット」セクションが追加され、メンバーとチャンネルと一緒に表示されます。",
|
|
1484
1847
|
friendsDetail: "友だち {n} 人",
|
|
@@ -1488,6 +1851,17 @@ var JA = {
|
|
|
1488
1851
|
inviteFriendsTitle: "「{title}」に友だちを招待",
|
|
1489
1852
|
inviteFriendsLead: "友だちをタップすると、その人の Ta にこのグループチャットが届きます。参加すれば、あなたの承認なしで入れます。",
|
|
1490
1853
|
inviteFriendsNone: "友だちは全員参加済みか、まだ友だちがいません",
|
|
1854
|
+
groupPickLead: "友だちを一人選ぶとその人とのチャット、二人以上でグループチャットになります。",
|
|
1855
|
+
groupPickLeadFrom: "あなたと{name}に加える人を選ぶと、新しいグループチャットになります。このチャットはそのままです。",
|
|
1856
|
+
groupPickNone: "まだ友だちがいません。リンクで招待できます",
|
|
1857
|
+
groupPickChat: "メッセージ",
|
|
1858
|
+
groupPickDone: "完了({n})",
|
|
1859
|
+
groupByLink: "リンクか QR コードで招待",
|
|
1860
|
+
groupByLinkLine: "まだ友だちでない人を招待",
|
|
1861
|
+
groupNameSep: "、",
|
|
1862
|
+
groupNameMore: "{names}ほか",
|
|
1863
|
+
directGroup: "グループチャットを作成",
|
|
1864
|
+
directGroupLine: "{name}とほかの人で新しいチャット",
|
|
1491
1865
|
inviteFriendsOld: "友だちを招待するには、このコンピュータの Ta を更新してください",
|
|
1492
1866
|
invitedFriend: "招待済み",
|
|
1493
1867
|
groupInviteTitle: "グループチャットへの招待",
|
|
@@ -1690,10 +2064,10 @@ class RoomBook {
|
|
|
1690
2064
|
this.putAgents(room, { ...known, [key]: { value: agents, by: member, version: known[key]?.version ?? 0 } });
|
|
1691
2065
|
}
|
|
1692
2066
|
heard(event) {
|
|
2067
|
+
this.chats.get("room" in event ? event.room : "")?.hear(event);
|
|
1693
2068
|
if (event.type !== "state") {
|
|
1694
2069
|
return;
|
|
1695
2070
|
}
|
|
1696
|
-
this.chats.get(event.room)?.heard(event.key, event);
|
|
1697
2071
|
const known = this.agentStates.get(event.room);
|
|
1698
2072
|
if (known && event.key.startsWith(ROOM_AGENTS_KEY) && (known[event.key]?.version ?? 0) < event.version) {
|
|
1699
2073
|
this.putAgents(event.room, { ...known, [event.key]: event });
|
|
@@ -2033,6 +2407,7 @@ class DirectBook {
|
|
|
2033
2407
|
kept = {};
|
|
2034
2408
|
listeners = new Set;
|
|
2035
2409
|
started = false;
|
|
2410
|
+
loaded = false;
|
|
2036
2411
|
get() {
|
|
2037
2412
|
return this.kept;
|
|
2038
2413
|
}
|
|
@@ -2062,9 +2437,11 @@ class DirectBook {
|
|
|
2062
2437
|
}
|
|
2063
2438
|
}
|
|
2064
2439
|
async read() {
|
|
2065
|
-
|
|
2440
|
+
const value = await pi.storage.get(DIRECT_KEY).then((kept) => kept ?? {}, () => {
|
|
2066
2441
|
return;
|
|
2067
|
-
})
|
|
2442
|
+
});
|
|
2443
|
+
this.loaded ||= value !== undefined;
|
|
2444
|
+
this.put(DirectUtil.parse(value));
|
|
2068
2445
|
}
|
|
2069
2446
|
put(kept) {
|
|
2070
2447
|
this.kept = kept;
|
|
@@ -2102,7 +2479,16 @@ function DirectFace({ room, size, unread }) {
|
|
|
2102
2479
|
className: "trm-unread"
|
|
2103
2480
|
}));
|
|
2104
2481
|
}
|
|
2105
|
-
|
|
2482
|
+
function openDirect(friend) {
|
|
2483
|
+
let open = opening.get(friend.id);
|
|
2484
|
+
if (!open) {
|
|
2485
|
+
open = openOrMake(friend).finally(() => opening.delete(friend.id));
|
|
2486
|
+
opening.set(friend.id, open);
|
|
2487
|
+
}
|
|
2488
|
+
return open;
|
|
2489
|
+
}
|
|
2490
|
+
var opening = new Map;
|
|
2491
|
+
async function openOrMake(friend) {
|
|
2106
2492
|
const server = rooms();
|
|
2107
2493
|
if (!server?.inviteFriends) {
|
|
2108
2494
|
return;
|
|
@@ -2134,6 +2520,20 @@ async function openDirect(friend) {
|
|
|
2134
2520
|
pi.ui.notify(message(error), "error");
|
|
2135
2521
|
}
|
|
2136
2522
|
}
|
|
2523
|
+
var tidied = new Set;
|
|
2524
|
+
function tidyDirects(list) {
|
|
2525
|
+
const server = rooms();
|
|
2526
|
+
for (const room of DirectUtil.extra(list, directs.get())) {
|
|
2527
|
+
if (!server || !directs.loaded || !room.owner || !DirectUtil.peer(room) || tidied.has(room.id)) {
|
|
2528
|
+
continue;
|
|
2529
|
+
}
|
|
2530
|
+
tidied.add(room.id);
|
|
2531
|
+
const chat = book.chat(room.id);
|
|
2532
|
+
chat?.load().then(() => chat.lines.length === 0 ? server.leave(room.id).then(() => book.load()) : undefined).catch(() => {
|
|
2533
|
+
return;
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2137
2537
|
var reinvited = new Set;
|
|
2138
2538
|
function reinvite(room) {
|
|
2139
2539
|
const friend = DirectUtil.friendOf(room, directs.get());
|
|
@@ -2874,7 +3274,7 @@ var EN3 = {
|
|
|
2874
3274
|
drafted: "Drafted",
|
|
2875
3275
|
message: "Message",
|
|
2876
3276
|
directEmpty: "Your chat with {name}",
|
|
2877
|
-
directHint: "
|
|
3277
|
+
directHint: "End-to-end encrypted, just the two of you",
|
|
2878
3278
|
directWaiting: "{name} gets it in their Ta",
|
|
2879
3279
|
directDelete: "Delete the chat",
|
|
2880
3280
|
directDeleteTitle: "Delete your chat with {name}?",
|
|
@@ -2912,7 +3312,8 @@ var EN3 = {
|
|
|
2912
3312
|
approveTitle: "{name} hands your double a task",
|
|
2913
3313
|
approveTake: "Take it",
|
|
2914
3314
|
approveDecline: "Not this time",
|
|
2915
|
-
approveWaiting: "Waits for you to take it"
|
|
3315
|
+
approveWaiting: "Waits for you to take it",
|
|
3316
|
+
approveHint: "Taken, it counts as yours: within what you let {name} have, pushing and deploying are not blocked either."
|
|
2916
3317
|
};
|
|
2917
3318
|
var ZH3 = {
|
|
2918
3319
|
replyTitle: "别人与我的分身",
|
|
@@ -2953,7 +3354,7 @@ var ZH3 = {
|
|
|
2953
3354
|
drafted: "已拟稿",
|
|
2954
3355
|
message: "发消息",
|
|
2955
3356
|
directEmpty: "和{name}的聊天",
|
|
2956
|
-
directHint: "
|
|
3357
|
+
directHint: "端到端加密,只有你们两人可见",
|
|
2957
3358
|
directWaiting: "{name}会在自己的 Ta 里收到",
|
|
2958
3359
|
directDelete: "删除聊天",
|
|
2959
3360
|
directDeleteTitle: "删除和{name}的聊天?",
|
|
@@ -2991,7 +3392,8 @@ var ZH3 = {
|
|
|
2991
3392
|
approveTitle: "{name}给你的分身派了任务",
|
|
2992
3393
|
approveTake: "接",
|
|
2993
3394
|
approveDecline: "这次不接",
|
|
2994
|
-
approveWaiting: "等你决定接不接"
|
|
3395
|
+
approveWaiting: "等你决定接不接",
|
|
3396
|
+
approveHint: "接下后按你发起的算:在你给{name}授权的范围内,推送、部署也不再拦。"
|
|
2995
3397
|
};
|
|
2996
3398
|
var ZH_TW3 = {
|
|
2997
3399
|
replyTitle: "別人與我的分身",
|
|
@@ -3032,7 +3434,7 @@ var ZH_TW3 = {
|
|
|
3032
3434
|
drafted: "已擬稿",
|
|
3033
3435
|
message: "傳訊息",
|
|
3034
3436
|
directEmpty: "和{name}的聊天",
|
|
3035
|
-
directHint: "
|
|
3437
|
+
directHint: "端對端加密,只有你們兩人可見",
|
|
3036
3438
|
directWaiting: "{name}會在自己的 Ta 裡收到",
|
|
3037
3439
|
directDelete: "刪除聊天",
|
|
3038
3440
|
directDeleteTitle: "刪除和{name}的聊天?",
|
|
@@ -3070,7 +3472,8 @@ var ZH_TW3 = {
|
|
|
3070
3472
|
approveTitle: "{name}給你的分身派了任務",
|
|
3071
3473
|
approveTake: "接",
|
|
3072
3474
|
approveDecline: "這次不接",
|
|
3073
|
-
approveWaiting: "等你決定接不接"
|
|
3475
|
+
approveWaiting: "等你決定接不接",
|
|
3476
|
+
approveHint: "接下後按你發起的算:在你給{name}授權的範圍內,推送、部署也不再攔。"
|
|
3074
3477
|
};
|
|
3075
3478
|
var JA3 = {
|
|
3076
3479
|
replyTitle: "ほかの人と分身",
|
|
@@ -3111,7 +3514,7 @@ var JA3 = {
|
|
|
3111
3514
|
drafted: "下書き済み",
|
|
3112
3515
|
message: "メッセージ",
|
|
3113
3516
|
directEmpty: "{name} とのチャット",
|
|
3114
|
-
directHint: "
|
|
3517
|
+
directHint: "エンドツーエンド暗号化、ふたりだけに表示",
|
|
3115
3518
|
directWaiting: "{name} の Ta に届きます",
|
|
3116
3519
|
directDelete: "チャットを削除",
|
|
3117
3520
|
directDeleteTitle: "{name} とのチャットを削除しますか?",
|
|
@@ -3149,7 +3552,8 @@ var JA3 = {
|
|
|
3149
3552
|
approveTitle: "{name}があなたの分身にタスクを依頼しました",
|
|
3150
3553
|
approveTake: "受ける",
|
|
3151
3554
|
approveDecline: "今回は受けない",
|
|
3152
|
-
approveWaiting: "受けるかどうか待っています"
|
|
3555
|
+
approveWaiting: "受けるかどうか待っています",
|
|
3556
|
+
approveHint: "受けると、あなたが頼んだものとして扱います。{name}に許可した範囲内では、プッシュやデプロイもブロックしません。"
|
|
3153
3557
|
};
|
|
3154
3558
|
var REPLY_WORDS = { "zh-CN": ZH3, "zh-TW": ZH_TW3, "en-US": EN3, "ja-JP": JA3 };
|
|
3155
3559
|
function rt(key, values = {}) {
|
|
@@ -3359,7 +3763,9 @@ function ApproveDialog({ task, close }) {
|
|
|
3359
3763
|
size: 36
|
|
3360
3764
|
}), /* @__PURE__ */ React.createElement("p", {
|
|
3361
3765
|
className: "trm-lead"
|
|
3362
|
-
}, task.text)), /* @__PURE__ */ React.createElement("
|
|
3766
|
+
}, task.text)), /* @__PURE__ */ React.createElement("p", {
|
|
3767
|
+
className: "trm-note"
|
|
3768
|
+
}, rt("approveHint", { name: task.name })), /* @__PURE__ */ React.createElement("div", {
|
|
3363
3769
|
className: "trm-actions"
|
|
3364
3770
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
3365
3771
|
type: "button",
|
|
@@ -4094,115 +4500,732 @@ function AgentRow({ room, agent }) {
|
|
|
4094
4500
|
})));
|
|
4095
4501
|
}
|
|
4096
4502
|
|
|
4097
|
-
// web-src/
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
}
|
|
4118
|
-
|
|
4119
|
-
const lines = text.split(`
|
|
4120
|
-
`).map((line) => line.trim());
|
|
4121
|
-
const first = lines.find((line) => line && !line.startsWith("|") && !line.startsWith("```")) ?? lines.find(Boolean) ?? "";
|
|
4122
|
-
return first.replace(/^#+\s*|^[-*]\s+|\*\*|__|`/g, "").trim();
|
|
4123
|
-
}
|
|
4124
|
-
function listed(status, mine) {
|
|
4125
|
-
if (!RoomTasksUtil.ended(status)) {
|
|
4126
|
-
return mine && status === "permission" ? "waiting" : "running";
|
|
4503
|
+
// web-src/files-view.tsx
|
|
4504
|
+
var CALL_BYTES = 384 * 1024;
|
|
4505
|
+
var AGAIN_MS = 1500;
|
|
4506
|
+
var KEPT = 6;
|
|
4507
|
+
var THUMB_SIDE = 16;
|
|
4508
|
+
var FilesUtil;
|
|
4509
|
+
((FilesUtil) => {
|
|
4510
|
+
function size(bytes) {
|
|
4511
|
+
return bytes < 1024 * 1024 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4512
|
+
}
|
|
4513
|
+
FilesUtil.size = size;
|
|
4514
|
+
function seconds(ms = 0) {
|
|
4515
|
+
const all = Math.max(1, Math.round(ms / 1000));
|
|
4516
|
+
return all < 60 ? `${all}″` : `${Math.floor(all / 60)}:${String(all % 60).padStart(2, "0")}`;
|
|
4517
|
+
}
|
|
4518
|
+
FilesUtil.seconds = seconds;
|
|
4519
|
+
function base64(bytes) {
|
|
4520
|
+
let binary = "";
|
|
4521
|
+
for (let at = 0;at < bytes.length; at += 32768) {
|
|
4522
|
+
binary += String.fromCharCode(...bytes.subarray(at, at + 32768));
|
|
4523
|
+
}
|
|
4524
|
+
return btoa(binary);
|
|
4127
4525
|
}
|
|
4128
|
-
|
|
4129
|
-
}
|
|
4130
|
-
function act(run) {
|
|
4131
|
-
return () => void run().catch((error) => pi.ui.notify(message(error), "error"));
|
|
4132
|
-
}
|
|
4526
|
+
FilesUtil.base64 = base64;
|
|
4527
|
+
})(FilesUtil ||= {});
|
|
4133
4528
|
|
|
4134
|
-
class
|
|
4135
|
-
|
|
4136
|
-
|
|
4529
|
+
class FileStore {
|
|
4530
|
+
urls = new Map;
|
|
4531
|
+
progress = new Map;
|
|
4137
4532
|
listeners = new Set;
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4533
|
+
url(room, id) {
|
|
4534
|
+
return this.urls.get(`${room}:${id}`);
|
|
4535
|
+
}
|
|
4536
|
+
coming(room, id) {
|
|
4537
|
+
return this.progress.get(`${room}:${id}`);
|
|
4141
4538
|
}
|
|
4142
4539
|
subscribe(listener) {
|
|
4143
|
-
if (this.listeners.size === 0) {
|
|
4144
|
-
const unsubscribe = doubles.subscribe(() => this.build(doubles.get()));
|
|
4145
|
-
const stopStore = doubles.start();
|
|
4146
|
-
this.stop = () => {
|
|
4147
|
-
unsubscribe();
|
|
4148
|
-
stopStore();
|
|
4149
|
-
};
|
|
4150
|
-
this.build(doubles.get());
|
|
4151
|
-
}
|
|
4152
4540
|
this.listeners.add(listener);
|
|
4153
|
-
return () =>
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4541
|
+
return () => this.listeners.delete(listener);
|
|
4542
|
+
}
|
|
4543
|
+
async open(room, file) {
|
|
4544
|
+
const key = `${room}:${file.id}`;
|
|
4545
|
+
const known = this.urls.get(key);
|
|
4546
|
+
if (known) {
|
|
4547
|
+
return known;
|
|
4548
|
+
}
|
|
4549
|
+
const parts = [];
|
|
4550
|
+
for (let offset = 0;offset < file.bytes; ) {
|
|
4551
|
+
const read = await callDoubles({ kind: "fileRead", room, id: file.id, offset });
|
|
4552
|
+
if (read.status !== "here") {
|
|
4553
|
+
this.set(key, read.status === "coming" ? read.got / Math.max(read.bytes, 1) : -1);
|
|
4554
|
+
return;
|
|
4158
4555
|
}
|
|
4159
|
-
|
|
4556
|
+
const bytes = Uint8Array.from(atob(read.data), (char) => char.charCodeAt(0));
|
|
4557
|
+
if (!bytes.length) {
|
|
4558
|
+
return;
|
|
4559
|
+
}
|
|
4560
|
+
parts.push(bytes);
|
|
4561
|
+
offset += bytes.length;
|
|
4562
|
+
if (offset < file.bytes) {
|
|
4563
|
+
this.set(key, offset / file.bytes);
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4566
|
+
const url = URL.createObjectURL(new Blob(parts, { type: file.type }));
|
|
4567
|
+
this.urls.set(key, url);
|
|
4568
|
+
this.progress.delete(key);
|
|
4569
|
+
for (const old of this.urls.keys()) {
|
|
4570
|
+
if (this.urls.size <= KEPT) {
|
|
4571
|
+
break;
|
|
4572
|
+
}
|
|
4573
|
+
URL.revokeObjectURL(this.urls.get(old));
|
|
4574
|
+
this.urls.delete(old);
|
|
4575
|
+
}
|
|
4576
|
+
this.tell();
|
|
4577
|
+
return url;
|
|
4160
4578
|
}
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4579
|
+
set(key, value) {
|
|
4580
|
+
this.progress.set(key, value);
|
|
4581
|
+
this.tell();
|
|
4582
|
+
}
|
|
4583
|
+
tell() {
|
|
4584
|
+
for (const listener of this.listeners) {
|
|
4585
|
+
listener();
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
var store = new FileStore;
|
|
4590
|
+
function use(file, url) {
|
|
4591
|
+
if (file.kind === "voice") {
|
|
4592
|
+
new Audio(url).play().catch(() => {
|
|
4593
|
+
return;
|
|
4594
|
+
});
|
|
4595
|
+
} else if (file.kind === "video") {
|
|
4596
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4597
|
+
title: file.name,
|
|
4598
|
+
onClose: close
|
|
4599
|
+
}, /* @__PURE__ */ React.createElement("video", {
|
|
4600
|
+
className: "trm-video-play",
|
|
4601
|
+
src: url,
|
|
4602
|
+
controls: true,
|
|
4603
|
+
autoPlay: true,
|
|
4604
|
+
playsInline: true
|
|
4605
|
+
})));
|
|
4606
|
+
} else {
|
|
4607
|
+
const link = document.createElement("a");
|
|
4608
|
+
link.href = url;
|
|
4609
|
+
link.download = file.name;
|
|
4610
|
+
link.click();
|
|
4611
|
+
}
|
|
4612
|
+
}
|
|
4613
|
+
function useOpen(room, file) {
|
|
4614
|
+
const read = () => `${store.url(room, file.id) ? "here" : ""}:${store.coming(room, file.id) ?? ""}`;
|
|
4615
|
+
const state = React.useSyncExternalStore((listener) => store.subscribe(listener), read);
|
|
4616
|
+
const [wanted, setWanted] = React.useState(false);
|
|
4617
|
+
const [here, coming] = state.split(":");
|
|
4618
|
+
React.useEffect(() => {
|
|
4619
|
+
if (!wanted) {
|
|
4167
4620
|
return;
|
|
4168
4621
|
}
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
if (!
|
|
4172
|
-
|
|
4622
|
+
let opened = false;
|
|
4623
|
+
const again = () => void store.open(room, file).then((url) => {
|
|
4624
|
+
if (url && !opened) {
|
|
4625
|
+
opened = true;
|
|
4626
|
+
setWanted(false);
|
|
4627
|
+
use(file, url);
|
|
4628
|
+
}
|
|
4629
|
+
}, (error) => pi.ui.notify(message(error), "error"));
|
|
4630
|
+
again();
|
|
4631
|
+
const timer = setInterval(again, AGAIN_MS);
|
|
4632
|
+
const came = pi.storage?.onChange((keys) => keys.includes(DoubleKeys.FILES) && again());
|
|
4633
|
+
return () => {
|
|
4634
|
+
clearInterval(timer);
|
|
4635
|
+
came?.();
|
|
4636
|
+
};
|
|
4637
|
+
}, [wanted, room, file]);
|
|
4638
|
+
return {
|
|
4639
|
+
here: !!here,
|
|
4640
|
+
...wanted && coming !== "" ? { coming: Number(coming) } : {},
|
|
4641
|
+
open: () => {
|
|
4642
|
+
const url = store.url(room, file.id);
|
|
4643
|
+
if (url) {
|
|
4644
|
+
use(file, url);
|
|
4645
|
+
} else {
|
|
4646
|
+
setWanted(true);
|
|
4173
4647
|
}
|
|
4174
4648
|
}
|
|
4175
|
-
|
|
4649
|
+
};
|
|
4650
|
+
}
|
|
4651
|
+
function FileItem({ room, file, name }) {
|
|
4652
|
+
const { open, coming } = useOpen(room, file);
|
|
4653
|
+
const status = coming === undefined ? FilesUtil.size(file.bytes) : coming < 0 ? t("fileWait", { name }) : t("fileComing", { percent: Math.floor(coming * 100) });
|
|
4654
|
+
if (file.kind === "voice") {
|
|
4655
|
+
const Mic = icon("Mic");
|
|
4656
|
+
const width = 72 + Math.min(1, (file.ms ?? 0) / RELAY_CHAT_VOICE_MS) * 120;
|
|
4657
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4658
|
+
type: "button",
|
|
4659
|
+
className: "trm-voice",
|
|
4660
|
+
style: { width },
|
|
4661
|
+
onClick: open,
|
|
4662
|
+
"aria-label": t("voice")
|
|
4663
|
+
}, /* @__PURE__ */ React.createElement(Mic, {
|
|
4664
|
+
size: 15
|
|
4665
|
+
}), /* @__PURE__ */ React.createElement("span", null, coming === undefined ? FilesUtil.seconds(file.ms) : status));
|
|
4666
|
+
}
|
|
4667
|
+
if (file.kind === "video") {
|
|
4668
|
+
const Play = icon("Play");
|
|
4669
|
+
const ratio = file.w && file.h ? file.w / file.h : 16 / 9;
|
|
4670
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4671
|
+
type: "button",
|
|
4672
|
+
className: "trm-video",
|
|
4673
|
+
style: { aspectRatio: String(ratio), ...file.thumb ? { backgroundImage: `url(${file.thumb})` } : {} },
|
|
4674
|
+
onClick: open,
|
|
4675
|
+
"aria-label": file.name
|
|
4676
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4677
|
+
className: "trm-video-mark"
|
|
4678
|
+
}, /* @__PURE__ */ React.createElement(Play, {
|
|
4679
|
+
size: 18
|
|
4680
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
4681
|
+
className: "trm-video-time"
|
|
4682
|
+
}, coming === undefined ? FilesUtil.seconds(file.ms) : status));
|
|
4683
|
+
}
|
|
4684
|
+
const File = icon("FileText");
|
|
4685
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4686
|
+
type: "button",
|
|
4687
|
+
className: "trm-file",
|
|
4688
|
+
onClick: open
|
|
4689
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4690
|
+
className: "trm-file-text"
|
|
4691
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4692
|
+
className: "trm-file-name"
|
|
4693
|
+
}, file.name), /* @__PURE__ */ React.createElement("span", {
|
|
4694
|
+
className: "trm-file-size"
|
|
4695
|
+
}, status)), /* @__PURE__ */ React.createElement(File, {
|
|
4696
|
+
size: 28
|
|
4697
|
+
}));
|
|
4698
|
+
}
|
|
4699
|
+
function LineFiles({ room, line, name }) {
|
|
4700
|
+
if (!line.files?.length) {
|
|
4701
|
+
return null;
|
|
4702
|
+
}
|
|
4703
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4704
|
+
className: "trm-files"
|
|
4705
|
+
}, line.files.map((file) => /* @__PURE__ */ React.createElement(FileItem, {
|
|
4706
|
+
key: file.id,
|
|
4707
|
+
room,
|
|
4708
|
+
file,
|
|
4709
|
+
name
|
|
4710
|
+
})));
|
|
4711
|
+
}
|
|
4712
|
+
function videoLook(blob) {
|
|
4713
|
+
return new Promise((resolve) => {
|
|
4714
|
+
const url = URL.createObjectURL(blob);
|
|
4715
|
+
const video = document.createElement("video");
|
|
4716
|
+
const done = (look) => {
|
|
4717
|
+
URL.revokeObjectURL(url);
|
|
4718
|
+
resolve(look);
|
|
4719
|
+
};
|
|
4720
|
+
const timer = setTimeout(() => done({}), 8000);
|
|
4721
|
+
video.muted = true;
|
|
4722
|
+
video.playsInline = true;
|
|
4723
|
+
video.preload = "auto";
|
|
4724
|
+
video.onloadeddata = () => {
|
|
4725
|
+
video.currentTime = Math.min(0.1, video.duration || 0);
|
|
4726
|
+
};
|
|
4727
|
+
video.onseeked = () => {
|
|
4728
|
+
clearTimeout(timer);
|
|
4729
|
+
const w = video.videoWidth;
|
|
4730
|
+
const h = video.videoHeight;
|
|
4731
|
+
const ms = Number.isFinite(video.duration) ? Math.round(video.duration * 1000) : undefined;
|
|
4732
|
+
const scale = THUMB_SIDE / Math.max(w, h, 1);
|
|
4733
|
+
const canvas = document.createElement("canvas");
|
|
4734
|
+
canvas.width = Math.max(1, Math.round(w * scale));
|
|
4735
|
+
canvas.height = Math.max(1, Math.round(h * scale));
|
|
4736
|
+
const context = canvas.getContext("2d");
|
|
4737
|
+
context?.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
4738
|
+
const thumb = context ? [canvas.toDataURL("image/webp", 0.5), canvas.toDataURL("image/jpeg", 0.3), canvas.toDataURL("image/png")].find((each) => each.length <= 900) : undefined;
|
|
4739
|
+
done({ ...w && h ? { w, h } : {}, ...ms ? { ms } : {}, ...thumb && thumb.length <= 900 ? { thumb } : {} });
|
|
4740
|
+
};
|
|
4741
|
+
video.onerror = () => {
|
|
4742
|
+
clearTimeout(timer);
|
|
4743
|
+
done({});
|
|
4744
|
+
};
|
|
4745
|
+
video.src = url;
|
|
4746
|
+
});
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
class Uploads {
|
|
4750
|
+
going = new Map;
|
|
4751
|
+
listeners = new Set;
|
|
4752
|
+
tell() {
|
|
4176
4753
|
for (const listener of this.listeners) {
|
|
4177
4754
|
listener();
|
|
4178
4755
|
}
|
|
4179
4756
|
}
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4757
|
+
}
|
|
4758
|
+
var uploads = new Uploads;
|
|
4759
|
+
async function sendFile(room, blob, kind, name, known = {}) {
|
|
4760
|
+
const most = RELAY_CHAT_FILE_BYTES[kind];
|
|
4761
|
+
if (blob.size > most) {
|
|
4762
|
+
throw new Error(t("fileTooLarge", { mb: Math.round(most / (1024 * 1024)) }));
|
|
4763
|
+
}
|
|
4764
|
+
const look = kind === "video" ? await videoLook(blob) : {};
|
|
4765
|
+
if (kind === "video" && (look.ms ?? 0) > RELAY_CHAT_VIDEO_MS) {
|
|
4766
|
+
throw new Error(t("videoTooLong"));
|
|
4767
|
+
}
|
|
4768
|
+
const type = blob.type || "application/octet-stream";
|
|
4769
|
+
const upload = await callDoubles({ kind: "fileBegin", room: room.id, fileKind: kind, type, bytes: blob.size });
|
|
4770
|
+
uploads.going.set(upload, { room: room.id, name, done: 0 });
|
|
4771
|
+
uploads.tell();
|
|
4772
|
+
try {
|
|
4773
|
+
for (let offset = 0;offset < blob.size; offset += CALL_BYTES) {
|
|
4774
|
+
const bytes = new Uint8Array(await blob.slice(offset, offset + CALL_BYTES).arrayBuffer());
|
|
4775
|
+
await callDoubles({ kind: "fileAppend", upload, offset, data: FilesUtil.base64(bytes) });
|
|
4776
|
+
uploads.going.set(upload, { room: room.id, name, done: Math.min(1, (offset + bytes.length) / blob.size) });
|
|
4777
|
+
uploads.tell();
|
|
4185
4778
|
}
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4779
|
+
return await callDoubles({ kind: "fileFinish", upload, name, ...look, ...known });
|
|
4780
|
+
} finally {
|
|
4781
|
+
uploads.going.delete(upload);
|
|
4782
|
+
uploads.tell();
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
function FileUploads({ room }) {
|
|
4786
|
+
const read = () => [...uploads.going.values()].filter((each) => each.room === room).map((each) => `${each.name} ${Math.floor(each.done * 100)}`).join(`
|
|
4787
|
+
`);
|
|
4788
|
+
const going = React.useSyncExternalStore((listener) => {
|
|
4789
|
+
uploads.listeners.add(listener);
|
|
4790
|
+
return () => uploads.listeners.delete(listener);
|
|
4791
|
+
}, read);
|
|
4792
|
+
if (!going) {
|
|
4793
|
+
return null;
|
|
4189
4794
|
}
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4795
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4796
|
+
className: "trm-uploads",
|
|
4797
|
+
role: "status"
|
|
4798
|
+
}, going.split(`
|
|
4799
|
+
`).map((each) => {
|
|
4800
|
+
const [name, percent] = each.split("\t");
|
|
4801
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4802
|
+
key: name,
|
|
4803
|
+
className: "trm-upload"
|
|
4804
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4805
|
+
className: "ta-spinner"
|
|
4806
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4807
|
+
className: "trm-ellipsis"
|
|
4808
|
+
}, t("fileSending", { name, percent })));
|
|
4809
|
+
}));
|
|
4810
|
+
}
|
|
4811
|
+
function pickFile(accept) {
|
|
4812
|
+
return new Promise((resolve) => {
|
|
4813
|
+
const input = document.createElement("input");
|
|
4814
|
+
input.type = "file";
|
|
4815
|
+
input.accept = accept;
|
|
4816
|
+
input.onchange = () => resolve(input.files?.[0]);
|
|
4817
|
+
input.oncancel = () => resolve(undefined);
|
|
4818
|
+
input.click();
|
|
4819
|
+
});
|
|
4820
|
+
}
|
|
4821
|
+
function VoiceRecorder({ close, onDone }) {
|
|
4822
|
+
const [elapsed, setElapsed] = React.useState(0);
|
|
4823
|
+
const [error, setError] = React.useState("");
|
|
4824
|
+
const recorder = React.useRef(undefined);
|
|
4825
|
+
const keep = React.useRef(false);
|
|
4826
|
+
React.useEffect(() => {
|
|
4827
|
+
let stream;
|
|
4828
|
+
let timer;
|
|
4829
|
+
const started = Date.now();
|
|
4830
|
+
const chunks = [];
|
|
4831
|
+
navigator.mediaDevices?.getUserMedia({ audio: true }).then((got) => {
|
|
4832
|
+
stream = got;
|
|
4833
|
+
const made = new MediaRecorder(got);
|
|
4834
|
+
recorder.current = made;
|
|
4835
|
+
made.ondataavailable = (event) => event.data.size && chunks.push(event.data);
|
|
4836
|
+
made.onstop = () => {
|
|
4837
|
+
for (const track of got.getTracks()) {
|
|
4838
|
+
track.stop();
|
|
4839
|
+
}
|
|
4840
|
+
if (keep.current && chunks.length) {
|
|
4841
|
+
onDone(new Blob(chunks, { type: made.mimeType || "audio/webm" }), Math.min(Date.now() - started, RELAY_CHAT_VOICE_MS));
|
|
4842
|
+
}
|
|
4843
|
+
};
|
|
4844
|
+
made.start();
|
|
4845
|
+
timer = setInterval(() => {
|
|
4846
|
+
const ms = Date.now() - started;
|
|
4847
|
+
setElapsed(ms);
|
|
4848
|
+
if (ms >= RELAY_CHAT_VOICE_MS) {
|
|
4849
|
+
keep.current = true;
|
|
4850
|
+
made.stop();
|
|
4851
|
+
close();
|
|
4852
|
+
}
|
|
4853
|
+
}, 200);
|
|
4854
|
+
}).catch(() => setError(t("voiceNoMic")));
|
|
4855
|
+
if (!navigator.mediaDevices) {
|
|
4856
|
+
setError(t("voiceNoMic"));
|
|
4857
|
+
}
|
|
4858
|
+
return () => {
|
|
4859
|
+
clearInterval(timer);
|
|
4860
|
+
if (recorder.current?.state === "recording") {
|
|
4861
|
+
recorder.current.stop();
|
|
4862
|
+
}
|
|
4863
|
+
for (const track of stream?.getTracks() ?? []) {
|
|
4864
|
+
track.stop();
|
|
4195
4865
|
}
|
|
4196
|
-
await callDoubles({ kind: "forgetTask", task: task.id });
|
|
4197
4866
|
};
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4867
|
+
}, []);
|
|
4868
|
+
const stop = (send) => {
|
|
4869
|
+
keep.current = send;
|
|
4870
|
+
if (recorder.current?.state === "recording") {
|
|
4871
|
+
recorder.current.stop();
|
|
4872
|
+
}
|
|
4873
|
+
close();
|
|
4874
|
+
};
|
|
4875
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4876
|
+
title: t("voiceTitle"),
|
|
4877
|
+
onClose: () => stop(false)
|
|
4878
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4879
|
+
className: "trm-recorder"
|
|
4880
|
+
}, error ? /* @__PURE__ */ React.createElement("p", {
|
|
4881
|
+
className: "trm-note"
|
|
4882
|
+
}, error) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
4883
|
+
className: "trm-recorder-dot"
|
|
4884
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4885
|
+
className: "trm-recorder-time"
|
|
4886
|
+
}, FilesUtil.seconds(elapsed)), /* @__PURE__ */ React.createElement("span", {
|
|
4887
|
+
className: "trm-note"
|
|
4888
|
+
}, t("voiceLong"))), /* @__PURE__ */ React.createElement("div", {
|
|
4889
|
+
className: "trm-answers"
|
|
4890
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4891
|
+
type: "button",
|
|
4892
|
+
className: "ta-button",
|
|
4893
|
+
onClick: () => stop(false)
|
|
4894
|
+
}, t("voiceCancel")), !error && /* @__PURE__ */ React.createElement("button", {
|
|
4895
|
+
type: "button",
|
|
4896
|
+
className: "ta-button ta-primary",
|
|
4897
|
+
onClick: () => stop(true)
|
|
4898
|
+
}, t("voiceSend")))));
|
|
4899
|
+
}
|
|
4900
|
+
function fileActions(room, said) {
|
|
4901
|
+
const sendOne = async (blob, kind, name, known = {}) => {
|
|
4902
|
+
try {
|
|
4903
|
+
await said([await sendFile(room, blob, kind, name, known)]);
|
|
4904
|
+
} catch (error) {
|
|
4905
|
+
pi.ui.notify(message(error), "error");
|
|
4906
|
+
}
|
|
4907
|
+
};
|
|
4908
|
+
const pick = (accept, kind) => () => void pickFile(accept).then((file) => file && sendOne(file, kind, file.name));
|
|
4909
|
+
return [
|
|
4910
|
+
{ key: "send-video", label: t("sendVideo"), icon: icon("Film"), run: pick("video/*", "video") },
|
|
4911
|
+
{ key: "send-file", label: t("sendFile"), icon: icon("FileText"), run: pick("*/*", "file") },
|
|
4912
|
+
{
|
|
4913
|
+
key: "send-voice",
|
|
4914
|
+
label: t("sendVoice"),
|
|
4915
|
+
icon: icon("Mic"),
|
|
4916
|
+
run: () => void show(({ close }) => /* @__PURE__ */ React.createElement(VoiceRecorder, {
|
|
4917
|
+
close,
|
|
4918
|
+
onDone: (blob, ms) => void sendOne(blob, "voice", t("voice"), { ms })
|
|
4919
|
+
}))
|
|
4920
|
+
}
|
|
4921
|
+
];
|
|
4922
|
+
}
|
|
4923
|
+
|
|
4924
|
+
// web-src/pictures-view.tsx
|
|
4925
|
+
var PICTURE_LIMITS = { side: 1600, bytes: 1024 * 1024 };
|
|
4926
|
+
var THUMB_SIDE2 = 16;
|
|
4927
|
+
var KEPT2 = 60;
|
|
4928
|
+
var AGAIN_MS2 = 15000;
|
|
4929
|
+
|
|
4930
|
+
class PictureStore {
|
|
4931
|
+
kept = new Map;
|
|
4932
|
+
loading = new Set;
|
|
4933
|
+
wanted = new Map;
|
|
4934
|
+
listeners = new Set;
|
|
4935
|
+
watching;
|
|
4936
|
+
get(room, id) {
|
|
4937
|
+
return this.kept.get(`${room}:${id}`);
|
|
4938
|
+
}
|
|
4939
|
+
subscribe(listener) {
|
|
4940
|
+
this.listeners.add(listener);
|
|
4941
|
+
this.watch();
|
|
4942
|
+
return () => this.listeners.delete(listener);
|
|
4943
|
+
}
|
|
4944
|
+
want(room, id) {
|
|
4945
|
+
const key = `${room}:${id}`;
|
|
4946
|
+
this.wanted.set(key, (this.wanted.get(key) ?? 0) + 1);
|
|
4947
|
+
this.load(room, id);
|
|
4948
|
+
}
|
|
4949
|
+
unwant(room, id) {
|
|
4950
|
+
const key = `${room}:${id}`;
|
|
4951
|
+
const left2 = (this.wanted.get(key) ?? 1) - 1;
|
|
4952
|
+
if (left2 > 0) {
|
|
4953
|
+
this.wanted.set(key, left2);
|
|
4954
|
+
} else {
|
|
4955
|
+
this.wanted.delete(key);
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
load(room, id) {
|
|
4959
|
+
const key = `${room}:${id}`;
|
|
4960
|
+
if (this.kept.has(key) || this.loading.has(key)) {
|
|
4961
|
+
return;
|
|
4962
|
+
}
|
|
4963
|
+
this.loading.add(key);
|
|
4964
|
+
callDoubles({ kind: "picture", room, id }).then((data) => {
|
|
4965
|
+
if (typeof data === "string" && data.startsWith("data:image/")) {
|
|
4966
|
+
this.keep(key, data);
|
|
4967
|
+
}
|
|
4968
|
+
}).catch(() => {
|
|
4969
|
+
return;
|
|
4970
|
+
}).finally(() => this.loading.delete(key));
|
|
4971
|
+
}
|
|
4972
|
+
again() {
|
|
4973
|
+
for (const key of this.wanted.keys()) {
|
|
4974
|
+
const at = key.indexOf(":");
|
|
4975
|
+
this.load(key.slice(0, at), key.slice(at + 1));
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
keep(key, data) {
|
|
4979
|
+
this.kept.delete(key);
|
|
4980
|
+
this.kept.set(key, data);
|
|
4981
|
+
for (const old of this.kept.keys()) {
|
|
4982
|
+
if (this.kept.size <= KEPT2) {
|
|
4983
|
+
break;
|
|
4984
|
+
}
|
|
4985
|
+
if (!this.wanted.has(old)) {
|
|
4986
|
+
this.kept.delete(old);
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
for (const listener of this.listeners) {
|
|
4990
|
+
listener();
|
|
4991
|
+
}
|
|
4992
|
+
}
|
|
4993
|
+
watch() {
|
|
4994
|
+
if (this.watching || !pi.storage) {
|
|
4995
|
+
return;
|
|
4996
|
+
}
|
|
4997
|
+
this.watching = pi.storage.onChange((keys) => keys.includes(DoubleKeys.PICTURES) && this.again());
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
5000
|
+
var store2 = new PictureStore;
|
|
5001
|
+
function useSources(room, images) {
|
|
5002
|
+
const ids = images.map((image) => image.id).join(",");
|
|
5003
|
+
const read = () => images.map((image) => store2.get(room, image.id) ?? "").join(`
|
|
5004
|
+
`);
|
|
5005
|
+
const joined = React.useSyncExternalStore((listener) => store2.subscribe(listener), read);
|
|
5006
|
+
const sources = joined.split(`
|
|
5007
|
+
`).map((source) => source || undefined);
|
|
5008
|
+
const missing = images.filter((_, at) => !sources[at]).map((image) => image.id).join(",");
|
|
5009
|
+
React.useEffect(() => {
|
|
5010
|
+
if (!missing) {
|
|
5011
|
+
return;
|
|
5012
|
+
}
|
|
5013
|
+
const wanted = missing.split(",");
|
|
5014
|
+
for (const id of wanted) {
|
|
5015
|
+
store2.want(room, id);
|
|
5016
|
+
}
|
|
5017
|
+
const timer = setInterval(() => {
|
|
5018
|
+
for (const id of wanted) {
|
|
5019
|
+
store2.load(room, id);
|
|
5020
|
+
}
|
|
5021
|
+
}, AGAIN_MS2);
|
|
5022
|
+
return () => {
|
|
5023
|
+
clearInterval(timer);
|
|
5024
|
+
for (const id of wanted) {
|
|
5025
|
+
store2.unwant(room, id);
|
|
5026
|
+
}
|
|
5027
|
+
};
|
|
5028
|
+
}, [room, missing]);
|
|
5029
|
+
return ids ? sources : [];
|
|
5030
|
+
}
|
|
5031
|
+
async function thumbOf(image) {
|
|
5032
|
+
const blob = await (await fetch(`data:${image.mimeType};base64,${image.data}`)).blob();
|
|
5033
|
+
const bitmap = await createImageBitmap(blob);
|
|
5034
|
+
try {
|
|
5035
|
+
const scale = THUMB_SIDE2 / Math.max(bitmap.width, bitmap.height);
|
|
5036
|
+
const canvas = document.createElement("canvas");
|
|
5037
|
+
canvas.width = Math.max(1, Math.round(bitmap.width * scale));
|
|
5038
|
+
canvas.height = Math.max(1, Math.round(bitmap.height * scale));
|
|
5039
|
+
const context = canvas.getContext("2d");
|
|
5040
|
+
let thumb;
|
|
5041
|
+
if (context) {
|
|
5042
|
+
context.fillStyle = "#fff";
|
|
5043
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
5044
|
+
context.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
5045
|
+
thumb = canvas.toDataURL("image/jpeg", 0.5);
|
|
5046
|
+
}
|
|
5047
|
+
return { thumb: thumb && thumb.length <= 900 ? thumb : undefined, w: image.width ?? bitmap.width, h: image.height ?? bitmap.height };
|
|
5048
|
+
} finally {
|
|
5049
|
+
bitmap.close();
|
|
5050
|
+
}
|
|
5051
|
+
}
|
|
5052
|
+
async function sendPictures(room, images) {
|
|
5053
|
+
return Promise.all(images.map(async (image) => {
|
|
5054
|
+
const [put, look] = await Promise.all([
|
|
5055
|
+
callDoubles({ kind: "putPicture", room: room.id, data: image.data, type: image.mimeType }),
|
|
5056
|
+
thumbOf(image)
|
|
5057
|
+
]);
|
|
5058
|
+
return { ...put, w: look.w, h: look.h, ...look.thumb ? { thumb: look.thumb } : {} };
|
|
5059
|
+
}));
|
|
5060
|
+
}
|
|
5061
|
+
function LinePictures({ room, line, name }) {
|
|
5062
|
+
const images = line.images ?? [];
|
|
5063
|
+
const sources = useSources(room, images);
|
|
5064
|
+
const ChatImages = pi.ui.ChatImages;
|
|
5065
|
+
if (!images.length) {
|
|
5066
|
+
return null;
|
|
5067
|
+
}
|
|
5068
|
+
if (!ChatImages) {
|
|
5069
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
5070
|
+
className: "trm-quiet"
|
|
5071
|
+
}, t("picture"));
|
|
5072
|
+
}
|
|
5073
|
+
const waiting = sources.some((source) => !source);
|
|
5074
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5075
|
+
className: "trm-pics",
|
|
5076
|
+
title: waiting ? t("pictureWait", { name }) : undefined
|
|
5077
|
+
}, /* @__PURE__ */ React.createElement(ChatImages, {
|
|
5078
|
+
alt: t("pictureAlt", { name }),
|
|
5079
|
+
images: images.map((image, at) => ({ key: image.id, src: sources[at], thumb: image.thumb, width: image.w, height: image.h }))
|
|
5080
|
+
}));
|
|
5081
|
+
}
|
|
5082
|
+
|
|
5083
|
+
// web-src/room-rules.ts
|
|
5084
|
+
var ROOM_RULES = ["agents", "doubles", "tasks"];
|
|
5085
|
+
var RoomRulesUtil;
|
|
5086
|
+
((RoomRulesUtil) => {
|
|
5087
|
+
function allows(room, rule) {
|
|
5088
|
+
return room?.rules?.[rule] !== false;
|
|
5089
|
+
}
|
|
5090
|
+
RoomRulesUtil.allows = allows;
|
|
5091
|
+
function approves(room) {
|
|
5092
|
+
return room?.rules?.approve === true;
|
|
5093
|
+
}
|
|
5094
|
+
RoomRulesUtil.approves = approves;
|
|
5095
|
+
function refused(rule, language) {
|
|
5096
|
+
return TaLanguageUtil.pick(language, {
|
|
5097
|
+
agents: {
|
|
5098
|
+
"zh-CN": "群主没有允许在这个群里用智能体",
|
|
5099
|
+
"zh-TW": "群主沒有允許在這個群裡用智慧體",
|
|
5100
|
+
"en-US": "the owner allows no agents in this group chat",
|
|
5101
|
+
"ja-JP": "このグループチャットではグループ主がエージェントを許可していません"
|
|
5102
|
+
},
|
|
5103
|
+
doubles: {
|
|
5104
|
+
"zh-CN": "群主没有允许分身在这个群里代答",
|
|
5105
|
+
"zh-TW": "群主沒有允許分身在這個群裡代答",
|
|
5106
|
+
"en-US": "the owner allows no double to answer in this group chat",
|
|
5107
|
+
"ja-JP": "このグループチャットではグループ主が分身の代理応答を許可していません"
|
|
5108
|
+
},
|
|
5109
|
+
tasks: {
|
|
5110
|
+
"zh-CN": "群主没有允许在这个群里给分身派任务",
|
|
5111
|
+
"zh-TW": "群主沒有允許在這個群裡給分身派任務",
|
|
5112
|
+
"en-US": "the owner allows no tasks for doubles in this group chat",
|
|
5113
|
+
"ja-JP": "このグループチャットではグループ主が分身へのタスクを許可していません"
|
|
5114
|
+
}
|
|
5115
|
+
}[rule]);
|
|
5116
|
+
}
|
|
5117
|
+
RoomRulesUtil.refused = refused;
|
|
5118
|
+
})(RoomRulesUtil ||= {});
|
|
5119
|
+
|
|
5120
|
+
// web-src/tasks-view.tsx
|
|
5121
|
+
function taskStatusWord(status) {
|
|
5122
|
+
switch (status) {
|
|
5123
|
+
case "sent":
|
|
5124
|
+
return dt("taskSent");
|
|
5125
|
+
case "queued":
|
|
5126
|
+
return dt("taskQueued");
|
|
5127
|
+
case "running":
|
|
5128
|
+
return dt("taskRunning");
|
|
5129
|
+
case "permission":
|
|
5130
|
+
return dt("taskPermission");
|
|
5131
|
+
case "done":
|
|
5132
|
+
return dt("taskDone");
|
|
5133
|
+
case "failed":
|
|
5134
|
+
return dt("taskFailed");
|
|
5135
|
+
case "stopped":
|
|
5136
|
+
return dt("taskStopped");
|
|
5137
|
+
default:
|
|
5138
|
+
return dt("taskDeclined");
|
|
5139
|
+
}
|
|
5140
|
+
}
|
|
5141
|
+
function oneLine(text) {
|
|
5142
|
+
const lines = text.split(`
|
|
5143
|
+
`).map((line) => line.trim());
|
|
5144
|
+
const first = lines.find((line) => line && !line.startsWith("|") && !line.startsWith("```")) ?? lines.find(Boolean) ?? "";
|
|
5145
|
+
return first.replace(/^#+\s*|^[-*]\s+|\*\*|__|`/g, "").trim();
|
|
5146
|
+
}
|
|
5147
|
+
function listed(status, mine) {
|
|
5148
|
+
if (!RoomTasksUtil.ended(status)) {
|
|
5149
|
+
return mine && status === "permission" ? "waiting" : "running";
|
|
5150
|
+
}
|
|
5151
|
+
return status === "done" ? "done" : status === "stopped" ? "stopped" : "failed";
|
|
5152
|
+
}
|
|
5153
|
+
function act(run) {
|
|
5154
|
+
return () => void run().catch((error) => pi.ui.notify(message(error), "error"));
|
|
5155
|
+
}
|
|
5156
|
+
|
|
5157
|
+
class RoomTaskSource {
|
|
5158
|
+
list = [];
|
|
5159
|
+
shown = new Map;
|
|
5160
|
+
listeners = new Set;
|
|
5161
|
+
stop;
|
|
5162
|
+
tasks() {
|
|
5163
|
+
return this.list;
|
|
5164
|
+
}
|
|
5165
|
+
subscribe(listener) {
|
|
5166
|
+
if (this.listeners.size === 0) {
|
|
5167
|
+
const unsubscribe = doubles.subscribe(() => this.build(doubles.get()));
|
|
5168
|
+
const stopStore = doubles.start();
|
|
5169
|
+
this.stop = () => {
|
|
5170
|
+
unsubscribe();
|
|
5171
|
+
stopStore();
|
|
5172
|
+
};
|
|
5173
|
+
this.build(doubles.get());
|
|
5174
|
+
}
|
|
5175
|
+
this.listeners.add(listener);
|
|
5176
|
+
return () => {
|
|
5177
|
+
this.listeners.delete(listener);
|
|
5178
|
+
if (this.listeners.size === 0) {
|
|
5179
|
+
this.stop?.();
|
|
5180
|
+
this.stop = undefined;
|
|
5181
|
+
}
|
|
5182
|
+
};
|
|
5183
|
+
}
|
|
5184
|
+
build(state) {
|
|
5185
|
+
const next = [
|
|
5186
|
+
...state.tasks.map((task) => this.reuse(`for:${task.id}`, task, () => this.forTask(task, state))),
|
|
5187
|
+
...state.handed.map((task) => this.reuse(`to:${task.id}`, task, () => this.toTask(task)))
|
|
5188
|
+
];
|
|
5189
|
+
if (next.length === this.list.length && next.every((entry, index) => entry === this.list[index])) {
|
|
5190
|
+
return;
|
|
5191
|
+
}
|
|
5192
|
+
const ids = new Set(next.map((entry) => entry.id));
|
|
5193
|
+
for (const id of [...this.shown.keys()]) {
|
|
5194
|
+
if (!ids.has(id)) {
|
|
5195
|
+
this.shown.delete(id);
|
|
5196
|
+
}
|
|
5197
|
+
}
|
|
5198
|
+
this.list = next;
|
|
5199
|
+
for (const listener of this.listeners) {
|
|
5200
|
+
listener();
|
|
5201
|
+
}
|
|
5202
|
+
}
|
|
5203
|
+
reuse(id, task, make) {
|
|
5204
|
+
const signature = `${pi.ui.language}:${JSON.stringify(task)}`;
|
|
5205
|
+
const before = this.shown.get(id);
|
|
5206
|
+
if (before?.signature === signature) {
|
|
5207
|
+
return before.entry;
|
|
5208
|
+
}
|
|
5209
|
+
const entry = make();
|
|
5210
|
+
this.shown.set(id, { signature, entry });
|
|
5211
|
+
return entry;
|
|
5212
|
+
}
|
|
5213
|
+
forTask(task, state) {
|
|
5214
|
+
const open = !RoomTasksUtil.ended(task.status);
|
|
5215
|
+
const remove = async () => {
|
|
5216
|
+
if (open) {
|
|
5217
|
+
await callDoubles({ kind: "stopTask", task: task.id });
|
|
5218
|
+
}
|
|
5219
|
+
await callDoubles({ kind: "forgetTask", task: task.id });
|
|
5220
|
+
};
|
|
5221
|
+
return {
|
|
5222
|
+
id: `for:${task.id}`,
|
|
5223
|
+
title: dt("taskFor", { name: task.name, text: task.text }),
|
|
5224
|
+
status: listed(task.status, true),
|
|
5225
|
+
detail: task.approval ? rt("approveWaiting") : task.status === "permission" ? dt("taskNeedsYou") : open ? taskStatusWord(task.status) : oneLine(task.answer ?? task.detail ?? taskStatusWord(task.status)),
|
|
5226
|
+
startedAt: task.at,
|
|
5227
|
+
...task.endedAt && !open ? { endedAt: task.endedAt } : {},
|
|
5228
|
+
icon: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
4206
5229
|
id: task.friend,
|
|
4207
5230
|
name: task.name,
|
|
4208
5231
|
size
|
|
@@ -4436,6 +5459,7 @@ function RoomView({ room, head, onBack }) {
|
|
|
4436
5459
|
const tasks = useTaskStates(room);
|
|
4437
5460
|
const list = React.useRef(null);
|
|
4438
5461
|
const stuck = React.useRef(true);
|
|
5462
|
+
const older = React.useRef(undefined);
|
|
4439
5463
|
const self = room.members.find((member) => member.self);
|
|
4440
5464
|
const personOf = (line) => room.members.find((member) => member.member === line.from)?.name ?? line.name;
|
|
4441
5465
|
const nameOf = (line) => line.agent ? line.agent.name : !line.double ? personOf(line) : line.from === self?.member ? dt("myDouble") : dt("doubleOf", { name: personOf(line) });
|
|
@@ -4466,13 +5490,30 @@ function RoomView({ room, head, onBack }) {
|
|
|
4466
5490
|
book.see(room.id, last.at);
|
|
4467
5491
|
}
|
|
4468
5492
|
}, [lines, room.id]);
|
|
4469
|
-
const
|
|
5493
|
+
const { apps } = useRoomApps(room);
|
|
5494
|
+
const actions = [
|
|
5495
|
+
fileActions(room, async (files) => {
|
|
5496
|
+
if (self && chat) {
|
|
5497
|
+
stuck.current = true;
|
|
5498
|
+
await chat.say("", self, { files });
|
|
5499
|
+
}
|
|
5500
|
+
}),
|
|
5501
|
+
[
|
|
5502
|
+
...RoomRulesUtil.allows(room, "agents") ? [{ key: "invite-agent", label: dt("inviteAgent"), icon: icon("Bot"), run: () => openAgentPicker(room) }] : [],
|
|
5503
|
+
...apps.map((app) => ({ key: `app:${app.id}`, label: app.label, detail: app.status, icon: app.icon, run: () => openApp(room, app) }))
|
|
5504
|
+
]
|
|
5505
|
+
];
|
|
5506
|
+
const say = async (text, images = []) => {
|
|
4470
5507
|
if (!self || !chat) {
|
|
4471
5508
|
throw new Error(t("connecting"));
|
|
4472
5509
|
}
|
|
4473
5510
|
stuck.current = true;
|
|
4474
5511
|
const { to, person } = addressed(text, room, agents);
|
|
4475
|
-
|
|
5512
|
+
const pictures = images.length ? await sendPictures(room, images) : [];
|
|
5513
|
+
await chat.say(text, self, {
|
|
5514
|
+
...to.length ? { to, ...person ? { person: true } : {} } : {},
|
|
5515
|
+
...pictures.length ? { images: pictures } : {}
|
|
5516
|
+
});
|
|
4476
5517
|
};
|
|
4477
5518
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4478
5519
|
className: "trm-room-page"
|
|
@@ -4496,6 +5537,15 @@ function RoomView({ room, head, onBack }) {
|
|
|
4496
5537
|
onScroll: (event) => {
|
|
4497
5538
|
const element = event.currentTarget;
|
|
4498
5539
|
stuck.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
|
|
5540
|
+
if (element.scrollTop < 120 && chat?.more && !older.current) {
|
|
5541
|
+
older.current = chat.older().then(() => {
|
|
5542
|
+
return;
|
|
5543
|
+
}, () => {
|
|
5544
|
+
return;
|
|
5545
|
+
}).finally(() => {
|
|
5546
|
+
older.current = undefined;
|
|
5547
|
+
});
|
|
5548
|
+
}
|
|
4499
5549
|
}
|
|
4500
5550
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
4501
5551
|
className: "trm-chat-col"
|
|
@@ -4527,13 +5577,23 @@ function RoomView({ room, head, onBack }) {
|
|
|
4527
5577
|
}, separator && /* @__PURE__ */ React.createElement("div", {
|
|
4528
5578
|
className: "trm-chat-time"
|
|
4529
5579
|
}, time(line.at)), line.from === self?.member && !line.double && !line.agent ? /* @__PURE__ */ React.createElement("div", {
|
|
4530
|
-
className:
|
|
5580
|
+
className: `ta-message ta-user trm-mine${line.pending ? " trm-pending" : ""}`,
|
|
4531
5581
|
title: time(line.at)
|
|
4532
|
-
}, /* @__PURE__ */ React.createElement(
|
|
5582
|
+
}, /* @__PURE__ */ React.createElement(LinePictures, {
|
|
5583
|
+
room: room.id,
|
|
5584
|
+
line,
|
|
5585
|
+
name: nameOf(line)
|
|
5586
|
+
}), /* @__PURE__ */ React.createElement(LineFiles, {
|
|
5587
|
+
room: room.id,
|
|
5588
|
+
line,
|
|
5589
|
+
name: nameOf(line)
|
|
5590
|
+
}), line.text && /* @__PURE__ */ React.createElement("div", {
|
|
4533
5591
|
className: "ta-bubble"
|
|
4534
5592
|
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
4535
5593
|
text: line.text
|
|
4536
|
-
}))
|
|
5594
|
+
})), line.failed && /* @__PURE__ */ React.createElement("div", {
|
|
5595
|
+
className: "trm-unsent"
|
|
5596
|
+
}, t("unsent"))) : /* @__PURE__ */ React.createElement("div", {
|
|
4537
5597
|
className: `trm-msg${first ? " trm-first" : ""}${line.double ? " trm-double" : ""}${line.agent ? " trm-agent" : ""}`
|
|
4538
5598
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
4539
5599
|
className: "trm-msg-face"
|
|
@@ -4550,7 +5610,15 @@ function RoomView({ room, head, onBack }) {
|
|
|
4550
5610
|
className: `trm-tag ${line.agent ? "trm-tag-agent" : "trm-tag-double"}`
|
|
4551
5611
|
}, tagOf(line)), line.task && /* @__PURE__ */ React.createElement("span", {
|
|
4552
5612
|
className: "trm-tag trm-tag-task"
|
|
4553
|
-
}, dt("taskTag"))), /* @__PURE__ */ React.createElement(
|
|
5613
|
+
}, dt("taskTag"))), /* @__PURE__ */ React.createElement(LinePictures, {
|
|
5614
|
+
room: room.id,
|
|
5615
|
+
line,
|
|
5616
|
+
name: nameOf(line)
|
|
5617
|
+
}), /* @__PURE__ */ React.createElement(LineFiles, {
|
|
5618
|
+
room: room.id,
|
|
5619
|
+
line,
|
|
5620
|
+
name: nameOf(line)
|
|
5621
|
+
}), line.text && /* @__PURE__ */ React.createElement("div", {
|
|
4554
5622
|
className: "trm-msg-bubble",
|
|
4555
5623
|
title: time(line.at)
|
|
4556
5624
|
}, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
@@ -4568,10 +5636,14 @@ function RoomView({ room, head, onBack }) {
|
|
|
4568
5636
|
className: "trm-chat-bottom"
|
|
4569
5637
|
}, /* @__PURE__ */ React.createElement(Drafts, {
|
|
4570
5638
|
room
|
|
5639
|
+
}), /* @__PURE__ */ React.createElement(FileUploads, {
|
|
5640
|
+
room: room.id
|
|
4571
5641
|
}), /* @__PURE__ */ React.createElement(pi.ui.Composer, {
|
|
4572
5642
|
placeholder: t("chatPlaceholder"),
|
|
4573
5643
|
draft: room.id,
|
|
4574
5644
|
onSend: say,
|
|
5645
|
+
images: PICTURE_LIMITS,
|
|
5646
|
+
actions,
|
|
4575
5647
|
mentions,
|
|
4576
5648
|
mentionLabel: rt("mentionPerson")
|
|
4577
5649
|
})));
|
|
@@ -4705,13 +5777,16 @@ function PersonDialog({ person, room, close }) {
|
|
|
4705
5777
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
4706
5778
|
type: "button",
|
|
4707
5779
|
className: "ta-button ta-danger",
|
|
4708
|
-
onClick: () => void
|
|
4709
|
-
await rooms()?.removeFriend(friend.id);
|
|
4710
|
-
close();
|
|
4711
|
-
await book.load();
|
|
4712
|
-
})
|
|
5780
|
+
onClick: () => void removeFriend(friend, close)
|
|
4713
5781
|
}, rt("removeFriendLong")))));
|
|
4714
5782
|
}
|
|
5783
|
+
function removeFriend(friend, then) {
|
|
5784
|
+
return confirmThen(t("removeFriendTitle", { name: friend.name }), t("removeFriendHint"), t("removeFriend"), async () => {
|
|
5785
|
+
await rooms()?.removeFriend(friend.id);
|
|
5786
|
+
then?.();
|
|
5787
|
+
await book.load();
|
|
5788
|
+
});
|
|
5789
|
+
}
|
|
4715
5790
|
function openPerson(person, room) {
|
|
4716
5791
|
show(({ close }) => /* @__PURE__ */ React.createElement(PersonDialog, {
|
|
4717
5792
|
person,
|
|
@@ -5008,6 +6083,41 @@ async function offerFriend(room, member, name) {
|
|
|
5008
6083
|
}
|
|
5009
6084
|
}
|
|
5010
6085
|
|
|
6086
|
+
// web-src/group-joining.ts
|
|
6087
|
+
var MEMBER_CHOICES = [16, 50, 100];
|
|
6088
|
+
var LINK_DAYS = [7, 30, 365];
|
|
6089
|
+
var DEFAULT_DAYS = 7;
|
|
6090
|
+
var LINK_DAYS_KEY = "linkDays";
|
|
6091
|
+
function parse(value) {
|
|
6092
|
+
return value && typeof value === "object" ? Object.fromEntries(Object.entries(value).filter((entry) => LINK_DAYS.includes(entry[1]))) : {};
|
|
6093
|
+
}
|
|
6094
|
+
async function linkDays(room) {
|
|
6095
|
+
return parse(await pi.storage?.get(LINK_DAYS_KEY).catch(() => {
|
|
6096
|
+
return;
|
|
6097
|
+
}))[room] ?? DEFAULT_DAYS;
|
|
6098
|
+
}
|
|
6099
|
+
async function setLinkDays(room, days) {
|
|
6100
|
+
const all = parse(await pi.storage?.get(LINK_DAYS_KEY).catch(() => {
|
|
6101
|
+
return;
|
|
6102
|
+
}));
|
|
6103
|
+
await pi.storage?.set(LINK_DAYS_KEY, { ...all, [room]: days });
|
|
6104
|
+
await rooms()?.invite(room, { days, renew: true });
|
|
6105
|
+
}
|
|
6106
|
+
function useLinkDays(room) {
|
|
6107
|
+
const [days, setDays] = React.useState(DEFAULT_DAYS);
|
|
6108
|
+
React.useEffect(() => {
|
|
6109
|
+
let live = true;
|
|
6110
|
+
const read = () => void linkDays(room).then((found) => live && setDays(found));
|
|
6111
|
+
read();
|
|
6112
|
+
const stop = pi.storage?.onChange((keys) => keys.includes(LINK_DAYS_KEY) && read());
|
|
6113
|
+
return () => {
|
|
6114
|
+
live = false;
|
|
6115
|
+
stop?.();
|
|
6116
|
+
};
|
|
6117
|
+
}, [room]);
|
|
6118
|
+
return days;
|
|
6119
|
+
}
|
|
6120
|
+
|
|
5011
6121
|
// web-src/dialogs.tsx
|
|
5012
6122
|
function show(component) {
|
|
5013
6123
|
if (!pi.ui.custom) {
|
|
@@ -5161,7 +6271,7 @@ function InviteDialog({ room, close }) {
|
|
|
5161
6271
|
const [error, setError] = React.useState();
|
|
5162
6272
|
const make = React.useCallback((renew) => {
|
|
5163
6273
|
setError(undefined);
|
|
5164
|
-
rooms()?.invite(room.id, renew ? { renew } :
|
|
6274
|
+
linkDays(room.id).then((days) => rooms()?.invite(room.id, { days, ...renew ? { renew } : {} })).then((made) => made && setLink(made.link)).catch((failure) => setError(message(failure)));
|
|
5165
6275
|
}, [room.id]);
|
|
5166
6276
|
React.useEffect(() => make(false), [make]);
|
|
5167
6277
|
return /* @__PURE__ */ React.createElement(ShareSheetCompat, {
|
|
@@ -5431,31 +6541,144 @@ function FriendPicker({ room, close }) {
|
|
|
5431
6541
|
setBusy(undefined);
|
|
5432
6542
|
}, (failure) => {
|
|
5433
6543
|
setError(message(failure));
|
|
5434
|
-
setBusy(undefined);
|
|
6544
|
+
setBusy(undefined);
|
|
6545
|
+
});
|
|
6546
|
+
};
|
|
6547
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
6548
|
+
title: t("inviteFriendsTitle", { title: room.title }),
|
|
6549
|
+
onClose: close
|
|
6550
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
6551
|
+
className: "trm-dialog"
|
|
6552
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
6553
|
+
className: "trm-note"
|
|
6554
|
+
}, t("inviteFriendsLead")), list.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
6555
|
+
title: t("inviteFriendsNone"),
|
|
6556
|
+
compact: true
|
|
6557
|
+
}), list.length > 0 && /* @__PURE__ */ React.createElement("ul", {
|
|
6558
|
+
className: "trm-rows trm-agent-pick"
|
|
6559
|
+
}, list.map((friend) => {
|
|
6560
|
+
const done = invited.includes(friend.id);
|
|
6561
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
6562
|
+
key: friend.id
|
|
6563
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
6564
|
+
type: "button",
|
|
6565
|
+
className: "trm-member",
|
|
6566
|
+
disabled: done || !!busy,
|
|
6567
|
+
onClick: () => invite(friend)
|
|
6568
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
6569
|
+
id: friend.id,
|
|
6570
|
+
name: friend.name,
|
|
6571
|
+
size: 34
|
|
6572
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
6573
|
+
className: "trm-member-text"
|
|
6574
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6575
|
+
className: "trm-member-name trm-ellipsis"
|
|
6576
|
+
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
6577
|
+
className: "trm-member-detail trm-ellipsis"
|
|
6578
|
+
}, done ? t("invitedFriend") : t("friendTag"))), busy === friend.id ? /* @__PURE__ */ React.createElement("span", {
|
|
6579
|
+
className: "ta-spinner"
|
|
6580
|
+
}) : done ? /* @__PURE__ */ React.createElement(Check, {
|
|
6581
|
+
size: 16
|
|
6582
|
+
}) : /* @__PURE__ */ React.createElement(Plus, {
|
|
6583
|
+
size: 16
|
|
6584
|
+
})));
|
|
6585
|
+
})), error && /* @__PURE__ */ React.createElement("p", {
|
|
6586
|
+
className: "trm-error"
|
|
6587
|
+
}, error)));
|
|
6588
|
+
}
|
|
6589
|
+
function openFriendPicker(room) {
|
|
6590
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(FriendPicker, {
|
|
6591
|
+
room,
|
|
6592
|
+
close
|
|
6593
|
+
}));
|
|
6594
|
+
}
|
|
6595
|
+
function groupTitle(names2) {
|
|
6596
|
+
const shown = names2.filter(Boolean);
|
|
6597
|
+
const title = shown.slice(0, 4).join(t("groupNameSep"));
|
|
6598
|
+
return (shown.length > 4 ? t("groupNameMore", { names: title }) : title).slice(0, 60);
|
|
6599
|
+
}
|
|
6600
|
+
async function makeGroup(friends, me) {
|
|
6601
|
+
const server = rooms();
|
|
6602
|
+
if (!server?.inviteFriends) {
|
|
6603
|
+
throw new Error(t("inviteFriendsOld"));
|
|
6604
|
+
}
|
|
6605
|
+
const room = await server.createRoom({ kind: ROOMS_KIND, title: groupTitle([me ?? "", ...friends.map((friend) => friend.name)]) });
|
|
6606
|
+
await server.inviteFriends(room.id, friends.map((friend) => friend.id));
|
|
6607
|
+
await book.load();
|
|
6608
|
+
openRoom(room.id);
|
|
6609
|
+
}
|
|
6610
|
+
function GroupPicker({ fixed, close }) {
|
|
6611
|
+
const { friends, identity } = useBook();
|
|
6612
|
+
const list = (friends ?? []).filter((friend) => friend.status === "friend");
|
|
6613
|
+
const [chosen, setChosen] = React.useState(fixed ? [fixed.id] : []);
|
|
6614
|
+
const [busy, setBusy] = React.useState(false);
|
|
6615
|
+
const [error, setError] = React.useState();
|
|
6616
|
+
const Check = icon("Check");
|
|
6617
|
+
const Link = icon("Link");
|
|
6618
|
+
const picked = list.filter((friend) => chosen.includes(friend.id));
|
|
6619
|
+
const direct = !fixed && picked.length === 1;
|
|
6620
|
+
const enough = picked.length >= (fixed ? 2 : 1);
|
|
6621
|
+
const toggle = (id) => {
|
|
6622
|
+
if (id !== fixed?.id) {
|
|
6623
|
+
setChosen((before) => before.includes(id) ? before.filter((each) => each !== id) : [...before, id]);
|
|
6624
|
+
}
|
|
6625
|
+
};
|
|
6626
|
+
const done = () => {
|
|
6627
|
+
if (direct) {
|
|
6628
|
+
close();
|
|
6629
|
+
openDirect(picked[0]);
|
|
6630
|
+
return;
|
|
6631
|
+
}
|
|
6632
|
+
setBusy(true);
|
|
6633
|
+
setError(undefined);
|
|
6634
|
+
makeGroup(picked, identity?.name).then(close, (failure) => {
|
|
6635
|
+
setError(message(failure));
|
|
6636
|
+
setBusy(false);
|
|
5435
6637
|
});
|
|
5436
6638
|
};
|
|
5437
6639
|
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
5438
|
-
title: t("
|
|
6640
|
+
title: t("newRoom"),
|
|
5439
6641
|
onClose: close
|
|
5440
6642
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
5441
6643
|
className: "trm-dialog"
|
|
5442
6644
|
}, /* @__PURE__ */ React.createElement("p", {
|
|
5443
6645
|
className: "trm-note"
|
|
5444
|
-
}, t("
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
className: "trm-
|
|
5449
|
-
|
|
5450
|
-
|
|
6646
|
+
}, fixed ? t("groupPickLeadFrom", { name: fixed.name }) : t("groupPickLead")), /* @__PURE__ */ React.createElement("ul", {
|
|
6647
|
+
className: "trm-rows trm-group-pick"
|
|
6648
|
+
}, !fixed && /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
6649
|
+
type: "button",
|
|
6650
|
+
className: "trm-member",
|
|
6651
|
+
disabled: busy,
|
|
6652
|
+
onClick: () => {
|
|
6653
|
+
close();
|
|
6654
|
+
createRoom();
|
|
6655
|
+
}
|
|
6656
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6657
|
+
className: "trm-member-plus"
|
|
6658
|
+
}, /* @__PURE__ */ React.createElement(Link, {
|
|
6659
|
+
size: 16
|
|
6660
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
6661
|
+
className: "trm-member-text"
|
|
6662
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6663
|
+
className: "trm-member-name"
|
|
6664
|
+
}, t("groupByLink")), /* @__PURE__ */ React.createElement("span", {
|
|
6665
|
+
className: "trm-member-detail"
|
|
6666
|
+
}, t("groupByLinkLine"))))), list.map((friend) => {
|
|
6667
|
+
const on = chosen.includes(friend.id);
|
|
5451
6668
|
return /* @__PURE__ */ React.createElement("li", {
|
|
5452
6669
|
key: friend.id
|
|
5453
6670
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
5454
6671
|
type: "button",
|
|
5455
6672
|
className: "trm-member",
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
6673
|
+
"aria-pressed": on,
|
|
6674
|
+
disabled: busy || friend.id === fixed?.id,
|
|
6675
|
+
onClick: () => toggle(friend.id)
|
|
6676
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6677
|
+
className: `trm-pick-box${on ? " trm-pick-on" : ""}`,
|
|
6678
|
+
"aria-hidden": "true"
|
|
6679
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
6680
|
+
size: 12
|
|
6681
|
+
})), /* @__PURE__ */ React.createElement(Face, {
|
|
5459
6682
|
id: friend.id,
|
|
5460
6683
|
name: friend.name,
|
|
5461
6684
|
size: 34
|
|
@@ -5463,22 +6686,26 @@ function FriendPicker({ room, close }) {
|
|
|
5463
6686
|
className: "trm-member-text"
|
|
5464
6687
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5465
6688
|
className: "trm-member-name trm-ellipsis"
|
|
5466
|
-
}, friend.name)
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
size: 16
|
|
5472
|
-
}) : /* @__PURE__ */ React.createElement(Plus, {
|
|
5473
|
-
size: 16
|
|
5474
|
-
})));
|
|
5475
|
-
})), error && /* @__PURE__ */ React.createElement("p", {
|
|
6689
|
+
}, friend.name))));
|
|
6690
|
+
})), list.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
6691
|
+
title: t("groupPickNone"),
|
|
6692
|
+
compact: true
|
|
6693
|
+
}), error && /* @__PURE__ */ React.createElement("p", {
|
|
5476
6694
|
className: "trm-error"
|
|
5477
|
-
}, error)
|
|
6695
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
6696
|
+
className: "trm-actions"
|
|
6697
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
6698
|
+
type: "button",
|
|
6699
|
+
className: "ta-button ta-primary",
|
|
6700
|
+
disabled: busy || !enough,
|
|
6701
|
+
onClick: done
|
|
6702
|
+
}, busy ? /* @__PURE__ */ React.createElement("span", {
|
|
6703
|
+
className: "ta-spinner"
|
|
6704
|
+
}) : direct ? t("groupPickChat") : t("groupPickDone", { n: picked.length + 1 })))));
|
|
5478
6705
|
}
|
|
5479
|
-
function
|
|
5480
|
-
show(({ close }) => /* @__PURE__ */ React.createElement(
|
|
5481
|
-
|
|
6706
|
+
function openGroupPicker(fixed) {
|
|
6707
|
+
show(({ close }) => /* @__PURE__ */ React.createElement(GroupPicker, {
|
|
6708
|
+
fixed,
|
|
5482
6709
|
close
|
|
5483
6710
|
}));
|
|
5484
6711
|
}
|
|
@@ -5563,43 +6790,6 @@ function openGroupInvite(invite) {
|
|
|
5563
6790
|
}));
|
|
5564
6791
|
}
|
|
5565
6792
|
|
|
5566
|
-
// web-src/room-rules.ts
|
|
5567
|
-
var ROOM_RULES = ["agents", "doubles", "tasks"];
|
|
5568
|
-
var RoomRulesUtil;
|
|
5569
|
-
((RoomRulesUtil) => {
|
|
5570
|
-
function allows(room, rule) {
|
|
5571
|
-
return room?.rules?.[rule] !== false;
|
|
5572
|
-
}
|
|
5573
|
-
RoomRulesUtil.allows = allows;
|
|
5574
|
-
function approves(room) {
|
|
5575
|
-
return room?.rules?.approve === true;
|
|
5576
|
-
}
|
|
5577
|
-
RoomRulesUtil.approves = approves;
|
|
5578
|
-
function refused(rule, language) {
|
|
5579
|
-
return TaLanguageUtil.pick(language, {
|
|
5580
|
-
agents: {
|
|
5581
|
-
"zh-CN": "群主没有允许在这个群里用智能体",
|
|
5582
|
-
"zh-TW": "群主沒有允許在這個群裡用智慧體",
|
|
5583
|
-
"en-US": "the owner allows no agents in this group chat",
|
|
5584
|
-
"ja-JP": "このグループチャットではグループ主がエージェントを許可していません"
|
|
5585
|
-
},
|
|
5586
|
-
doubles: {
|
|
5587
|
-
"zh-CN": "群主没有允许分身在这个群里代答",
|
|
5588
|
-
"zh-TW": "群主沒有允許分身在這個群裡代答",
|
|
5589
|
-
"en-US": "the owner allows no double to answer in this group chat",
|
|
5590
|
-
"ja-JP": "このグループチャットではグループ主が分身の代理応答を許可していません"
|
|
5591
|
-
},
|
|
5592
|
-
tasks: {
|
|
5593
|
-
"zh-CN": "群主没有允许在这个群里给分身派任务",
|
|
5594
|
-
"zh-TW": "群主沒有允許在這個群裡給分身派任務",
|
|
5595
|
-
"en-US": "the owner allows no tasks for doubles in this group chat",
|
|
5596
|
-
"ja-JP": "このグループチャットではグループ主が分身へのタスクを許可していません"
|
|
5597
|
-
}
|
|
5598
|
-
}[rule]);
|
|
5599
|
-
}
|
|
5600
|
-
RoomRulesUtil.refused = refused;
|
|
5601
|
-
})(RoomRulesUtil ||= {});
|
|
5602
|
-
|
|
5603
6793
|
// web-src/rules-i18n.ts
|
|
5604
6794
|
var EN4 = {
|
|
5605
6795
|
rulesManage: "Manage the group chat",
|
|
@@ -5617,6 +6807,19 @@ var EN4 = {
|
|
|
5617
6807
|
rulesOthers: "Set by the owner; everyone’s Ta keeps them.",
|
|
5618
6808
|
approve: "Invited friends ask too",
|
|
5619
6809
|
approveHint: "Friends you or an admin invite are let in only once one of you agrees",
|
|
6810
|
+
guests: "Those from a browser come in",
|
|
6811
|
+
guestsHint: "Who opens the link in a browser joins without asking, and only chats; past {n} an hour you are asked",
|
|
6812
|
+
joining: "Joining",
|
|
6813
|
+
capacity: "Members at most",
|
|
6814
|
+
capacityValue: "Up to {n}",
|
|
6815
|
+
history: "Chat history for new members",
|
|
6816
|
+
historyNone: "None",
|
|
6817
|
+
historyValue: "Last {n} messages",
|
|
6818
|
+
linkDays: "The link that invites works",
|
|
6819
|
+
linkDaysValue7: "7 days",
|
|
6820
|
+
linkDaysValue30: "30 days",
|
|
6821
|
+
linkDaysValue365: "A year",
|
|
6822
|
+
linkDaysHint: "A new link is made: the one of before stops working.",
|
|
5620
6823
|
agents: "Agents may be invited",
|
|
5621
6824
|
agentsHint: "Members may bring their agents in to help",
|
|
5622
6825
|
doubles: "Doubles may answer for people",
|
|
@@ -5640,6 +6843,19 @@ var ZH4 = {
|
|
|
5640
6843
|
rulesOthers: "由群主设置,每个人的 Ta 都按这个执行。",
|
|
5641
6844
|
approve: "受邀的好友也要同意",
|
|
5642
6845
|
approveHint: "你或管理员邀请的好友,也要你们同意后才能进群",
|
|
6846
|
+
guests: "网页访客直接进",
|
|
6847
|
+
guestsHint: "用浏览器打开链接的人不用同意就能进群,只能聊天;每小时超过 {n} 人后仍要你同意",
|
|
6848
|
+
joining: "加入",
|
|
6849
|
+
capacity: "人数上限",
|
|
6850
|
+
capacityValue: "最多 {n} 人",
|
|
6851
|
+
history: "新成员可见的聊天记录",
|
|
6852
|
+
historyNone: "不可见",
|
|
6853
|
+
historyValue: "最近 {n} 条",
|
|
6854
|
+
linkDays: "邀请链接有效期",
|
|
6855
|
+
linkDaysValue7: "7 天",
|
|
6856
|
+
linkDaysValue30: "30 天",
|
|
6857
|
+
linkDaysValue365: "1 年",
|
|
6858
|
+
linkDaysHint: "会生成新链接,之前的链接失效。",
|
|
5643
6859
|
agents: "允许邀请智能体",
|
|
5644
6860
|
agentsHint: "成员可以请自己的智能体进群帮忙",
|
|
5645
6861
|
doubles: "允许分身代答",
|
|
@@ -5663,6 +6879,19 @@ var ZH_TW4 = {
|
|
|
5663
6879
|
rulesOthers: "由群主設定,每個人的 Ta 都按這個執行。",
|
|
5664
6880
|
approve: "受邀的好友也要同意",
|
|
5665
6881
|
approveHint: "你或管理員邀請的好友,也要你們同意後才能進群",
|
|
6882
|
+
guests: "網頁訪客直接進",
|
|
6883
|
+
guestsHint: "用瀏覽器開啟連結的人不用同意就能進群,只能聊天;每小時超過 {n} 人後仍要你同意",
|
|
6884
|
+
joining: "加入",
|
|
6885
|
+
capacity: "人數上限",
|
|
6886
|
+
capacityValue: "最多 {n} 人",
|
|
6887
|
+
history: "新成員可見的聊天記錄",
|
|
6888
|
+
historyNone: "不可見",
|
|
6889
|
+
historyValue: "最近 {n} 則",
|
|
6890
|
+
linkDays: "邀請連結有效期",
|
|
6891
|
+
linkDaysValue7: "7 天",
|
|
6892
|
+
linkDaysValue30: "30 天",
|
|
6893
|
+
linkDaysValue365: "1 年",
|
|
6894
|
+
linkDaysHint: "會產生新連結,之前的連結失效。",
|
|
5666
6895
|
agents: "允許邀請智慧體",
|
|
5667
6896
|
agentsHint: "成員可以請自己的智慧體進群幫忙",
|
|
5668
6897
|
doubles: "允許分身代答",
|
|
@@ -5686,6 +6915,19 @@ var JA4 = {
|
|
|
5686
6915
|
rulesOthers: "グループ主が設定し、全員の Ta が守ります。",
|
|
5687
6916
|
approve: "招待した友だちも承認が必要",
|
|
5688
6917
|
approveHint: "あなたや管理者が招待した友だちも、承認されてから参加します",
|
|
6918
|
+
guests: "ブラウザからは承認なしで参加",
|
|
6919
|
+
guestsHint: "ブラウザでリンクを開いた人は承認なしで参加し、チャットのみできます。1 時間に {n} 人を超えると承認が必要です",
|
|
6920
|
+
joining: "参加",
|
|
6921
|
+
capacity: "人数の上限",
|
|
6922
|
+
capacityValue: "最大 {n} 人",
|
|
6923
|
+
history: "新しいメンバーが見られる履歴",
|
|
6924
|
+
historyNone: "見られない",
|
|
6925
|
+
historyValue: "直近 {n} 件",
|
|
6926
|
+
linkDays: "招待リンクの有効期限",
|
|
6927
|
+
linkDaysValue7: "7 日",
|
|
6928
|
+
linkDaysValue30: "30 日",
|
|
6929
|
+
linkDaysValue365: "1 年",
|
|
6930
|
+
linkDaysHint: "新しいリンクを作成し、以前のリンクは無効になります。",
|
|
5689
6931
|
agents: "エージェントの招待を許可",
|
|
5690
6932
|
agentsHint: "メンバーは自分のエージェントを招待して手伝わせることができます",
|
|
5691
6933
|
doubles: "分身の代理応答を許可",
|
|
@@ -5700,15 +6942,19 @@ function gt(key, values = {}) {
|
|
|
5700
6942
|
|
|
5701
6943
|
// web-src/group-rules-view.tsx
|
|
5702
6944
|
var ADMINS_MAX = 8;
|
|
6945
|
+
var GUESTS_PER_HOUR = 30;
|
|
6946
|
+
var OWN_RULES = ["approve", "guests"];
|
|
5703
6947
|
var SWITCHES = [
|
|
5704
6948
|
{ rule: "approve", label: () => gt("approve"), hint: () => gt("approveHint") },
|
|
6949
|
+
{ rule: "guests", label: () => gt("guests"), hint: () => gt("guestsHint", { n: GUESTS_PER_HOUR }) },
|
|
5705
6950
|
...ROOM_RULES.map((rule) => ({ rule, label: () => gt(rule), hint: () => gt(`${rule}Hint`) }))
|
|
5706
6951
|
];
|
|
6952
|
+
var isOwn = (rule) => OWN_RULES.includes(rule);
|
|
5707
6953
|
function isOn(room, rule) {
|
|
5708
|
-
return rule
|
|
6954
|
+
return isOwn(rule) ? room.rules?.[rule] === true : room.rules?.[rule] !== false;
|
|
5709
6955
|
}
|
|
5710
6956
|
function countSet(room) {
|
|
5711
|
-
return SWITCHES.filter(({ rule }) => isOn(room, rule) !== (rule
|
|
6957
|
+
return SWITCHES.filter(({ rule }) => isOn(room, rule) !== !isOwn(rule)).length;
|
|
5712
6958
|
}
|
|
5713
6959
|
function GroupRulesRow({ room }) {
|
|
5714
6960
|
const Chevron = icon("ChevronRight");
|
|
@@ -5728,6 +6974,7 @@ function GroupRulesRow({ room }) {
|
|
|
5728
6974
|
size: 15
|
|
5729
6975
|
}));
|
|
5730
6976
|
}
|
|
6977
|
+
var HISTORY_CHOICES = [0, 50, 100, 200, 500];
|
|
5731
6978
|
function configure(room, options) {
|
|
5732
6979
|
const call = rooms()?.configureRoom(room.id, options);
|
|
5733
6980
|
return (call ?? Promise.resolve()).catch((error) => {
|
|
@@ -5755,12 +7002,72 @@ function AdminRow({ room, member, admins }) {
|
|
|
5755
7002
|
onChange: (next) => configure(room, { admins: next ? [...admins, member.member] : admins.filter((id) => id !== member.member) })
|
|
5756
7003
|
}));
|
|
5757
7004
|
}
|
|
7005
|
+
function Joining({ room }) {
|
|
7006
|
+
const [menu, openMenu] = pi.ui.useContextMenu();
|
|
7007
|
+
const days = useLinkDays(room.id);
|
|
7008
|
+
const Check = icon("Check");
|
|
7009
|
+
const choose = (event, items) => openMenu(event, [items.map((item) => ({ key: item.key, label: item.label, ...item.on ? { icon: Check } : {}, run: item.run }))]);
|
|
7010
|
+
const capacity = room.capacity ?? MEMBER_CHOICES[0];
|
|
7011
|
+
const history = room.history ?? 0;
|
|
7012
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
7013
|
+
className: "trm-panel-label"
|
|
7014
|
+
}, gt("joining")), /* @__PURE__ */ React.createElement(JoinRow, {
|
|
7015
|
+
label: gt("capacity"),
|
|
7016
|
+
value: gt("capacityValue", { n: capacity }),
|
|
7017
|
+
onClick: (event) => choose(event, MEMBER_CHOICES.map((n) => ({
|
|
7018
|
+
key: String(n),
|
|
7019
|
+
label: gt("capacityValue", { n }),
|
|
7020
|
+
on: n === capacity,
|
|
7021
|
+
run: () => void configure(room, { members: n }).catch(() => {
|
|
7022
|
+
return;
|
|
7023
|
+
})
|
|
7024
|
+
})))
|
|
7025
|
+
}), /* @__PURE__ */ React.createElement(JoinRow, {
|
|
7026
|
+
label: gt("linkDays"),
|
|
7027
|
+
value: gt(`linkDaysValue${days}`),
|
|
7028
|
+
onClick: (event) => choose(event, LINK_DAYS.map((n) => ({
|
|
7029
|
+
key: String(n),
|
|
7030
|
+
label: gt(`linkDaysValue${n}`),
|
|
7031
|
+
on: n === days,
|
|
7032
|
+
run: () => void setLinkDays(room.id, n).then(() => pi.ui.notify(gt("linkDaysHint"))).catch((error) => pi.ui.notify(message(error), "error"))
|
|
7033
|
+
})))
|
|
7034
|
+
}), /* @__PURE__ */ React.createElement(JoinRow, {
|
|
7035
|
+
label: gt("history"),
|
|
7036
|
+
value: history ? gt("historyValue", { n: history }) : gt("historyNone"),
|
|
7037
|
+
onClick: (event) => choose(event, HISTORY_CHOICES.map((n) => ({
|
|
7038
|
+
key: String(n),
|
|
7039
|
+
label: n ? gt("historyValue", { n }) : gt("historyNone"),
|
|
7040
|
+
on: n === history,
|
|
7041
|
+
run: () => void configure(room, { history: n }).catch(() => {
|
|
7042
|
+
return;
|
|
7043
|
+
})
|
|
7044
|
+
})))
|
|
7045
|
+
}), menu, /* @__PURE__ */ React.createElement("div", {
|
|
7046
|
+
className: "trm-panel-sep"
|
|
7047
|
+
}));
|
|
7048
|
+
}
|
|
7049
|
+
function JoinRow({ label, value, onClick }) {
|
|
7050
|
+
const Chevron = icon("ChevronRight");
|
|
7051
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
7052
|
+
type: "button",
|
|
7053
|
+
className: "trm-setting",
|
|
7054
|
+
onClick
|
|
7055
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
7056
|
+
className: "trm-setting-label"
|
|
7057
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
7058
|
+
className: "trm-setting-value trm-ellipsis"
|
|
7059
|
+
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
7060
|
+
size: 15
|
|
7061
|
+
}));
|
|
7062
|
+
}
|
|
5758
7063
|
function GroupRulesView({ room }) {
|
|
5759
7064
|
const candidates = room.members.filter((member) => !member.owner && !member.guest && !member.self);
|
|
5760
7065
|
const admins = room.members.filter((member) => member.admin).map((member) => member.member);
|
|
5761
7066
|
return /* @__PURE__ */ React.createElement("div", {
|
|
5762
7067
|
className: "trm-rules"
|
|
5763
|
-
}, room.owner && /* @__PURE__ */ React.createElement(
|
|
7068
|
+
}, room.owner && /* @__PURE__ */ React.createElement(Joining, {
|
|
7069
|
+
room
|
|
7070
|
+
}), room.owner && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5764
7071
|
className: "trm-panel-label"
|
|
5765
7072
|
}, gt("admins")), /* @__PURE__ */ React.createElement("p", {
|
|
5766
7073
|
className: "trm-note trm-panel-note"
|
|
@@ -5995,7 +7302,21 @@ function MembersView() {
|
|
|
5995
7302
|
className: "trm-panel-label"
|
|
5996
7303
|
}, t("membersCount", { n: room.members.length, online })), /* @__PURE__ */ React.createElement("ul", {
|
|
5997
7304
|
className: "trm-panel-members"
|
|
5998
|
-
},
|
|
7305
|
+
}, peerFriend && !!pi.rooms && /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
7306
|
+
type: "button",
|
|
7307
|
+
className: "trm-member trm-member-add",
|
|
7308
|
+
onClick: () => pi.ui.startGroup ? pi.ui.startGroup(peerFriend.id) : openGroupPicker(peerFriend)
|
|
7309
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
7310
|
+
className: "trm-member-plus"
|
|
7311
|
+
}, /* @__PURE__ */ React.createElement(Plus, {
|
|
7312
|
+
size: 16
|
|
7313
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
7314
|
+
className: "trm-member-text"
|
|
7315
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
7316
|
+
className: "trm-member-name"
|
|
7317
|
+
}, t("directGroup")), /* @__PURE__ */ React.createElement("span", {
|
|
7318
|
+
className: "trm-member-detail"
|
|
7319
|
+
}, t("directGroupLine", { name: peerFriend.name }))))), (room.owner || room.admin) && !direct && !!pi.rooms && /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
|
|
5999
7320
|
type: "button",
|
|
6000
7321
|
className: "trm-member trm-member-add",
|
|
6001
7322
|
onClick: () => openFriendPicker(room)
|
|
@@ -6182,11 +7503,12 @@ function roomPreview(room, last) {
|
|
|
6182
7503
|
}
|
|
6183
7504
|
const self = room.members.find((each) => each.self)?.member;
|
|
6184
7505
|
if (direct && !last.agent && !last.double) {
|
|
6185
|
-
return plain(last
|
|
7506
|
+
return plain(RelayRoomChatUtil.preview(last, t("picture"), { file: t("file"), voice: t("voice"), video: t("video") }));
|
|
6186
7507
|
}
|
|
6187
7508
|
const person = room.members.find((each) => each.member === last.from)?.name ?? last.name;
|
|
6188
7509
|
const name = last.agent?.name ?? (!last.double ? person : last.from === self ? dt("myDouble") : dt("doubleOf", { name: person }));
|
|
6189
|
-
|
|
7510
|
+
const said = plain(RelayRoomChatUtil.preview(last, t("picture"), { file: t("file"), voice: t("voice"), video: t("video") }));
|
|
7511
|
+
return last.from === self && !last.agent && !last.double ? said : t("said", { name, text: said });
|
|
6190
7512
|
}
|
|
6191
7513
|
function lastAt(room) {
|
|
6192
7514
|
const lines = room.status === "member" ? book.chat(room.id)?.lines : undefined;
|
|
@@ -6257,7 +7579,12 @@ function RoomList({ openMenu }) {
|
|
|
6257
7579
|
const { identity, rooms: list, requests, groupInvites: invites, opened, seen } = useBook();
|
|
6258
7580
|
const groupInvites = invites.filter((invite) => !DirectUtil.is(invite));
|
|
6259
7581
|
const { asks } = useDoubles();
|
|
6260
|
-
const
|
|
7582
|
+
const kept = useDirects();
|
|
7583
|
+
const shown = React.useMemo(() => {
|
|
7584
|
+
const extra = new Set(DirectUtil.extra(list ?? [], kept).map((room) => room.id));
|
|
7585
|
+
return (list ?? []).filter((room) => !extra.has(room.id));
|
|
7586
|
+
}, [list, kept]);
|
|
7587
|
+
const sorted = useSorted(shown);
|
|
6261
7588
|
return /* @__PURE__ */ React.createElement("div", {
|
|
6262
7589
|
className: "trm-list"
|
|
6263
7590
|
}, asks.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
@@ -6306,7 +7633,7 @@ function RoomList({ openMenu }) {
|
|
|
6306
7633
|
function addMenu() {
|
|
6307
7634
|
return [
|
|
6308
7635
|
[
|
|
6309
|
-
{ key: "new", label: t("newRoom"), icon: icon("MessagesSquare"), run: () =>
|
|
7636
|
+
{ key: "new", label: t("newRoom"), icon: icon("MessagesSquare"), run: () => pi.ui.startGroup ? pi.ui.startGroup() : openGroupPicker() },
|
|
6310
7637
|
{ key: "link", label: t("joinByLink"), icon: icon("Link"), run: () => void pasteLink() },
|
|
6311
7638
|
...pi.ui.scanCode ? [{ key: "scan", label: t("scan"), icon: icon("ScanLine"), run: () => void scanLink() }] : []
|
|
6312
7639
|
],
|
|
@@ -6519,7 +7846,9 @@ class RoomsHome {
|
|
|
6519
7846
|
const { rooms: rooms2 = [], seen, friends, friendRequests, requests } = book.get();
|
|
6520
7847
|
const groupInvites = book.get().groupInvites.filter((invite) => !DirectUtil.is(invite));
|
|
6521
7848
|
const sent = this.partners ? FriendShares.get() : [];
|
|
6522
|
-
const
|
|
7849
|
+
const extra = new Set(DirectUtil.extra(rooms2, directs.get()).map((room) => room.id));
|
|
7850
|
+
tidyDirects(rooms2);
|
|
7851
|
+
const joined = this.shown || this.partners ? rooms2.filter((room) => room.status === "member" && !extra.has(room.id)) : [];
|
|
6523
7852
|
this.follow(joined);
|
|
6524
7853
|
const rows = joined.map((room) => ({ room, lines: book.chat(room.id)?.lines ?? [] })).sort((a, b) => lastAt(b.room) - lastAt(a.room));
|
|
6525
7854
|
const signature = [
|
|
@@ -6724,6 +8053,241 @@ function roomsSettings() {
|
|
|
6724
8053
|
};
|
|
6725
8054
|
}
|
|
6726
8055
|
|
|
8056
|
+
// web-src/rooms-partners.tsx
|
|
8057
|
+
var NAME = "@celljs/ta-rooms";
|
|
8058
|
+
var CHANNELS = "@celljs/ta-channels";
|
|
8059
|
+
|
|
8060
|
+
class RoomsPartners {
|
|
8061
|
+
current = [];
|
|
8062
|
+
signature = "";
|
|
8063
|
+
listeners = new Set;
|
|
8064
|
+
chats = new Map;
|
|
8065
|
+
faces = new Map;
|
|
8066
|
+
partners = () => this.current;
|
|
8067
|
+
subscribe = (listener) => {
|
|
8068
|
+
this.listeners.add(listener);
|
|
8069
|
+
return () => this.listeners.delete(listener);
|
|
8070
|
+
};
|
|
8071
|
+
start() {
|
|
8072
|
+
const stops = [
|
|
8073
|
+
book.subscribe(() => this.refresh()),
|
|
8074
|
+
directs.subscribe(() => this.refresh()),
|
|
8075
|
+
FriendShares.subscribe(() => this.refresh()),
|
|
8076
|
+
FriendShares.start()
|
|
8077
|
+
];
|
|
8078
|
+
this.refresh();
|
|
8079
|
+
return () => {
|
|
8080
|
+
for (const stop of stops) {
|
|
8081
|
+
stop();
|
|
8082
|
+
}
|
|
8083
|
+
for (const stop of this.chats.values()) {
|
|
8084
|
+
stop();
|
|
8085
|
+
}
|
|
8086
|
+
this.chats.clear();
|
|
8087
|
+
};
|
|
8088
|
+
}
|
|
8089
|
+
add() {
|
|
8090
|
+
return [
|
|
8091
|
+
{ key: "friend", label: t("addFriend"), icon: icon("UserPlus"), run: openAddFriend },
|
|
8092
|
+
...pi.ui.scanCode ? [{ key: "scan", label: t("scan"), icon: icon("ScanLine"), run: () => void scanLink() }] : []
|
|
8093
|
+
];
|
|
8094
|
+
}
|
|
8095
|
+
async group(members) {
|
|
8096
|
+
const friend = (member) => member.extension === NAME && member.kind === "friend";
|
|
8097
|
+
const agent = (member) => member.extension === CHANNELS && member.kind === "agent";
|
|
8098
|
+
const server = rooms();
|
|
8099
|
+
if (!server?.inviteFriends || !members.some(friend) || !members.every((member) => friend(member) || agent(member))) {
|
|
8100
|
+
return false;
|
|
8101
|
+
}
|
|
8102
|
+
const room = await server.createRoom({ kind: ROOMS_KIND, title: groupTitle([book.get().identity?.name ?? "", ...members.map((member) => member.name)]) });
|
|
8103
|
+
await server.inviteFriends(room.id, members.filter(friend).map((member) => member.id));
|
|
8104
|
+
for (const member of members.filter(agent)) {
|
|
8105
|
+
await callDoubles({ kind: "invite", room: room.id, agent: member.id }).catch((error) => pi.ui.notify(error instanceof Error ? error.message : String(error), "error"));
|
|
8106
|
+
}
|
|
8107
|
+
await book.load();
|
|
8108
|
+
await openRoom(room.id, true);
|
|
8109
|
+
return true;
|
|
8110
|
+
}
|
|
8111
|
+
refresh() {
|
|
8112
|
+
const state = book.get();
|
|
8113
|
+
const { rooms: list = [], seen, friends = [], friendRequests, requests } = state;
|
|
8114
|
+
const invites = state.groupInvites.filter((invite) => !DirectUtil.is(invite));
|
|
8115
|
+
const shares = FriendShares.get();
|
|
8116
|
+
const extra = new Set(DirectUtil.extra(list, directs.get()).map((room) => room.id));
|
|
8117
|
+
tidyDirects(list);
|
|
8118
|
+
const joined = list.filter((room) => room.status === "member" && !extra.has(room.id));
|
|
8119
|
+
this.follow(joined);
|
|
8120
|
+
const lines = (room) => book.chat(room.id)?.lines ?? [];
|
|
8121
|
+
const signature = [
|
|
8122
|
+
pi.ui.language,
|
|
8123
|
+
...friends.map((friend) => [friend.id, friend.name, friend.look, friend.status, friend.online ? 1 : 0].join("/")),
|
|
8124
|
+
...friendRequests.map((request) => `${request.id}/${request.at}`),
|
|
8125
|
+
...requests.map((request) => `${request.room}/${request.ask}`),
|
|
8126
|
+
...invites.map((invite) => invite.room),
|
|
8127
|
+
...shares.map((share) => `${share.id}/${share.seen ? 1 : 0}`),
|
|
8128
|
+
...joined.map((room) => [
|
|
8129
|
+
room.id,
|
|
8130
|
+
room.title,
|
|
8131
|
+
room.members.length,
|
|
8132
|
+
lines(room).at(-1)?.id ?? "",
|
|
8133
|
+
unseen(room, lines(room), seen) ? 1 : 0,
|
|
8134
|
+
Object.keys(directs.get()).length
|
|
8135
|
+
].join(":"))
|
|
8136
|
+
].join("|");
|
|
8137
|
+
if (signature === this.signature) {
|
|
8138
|
+
return;
|
|
8139
|
+
}
|
|
8140
|
+
this.signature = signature;
|
|
8141
|
+
const directOf = new Map;
|
|
8142
|
+
for (const room of joined.filter(DirectUtil.is)) {
|
|
8143
|
+
const peer = DirectUtil.friendOf(room, directs.get());
|
|
8144
|
+
if (peer) {
|
|
8145
|
+
directOf.set(peer, room);
|
|
8146
|
+
}
|
|
8147
|
+
}
|
|
8148
|
+
this.current = [
|
|
8149
|
+
...friendRequests.map((request) => this.asking(request)),
|
|
8150
|
+
...friends.map((friend) => this.friend(friend, directOf.get(friend.id), shares.filter((share) => share.by.id === friend.id && !share.seen).at(-1))),
|
|
8151
|
+
...requests.map((request) => this.joining(request)),
|
|
8152
|
+
...invites.map((invite) => this.invited(invite)),
|
|
8153
|
+
...joined.filter((room) => !DirectUtil.is(room)).map((room) => this.groupOf(room))
|
|
8154
|
+
];
|
|
8155
|
+
for (const listener of this.listeners) {
|
|
8156
|
+
listener();
|
|
8157
|
+
}
|
|
8158
|
+
}
|
|
8159
|
+
friend(friend, direct, share) {
|
|
8160
|
+
const said = direct ? book.chat(direct.id)?.lines ?? [] : [];
|
|
8161
|
+
const at = direct ? lastAt(direct) : undefined;
|
|
8162
|
+
const shared = share && (at === undefined || share.at > at) ? share : undefined;
|
|
8163
|
+
const online = friend.status === "friend" ? friend.online : undefined;
|
|
8164
|
+
return {
|
|
8165
|
+
id: friend.id,
|
|
8166
|
+
kind: "friend",
|
|
8167
|
+
name: friend.name,
|
|
8168
|
+
face: this.faceOf(`friend:${friend.id}`, ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
8169
|
+
id: friend.id,
|
|
8170
|
+
name: friend.name,
|
|
8171
|
+
size
|
|
8172
|
+
})),
|
|
8173
|
+
icon: icon("Contact"),
|
|
8174
|
+
...friend.status === "adding" ? { status: "waiting", about: t("friendAdding") } : {},
|
|
8175
|
+
...online ? { online } : {},
|
|
8176
|
+
chat: shared ? { last: t("friendShareRow", { title: shared.title || shared.link }), at: shared.at, unseen: true } : direct ? {
|
|
8177
|
+
last: roomPreview(direct, said.at(-1)) || undefined,
|
|
8178
|
+
at,
|
|
8179
|
+
unseen: unseen(direct, said, book.get().seen),
|
|
8180
|
+
close: { key: "close", label: rt("directDelete"), danger: true, run: () => void leaveRoom(direct) }
|
|
8181
|
+
} : undefined,
|
|
8182
|
+
open: () => shared ? openFriendShare(shared) : friend.status === "friend" ? openDirect(friend) : openFriend(friend.id),
|
|
8183
|
+
info: () => openPerson({ id: friend.id, name: friend.name }),
|
|
8184
|
+
remove: { key: "remove", label: rt("removeFriendLong"), danger: true, run: () => void removeFriend(friend) }
|
|
8185
|
+
};
|
|
8186
|
+
}
|
|
8187
|
+
groupOf(room) {
|
|
8188
|
+
const said = book.chat(room.id)?.lines ?? [];
|
|
8189
|
+
return {
|
|
8190
|
+
id: room.id,
|
|
8191
|
+
kind: "group",
|
|
8192
|
+
name: room.title,
|
|
8193
|
+
face: this.faceOf(`room:${room.id}`, ({ size }) => /* @__PURE__ */ React.createElement(RoomFaceOf, {
|
|
8194
|
+
id: room.id,
|
|
8195
|
+
size
|
|
8196
|
+
})),
|
|
8197
|
+
icon: icon("Users"),
|
|
8198
|
+
friends: true,
|
|
8199
|
+
about: t("roomOf", { name: room.ownerName }),
|
|
8200
|
+
chat: { last: roomPreview(room, said.at(-1)) || undefined, at: lastAt(room), unseen: unseen(room, said, book.get().seen) },
|
|
8201
|
+
open: () => openRoom(room.id, true),
|
|
8202
|
+
info: () => void openRoom(room.id, true).then(() => pi.ui.showView(MEMBERS_VIEW)),
|
|
8203
|
+
remove: { key: "leave", label: room.owner ? t("close") : t("leave"), danger: true, run: () => void leaveRoom(room) }
|
|
8204
|
+
};
|
|
8205
|
+
}
|
|
8206
|
+
asking(request) {
|
|
8207
|
+
return {
|
|
8208
|
+
id: `friend-request:${request.id}`,
|
|
8209
|
+
kind: "friend",
|
|
8210
|
+
name: request.name,
|
|
8211
|
+
face: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
8212
|
+
id: request.id,
|
|
8213
|
+
name: request.name,
|
|
8214
|
+
size
|
|
8215
|
+
}),
|
|
8216
|
+
icon: icon("UserPlus"),
|
|
8217
|
+
status: "asking",
|
|
8218
|
+
about: request.via === "room" && request.room ? t("friendRequestRoom", { room: request.room }) : t("friendRequestLink"),
|
|
8219
|
+
open: openFriendRequests
|
|
8220
|
+
};
|
|
8221
|
+
}
|
|
8222
|
+
joining(request) {
|
|
8223
|
+
return {
|
|
8224
|
+
id: `request:${request.room}:${request.ask}`,
|
|
8225
|
+
kind: "group",
|
|
8226
|
+
name: request.name,
|
|
8227
|
+
face: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
8228
|
+
id: request.id,
|
|
8229
|
+
name: request.name,
|
|
8230
|
+
size
|
|
8231
|
+
}),
|
|
8232
|
+
icon: icon("UserPlus"),
|
|
8233
|
+
status: "asking",
|
|
8234
|
+
about: t("requestLine", { title: request.title }),
|
|
8235
|
+
open: openRequests
|
|
8236
|
+
};
|
|
8237
|
+
}
|
|
8238
|
+
invited(invite) {
|
|
8239
|
+
return {
|
|
8240
|
+
id: `invite:${invite.room}`,
|
|
8241
|
+
kind: "group",
|
|
8242
|
+
name: invite.title,
|
|
8243
|
+
face: ({ size }) => /* @__PURE__ */ React.createElement(Face, {
|
|
8244
|
+
id: invite.by.id,
|
|
8245
|
+
name: invite.by.name,
|
|
8246
|
+
size
|
|
8247
|
+
}),
|
|
8248
|
+
icon: icon("MessagesSquare"),
|
|
8249
|
+
status: "invited",
|
|
8250
|
+
about: t("groupInviteLine", { name: invite.by.name }),
|
|
8251
|
+
open: () => openGroupInvite(invite)
|
|
8252
|
+
};
|
|
8253
|
+
}
|
|
8254
|
+
faceOf(key, face) {
|
|
8255
|
+
let kept = this.faces.get(key);
|
|
8256
|
+
if (!kept) {
|
|
8257
|
+
kept = face;
|
|
8258
|
+
this.faces.set(key, kept);
|
|
8259
|
+
}
|
|
8260
|
+
return kept;
|
|
8261
|
+
}
|
|
8262
|
+
follow(joined) {
|
|
8263
|
+
const ids = new Set(joined.map((room) => room.id));
|
|
8264
|
+
for (const [id, stop] of this.chats) {
|
|
8265
|
+
if (!ids.has(id)) {
|
|
8266
|
+
stop();
|
|
8267
|
+
this.chats.delete(id);
|
|
8268
|
+
}
|
|
8269
|
+
}
|
|
8270
|
+
for (const room of joined) {
|
|
8271
|
+
if (!this.chats.has(room.id)) {
|
|
8272
|
+
const stop = book.chat(room.id)?.subscribe(() => this.refresh());
|
|
8273
|
+
this.chats.set(room.id, stop ?? (() => {
|
|
8274
|
+
return;
|
|
8275
|
+
}));
|
|
8276
|
+
}
|
|
8277
|
+
}
|
|
8278
|
+
}
|
|
8279
|
+
}
|
|
8280
|
+
function RoomFaceOf({ id, size }) {
|
|
8281
|
+
const room = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get().rooms?.find((each) => each.id === id));
|
|
8282
|
+
return room ? DirectUtil.is(room) ? /* @__PURE__ */ React.createElement(DirectFace, {
|
|
8283
|
+
room,
|
|
8284
|
+
size
|
|
8285
|
+
}) : /* @__PURE__ */ React.createElement(RoomFace, {
|
|
8286
|
+
room,
|
|
8287
|
+
size
|
|
8288
|
+
}) : null;
|
|
8289
|
+
}
|
|
8290
|
+
|
|
6727
8291
|
// web-src/style.ts
|
|
6728
8292
|
var STYLE = `
|
|
6729
8293
|
.trm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -6838,6 +8402,8 @@ var STYLE = `
|
|
|
6838
8402
|
.trm-chat-empty strong { margin-top: 6px; color: var(--ta-text); font-size: calc(16px * var(--ta-font-scale)); }
|
|
6839
8403
|
.trm-chat-hint { margin-top: 4px; font-size: calc(12px * var(--ta-font-scale)); line-height: 1.6; }
|
|
6840
8404
|
.trm-mine { margin: 6px 0 2px; }
|
|
8405
|
+
.trm-pending .ta-bubble { opacity: 0.6; transition: opacity 0.2s; }
|
|
8406
|
+
.trm-unsent { align-self: flex-end; margin-top: 2px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); }
|
|
6841
8407
|
.trm-msg { display: flex; align-items: flex-start; gap: 10px; }
|
|
6842
8408
|
.trm-msg.trm-first { margin-top: 10px; }
|
|
6843
8409
|
.trm-msg-face { display: flex; justify-content: center; width: 28px; flex: none; }
|
|
@@ -6845,6 +8411,26 @@ var STYLE = `
|
|
|
6845
8411
|
.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)); }
|
|
6846
8412
|
.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; }
|
|
6847
8413
|
.trm-msg-bubble pre { max-width: 100%; overflow-x: auto; }
|
|
8414
|
+
/* Pictures of a line (ui.ChatImages), no bubble around them, on the side of who sent them. */
|
|
8415
|
+
.trm-pics { margin: 1px 0 3px; }
|
|
8416
|
+
.trm-mine .trm-pics { align-self: flex-end; }
|
|
8417
|
+
.trm-files { display: flex; flex-direction: column; gap: 6px; margin: 1px 0 3px; max-width: min(78%, 280px); }
|
|
8418
|
+
.trm-mine .trm-files { align-self: flex-end; align-items: flex-end; }
|
|
8419
|
+
.trm-file { display: flex; align-items: center; gap: 12px; width: 240px; max-width: 100%; padding: 10px 12px; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-side); color: var(--ta-secondary); text-align: left; cursor: pointer; }
|
|
8420
|
+
.trm-file-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
|
|
8421
|
+
.trm-file-name { color: var(--ta-body); font-size: calc(14px * var(--ta-font-scale)); line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
|
|
8422
|
+
.trm-file-size { font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
8423
|
+
.trm-voice { display: inline-flex; align-items: center; gap: 8px; min-width: 72px; max-width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--ta-border-muted); border-radius: 5px 16px 16px 16px; background: var(--ta-side); color: var(--ta-body); font-size: calc(13px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; cursor: pointer; }
|
|
8424
|
+
.trm-mine .trm-voice { flex-direction: row-reverse; border: 0; border-radius: 16px 16px 5px 16px; background: var(--ta-user); color: var(--ta-text); }
|
|
8425
|
+
.trm-video { position: relative; width: 200px; max-height: 300px; border: 0; border-radius: 10px; background: #222 center / cover no-repeat; overflow: hidden; cursor: pointer; }
|
|
8426
|
+
.trm-video-mark { position: absolute; inset: 0; margin: auto; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(0, 0, 0, 0.45); color: #fff; }
|
|
8427
|
+
.trm-video-time { position: absolute; right: 8px; bottom: 6px; color: #fff; font-size: calc(11.5px * var(--ta-font-scale)); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); font-variant-numeric: tabular-nums; }
|
|
8428
|
+
.trm-video-play { display: block; width: 100%; max-height: 70vh; border-radius: 8px; background: #000; }
|
|
8429
|
+
.trm-uploads { display: flex; flex-direction: column; gap: 4px; padding: 4px 12px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
8430
|
+
.trm-upload { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
8431
|
+
.trm-recorder { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0 4px; }
|
|
8432
|
+
.trm-recorder-dot { width: 12px; height: 12px; border-radius: 50%; background: #e5484d; animation: trm-breathe 1.2s ease-in-out infinite; }
|
|
8433
|
+
.trm-recorder-time { font-size: calc(28px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; color: var(--ta-body); }
|
|
6848
8434
|
.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; }
|
|
6849
8435
|
/* Above the keyboard the home indicator is not there: no room for it, as under the box of a conversation. */
|
|
6850
8436
|
:root[data-keyboard] .trm-chat-bottom { padding-bottom: 8px; }
|
|
@@ -6938,6 +8524,11 @@ button.trm-member { cursor: pointer; }
|
|
|
6938
8524
|
.trm-try-alone { margin-top: 12px; }
|
|
6939
8525
|
.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)); }
|
|
6940
8526
|
.trm-agent-pick .trm-member:disabled { cursor: default; opacity: 1; }
|
|
8527
|
+
.trm-group-pick { max-height: min(56vh, 420px); overflow-y: auto; }
|
|
8528
|
+
.trm-group-pick .trm-member:disabled { cursor: default; opacity: 1; }
|
|
8529
|
+
.trm-pick-box { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: 1.5px solid var(--ta-border-field); border-radius: 50%; color: #fff; transition: background 0.12s, border-color 0.12s; }
|
|
8530
|
+
.trm-pick-on { border-color: var(--ta-green); background: var(--ta-green); }
|
|
8531
|
+
.trm-group-pick .trm-member:disabled .trm-pick-on { opacity: 0.5; }
|
|
6941
8532
|
.trm-agent-pick .trm-member:disabled .trm-member-detail { color: var(--ta-green); }
|
|
6942
8533
|
.trm-member-may { color: var(--ta-secondary); }
|
|
6943
8534
|
.trm-member-action.trm-on-icon { opacity: 1; color: var(--ta-green); }
|
|
@@ -7087,11 +8678,16 @@ function activate(pi2) {
|
|
|
7087
8678
|
const stopDirects = pi2.rooms ? directs.start() : () => {
|
|
7088
8679
|
return;
|
|
7089
8680
|
};
|
|
7090
|
-
const
|
|
7091
|
-
const
|
|
8681
|
+
const shared = pi2.rooms && typeof pi2.registerPartners === "function" ? new RoomsPartners : undefined;
|
|
8682
|
+
const home = shared ? undefined : new RoomsHome(partners2);
|
|
8683
|
+
const stopHome = !pi2.rooms ? () => {
|
|
7092
8684
|
return;
|
|
7093
|
-
}
|
|
7094
|
-
|
|
8685
|
+
} : shared ? shared.start() : home?.start() ?? (() => {
|
|
8686
|
+
return;
|
|
8687
|
+
});
|
|
8688
|
+
if (shared) {
|
|
8689
|
+
pi2.registerPartners(shared);
|
|
8690
|
+
} else if (pi2.rooms && home) {
|
|
7095
8691
|
pi2.registerHomeItems?.(home);
|
|
7096
8692
|
}
|
|
7097
8693
|
const stopAsks = pi2.rooms ? listenAsks() : () => {
|