@ghostlytools/cli 1.7.2 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -24
- package/SKILL.md +10 -4
- package/dist/assets/{api-CcuCtc1H.js → api-Chhvpwok.js} +2 -2
- package/dist/assets/{api-tSZELCPQ.js → api-D3i2hwy0.js} +340 -155
- package/dist/assets/api-D3i2hwy0.js.map +1 -0
- package/dist/assets/{apiKit-BFk7GAk9.js → apiKit-BtsHrnoo.js} +60 -8
- package/dist/assets/apiKit-BtsHrnoo.js.map +1 -0
- package/dist/assets/{apps-D6THreq_.js → apps-BFJTqvAt.js} +1 -1
- package/dist/assets/{apps-C5Mi6x9Q.js → apps-BHl97rHs.js} +11 -9
- package/dist/assets/apps-BHl97rHs.js.map +1 -0
- package/dist/assets/{arkade-Cz0B9bJ0.js → arkade-BFE8KkEE.js} +2 -2
- package/dist/assets/{arkade-Cz0B9bJ0.js.map → arkade-BFE8KkEE.js.map} +1 -1
- package/dist/assets/{backup-A0hIa9GE.js → backup-Bbsr6nDi.js} +1 -1
- package/dist/assets/{backup-Wb2sm2dd.js → backup-CxACdtQX.js} +7 -7
- package/dist/assets/{backup-Wb2sm2dd.js.map → backup-CxACdtQX.js.map} +1 -1
- package/dist/assets/{blobFiles-Bckz9fjp.js → blobFiles-DOQDRdDI.js} +3 -3
- package/dist/assets/{blobFiles-Bckz9fjp.js.map → blobFiles-DOQDRdDI.js.map} +1 -1
- package/dist/assets/{buttons-Cf70NVYq.js → buttons-CieBtXEO.js} +35 -9
- package/dist/assets/buttons-CieBtXEO.js.map +1 -0
- package/dist/assets/buttons-YtAj3R_E.js +2 -0
- package/dist/assets/{daemonProof-Bp9lJDxf.js → daemonProof-QmtwDj-N.js} +2 -2
- package/dist/assets/{daemonProof-Bp9lJDxf.js.map → daemonProof-QmtwDj-N.js.map} +1 -1
- package/dist/assets/{envelope-kQ5kYjVE.js → envelope-DYiGwzq_.js} +2 -2
- package/dist/assets/{envelope-kQ5kYjVE.js.map → envelope-DYiGwzq_.js.map} +1 -1
- package/dist/assets/{errors-mnjSQlbX.js → errors-QUGP-jIF.js} +2 -2
- package/dist/assets/errors-QUGP-jIF.js.map +1 -0
- package/dist/assets/{fileBytes-OolN5cSY.js → fileBytes-BPDKufla.js} +1 -1
- package/dist/assets/{fileBytes-BD0v3rRG.js → fileBytes-DNgrRL0R.js} +3 -3
- package/dist/assets/{fileBytes-BD0v3rRG.js.map → fileBytes-DNgrRL0R.js.map} +1 -1
- package/dist/assets/{fileBytes-_fd-2JRY.js → fileBytes-Q3ehcEr8.js} +2 -2
- package/dist/assets/{fileBytes-_fd-2JRY.js.map → fileBytes-Q3ehcEr8.js.map} +1 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +2 -0
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js → fileBytesIdb-Dm1EyEbT.js} +3 -3
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js.map → fileBytesIdb-Dm1EyEbT.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js → fileBytesOpfs-ZGD21c4Q.js} +3 -3
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js.map → fileBytesOpfs-ZGD21c4Q.js.map} +1 -1
- package/dist/assets/{groupFiles-D9Ttlm3M.js → groupFiles-CBJIEvCE.js} +572 -6
- package/dist/assets/groupFiles-CBJIEvCE.js.map +1 -0
- package/dist/assets/{host-DpypH-fR.js → host-Va-r_KJz.js} +84 -23
- package/dist/assets/host-Va-r_KJz.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-D1rj84v2.js → hyperdhtRelay-B2uK9tJv.js} +2 -2
- package/dist/assets/{hyperdhtRelay-D1rj84v2.js.map → hyperdhtRelay-B2uK9tJv.js.map} +1 -1
- package/dist/assets/{idb-BlH8-O3R.js → idb-BkOJES5_.js} +5 -3
- package/dist/assets/idb-BkOJES5_.js.map +1 -0
- package/dist/assets/{irohWeb-BTSlWgEX.js → irohWeb-DxeEgQ-W.js} +2 -2
- package/dist/assets/{irohWeb-BTSlWgEX.js.map → irohWeb-DxeEgQ-W.js.map} +1 -1
- package/dist/assets/{main-BwgoQZVu.js → main-BX4oPWCJ.js} +589 -192
- package/dist/assets/main-BX4oPWCJ.js.map +1 -0
- package/dist/assets/{mainline-B1urhbEZ.js → mainline-IfWQOB-J.js} +39 -12
- package/dist/assets/mainline-IfWQOB-J.js.map +1 -0
- package/dist/assets/{networkReason-D2Z0BdIj.js → networkReason-N2vAaoth.js} +3 -3
- package/dist/assets/{networkReason-D2Z0BdIj.js.map → networkReason-N2vAaoth.js.map} +1 -1
- package/dist/assets/{nwc-T2aUK6bi.js → nwc-CzyCtNK2.js} +3 -3
- package/dist/assets/{nwc-T2aUK6bi.js.map → nwc-CzyCtNK2.js.map} +1 -1
- package/dist/assets/{nwcProvider-Dz-ty_DE.js → nwcProvider-DjWmEn3j.js} +2 -2
- package/dist/assets/{nwcProvider-Dz-ty_DE.js.map → nwcProvider-DjWmEn3j.js.map} +1 -1
- package/dist/assets/{profiles-C6XWqre5.js → profiles-DcCeOi7J.js} +104 -10
- package/dist/assets/profiles-DcCeOi7J.js.map +1 -0
- package/dist/assets/{registry-BlSTJlbv.js → registry-BmS02J5h.js} +1 -1
- package/dist/assets/{registry-Bazitl0a.js → registry-CeW8XEQc.js} +45 -14
- package/dist/assets/registry-CeW8XEQc.js.map +1 -0
- package/dist/assets/{resolve-Bx1Eeg-w.js → resolve-BvHkAhDH.js} +66 -29
- package/dist/assets/resolve-BvHkAhDH.js.map +1 -0
- package/dist/assets/{restoredRows-Fv-MuY45.js → restoredRows-mTTp3XNs.js} +2 -2
- package/dist/assets/{restoredRows-Fv-MuY45.js.map → restoredRows-mTTp3XNs.js.map} +1 -1
- package/dist/assets/{server-CnPj9wWh.js → server-BUcJo4vz.js} +1033 -821
- package/dist/assets/server-BUcJo4vz.js.map +1 -0
- package/dist/assets/{src-BsznF3XG.js → src-BB5-5P3s.js} +645 -196
- package/dist/assets/src-BB5-5P3s.js.map +1 -0
- package/dist/assets/{translate-cDBotA-b.js → translate-2WyaRVCr.js} +11 -9
- package/dist/assets/translate-2WyaRVCr.js.map +1 -0
- package/dist/assets/{usdt-DxxLdG60.js → usdt-BLazHiaP.js} +3 -3
- package/dist/assets/{usdt-DxxLdG60.js.map → usdt-BLazHiaP.js.map} +1 -1
- package/dist/assets/{words-qH8gGtmc.js → words-BaumxjXe.js} +5 -3
- package/dist/assets/words-BaumxjXe.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-tSZELCPQ.js.map +0 -1
- package/dist/assets/apiKit-BFk7GAk9.js.map +0 -1
- package/dist/assets/apps-C5Mi6x9Q.js.map +0 -1
- package/dist/assets/buttons-Bxxu3lSk.js +0 -2
- package/dist/assets/buttons-Cf70NVYq.js.map +0 -1
- package/dist/assets/errors-mnjSQlbX.js.map +0 -1
- package/dist/assets/fileBytesIdb-CsSQcSxD.js +0 -2
- package/dist/assets/groupFiles-D9Ttlm3M.js.map +0 -1
- package/dist/assets/host-DpypH-fR.js.map +0 -1
- package/dist/assets/idb-BlH8-O3R.js.map +0 -1
- package/dist/assets/main-BwgoQZVu.js.map +0 -1
- package/dist/assets/mainline-B1urhbEZ.js.map +0 -1
- package/dist/assets/profiles-C6XWqre5.js.map +0 -1
- package/dist/assets/registry-Bazitl0a.js.map +0 -1
- package/dist/assets/resolve-Bx1Eeg-w.js.map +0 -1
- package/dist/assets/server-CnPj9wWh.js.map +0 -1
- package/dist/assets/src-BsznF3XG.js.map +0 -1
- package/dist/assets/translate-cDBotA-b.js.map +0 -1
- package/dist/assets/words-qH8gGtmc.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { u as fileStore } from "./idb-
|
|
3
|
-
import { O as waitingGroupFile, T as removeStored,
|
|
4
|
-
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-
|
|
5
|
-
import { t as IDENTITY_PROVIDERS } from "./registry-
|
|
6
|
-
import { a as
|
|
7
|
-
import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-
|
|
8
|
-
import { i as localFileError, r as asCliError, t as CliError } from "./errors-
|
|
9
|
-
import { _ as
|
|
10
|
-
import { a as checkShownName } from "./profiles-
|
|
11
|
-
import { t as BACKUP_METHODS } from "./backup-
|
|
12
|
-
import { o as checkedBundle } from "./apps-
|
|
1
|
+
import { Cu as randomBytes$1, Eo as AWAITING_PEER_MS, Fr as TYPING_REFRESH_MS, Ga as replySnippet, Gc as appRef, Gi as identityStatement, Gn as GROUP_FILE_LIMITS, Io as LIMITS, Lc as isAppUrl, Lr as sanitizeTypingStatus, Mc as APP_PERMISSIONS, Mo as GhostlyHttpError, Po as parseLocalTarget, Pr as TYPING_KINDS, X as groupName, Yc as isAppRef, _a as parseVoiceMeta, _u as MAX_AVATAR_LENGTH, co as statusCardBytes, da as PLAYABLE_AUDIO, do as claimedTime, eo as STATUS_CARD_LIMITS, fa as VOICE_LIMITS, gl as inviteLink, ha as downsamplePeaks, io as cardLine, la as sanitizeFileName, ma as baseMime, nl as readImageMeta, no as appCardId, oo as checkStatusCard, pa as VOICE_METER, ri as APP_DATA_MAX_BYTES, ua as sanitizeMime, va as voiceDownloadName, vl as ownInviteRefusal, vu as sanitizeAvatar, wu as toBase64Url, ya as voiceLevel } from "./src-BB5-5P3s.js";
|
|
2
|
+
import { u as fileStore } from "./idb-BkOJES5_.js";
|
|
3
|
+
import { J as iceServerProblem, O as waitingGroupFile, T as removeStored, Y as iceServerSetting, i as groupOfFile, k as IDENTITY_DRAFT_TTL_MS, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-CBJIEvCE.js";
|
|
4
|
+
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DNgrRL0R.js";
|
|
5
|
+
import { t as IDENTITY_PROVIDERS } from "./registry-CeW8XEQc.js";
|
|
6
|
+
import { a as waitForConfirmed, c as waitForMessage, i as pressable, l as waitForRemoval, n as buttonsCard, o as waitForEdit, s as waitForGroupFrame, t as BUTTON_METHODS, u as findSecret } from "./buttons-CieBtXEO.js";
|
|
7
|
+
import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-BaumxjXe.js";
|
|
8
|
+
import { i as localFileError, r as asCliError, t as CliError } from "./errors-QUGP-jIF.js";
|
|
9
|
+
import { S as waitForState, _ as oneOf, a as dhtOnly, b as str, c as findGroup, d as inviteTaken, f as list, g as num, h as node, i as chatOrGroup, n as bool, o as findChat, p as messageOf, r as chatOf, s as findChatOrGroup, u as groupOf, v as sentAt, x as transportOffered, y as state } from "./apiKit-BtsHrnoo.js";
|
|
10
|
+
import { a as checkShownName } from "./profiles-DcCeOi7J.js";
|
|
11
|
+
import { t as BACKUP_METHODS } from "./backup-CxACdtQX.js";
|
|
12
|
+
import { o as checkedBundle } from "./apps-BHl97rHs.js";
|
|
13
13
|
import { generateMnemonic } from "@scure/bip39";
|
|
14
14
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
15
15
|
import { openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { access, constants as constants$1, open, readFile, rm, stat } from "node:fs/promises";
|
|
16
|
+
import { access, constants as constants$1, copyFile, link, open, readFile, rename, rm, stat } from "node:fs/promises";
|
|
17
17
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
18
18
|
import { spawn } from "node:child_process";
|
|
19
19
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
@@ -749,6 +749,8 @@ function filesOf(messages, transferOf) {
|
|
|
749
749
|
transfer: transferOf(m.file.id) ?? null
|
|
750
750
|
}));
|
|
751
751
|
}
|
|
752
|
+
/** A file's size as a person reads it: "40 MB", "26.2 MB". */
|
|
753
|
+
var megabytes = (size) => `${Math.round(size / 1e5) / 10} MB`;
|
|
752
754
|
/** The chat or the group a file command names (`findChatOrGroup`). */
|
|
753
755
|
var chatOrGroupOf = (ctx, params) => findChatOrGroup(state(ctx).links, state(ctx).groups, str(params, "chat", true));
|
|
754
756
|
/**
|
|
@@ -904,6 +906,24 @@ function saveName(name) {
|
|
|
904
906
|
const clean = sanitizeFileName(name);
|
|
905
907
|
return fitName(clean.startsWith("-") ? `_${clean}` : clean);
|
|
906
908
|
}
|
|
909
|
+
/**
|
|
910
|
+
* Gives the whole file at `partial` the name `target`: over a file there when `force`, else never (EEXIST). Where the
|
|
911
|
+
* file system has no hard links (exFAT, some network shares), it is copied under the name, still never over a file.
|
|
912
|
+
*/
|
|
913
|
+
async function place(partial, target, force) {
|
|
914
|
+
if (force) return rename(partial, target);
|
|
915
|
+
try {
|
|
916
|
+
await link(partial, target);
|
|
917
|
+
} catch (error) {
|
|
918
|
+
if (![
|
|
919
|
+
"EPERM",
|
|
920
|
+
"ENOTSUP",
|
|
921
|
+
"EOPNOTSUPP",
|
|
922
|
+
"ENOSYS"
|
|
923
|
+
].includes(error.code ?? "")) throw error;
|
|
924
|
+
await copyFile(partial, target, constants$1.COPYFILE_EXCL);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
907
927
|
var ACTIONS = [
|
|
908
928
|
"accept",
|
|
909
929
|
"decline",
|
|
@@ -1059,7 +1079,13 @@ var FILE_METHODS = {
|
|
|
1059
1079
|
const transfer = state(ctx).transfers[fileId];
|
|
1060
1080
|
if (!transfer || transfer.state === "done") throw new CliError("refused", outgoing ? "Nothing to send again: it arrived whole" : "Nothing to ask for: the file is all here");
|
|
1061
1081
|
if (transfer.state === "failed" && (!outgoing || !transfer.retry)) throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1062
|
-
} else
|
|
1082
|
+
} else {
|
|
1083
|
+
const outgoing = fileId.startsWith(`${linkId}-out-`);
|
|
1084
|
+
if (outgoing && (action === "accept" || action === "decline")) throw new CliError("bad_request", "A file sent from here is not accepted or declined: file cancel stops it");
|
|
1085
|
+
await refuseAllHere();
|
|
1086
|
+
const transfer = state(ctx).transfers[fileId] ?? (await fileStore.get(fileId).catch(() => void 0))?.transfer;
|
|
1087
|
+
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}${outgoing && transfer.retry ? " (file resend sends it again)" : ""}`);
|
|
1088
|
+
}
|
|
1063
1089
|
await node(ctx).fileAction({
|
|
1064
1090
|
linkId,
|
|
1065
1091
|
fileId,
|
|
@@ -1087,7 +1113,7 @@ var FILE_METHODS = {
|
|
|
1087
1113
|
}) * 1e3;
|
|
1088
1114
|
const transfer = await waitForState(ctx, (s) => {
|
|
1089
1115
|
const now = s.transfers[fileId] ?? stored?.transfer;
|
|
1090
|
-
return now && (now.state === "done" || now.state === "failed") ? now : void 0;
|
|
1116
|
+
return now && (now.state === "done" || now.state === "failed" || now.stage === "asking" && now.direction === "in") ? now : void 0;
|
|
1091
1117
|
}, ms, `file ${fileId} to arrive`).catch((error) => {
|
|
1092
1118
|
const now = state(ctx).transfers[fileId];
|
|
1093
1119
|
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${now.stage}` : ""})`, {
|
|
@@ -1103,6 +1129,15 @@ var FILE_METHODS = {
|
|
|
1103
1129
|
...where,
|
|
1104
1130
|
retry: !!transfer.retry
|
|
1105
1131
|
});
|
|
1132
|
+
if (transfer.state !== "done") {
|
|
1133
|
+
const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
|
|
1134
|
+
throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
1135
|
+
file: fileId,
|
|
1136
|
+
...where,
|
|
1137
|
+
size: transfer.size,
|
|
1138
|
+
stage: "asking"
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1106
1141
|
return {
|
|
1107
1142
|
...where,
|
|
1108
1143
|
file: fileId,
|
|
@@ -1126,22 +1161,28 @@ var FILE_METHODS = {
|
|
|
1126
1161
|
if (!stored?.metadata) throw new CliError("not_found", `No file ${fileId}`);
|
|
1127
1162
|
if (stored.leftOut) throw new CliError("not_found", "Not in this backup: the light backup this profile was restored from left the file out");
|
|
1128
1163
|
const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? stored.transfer;
|
|
1164
|
+
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1129
1165
|
if (transfer && transfer.state !== "done") throw new CliError("unavailable", `The file is not all here yet (${transfer.transferred} of ${transfer.size} bytes)`);
|
|
1130
1166
|
const named = str(params, "path") ? resolve(str(params, "path", true)) : join(resolve(str(params, "dir") ?? "."), saveName(stored.metadata.voice ? voiceDownloadName(stored.metadata.mime, await voiceTime(ctx, stored)) : stored.metadata.name));
|
|
1131
1167
|
const force = bool(params, "force");
|
|
1132
1168
|
const free = !force && !str(params, "path") && !!stored.metadata.voice;
|
|
1133
1169
|
const ext = extname(named), stem = named.slice(0, named.length - ext.length);
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1170
|
+
const taken = async (target, code) => {
|
|
1171
|
+
const there = await stat(target).catch(() => void 0);
|
|
1172
|
+
if (there?.isDirectory()) return new CliError("bad_request", `${target} is a folder: name a file, or use --dir ${target} (dir over the socket)`);
|
|
1173
|
+
if (there && !force || code === "EEXIST") return new CliError("confirm", `${target} exists: pass --force (force: true over the socket) to replace it`);
|
|
1174
|
+
};
|
|
1175
|
+
let target = named;
|
|
1176
|
+
for (let n = 2, refused = await taken(target); refused; n += 1, refused = await taken(target)) {
|
|
1177
|
+
if (!free || refused.code !== "confirm" || n > 1e3) throw refused;
|
|
1178
|
+
target = `${stem} (${n})${ext}`;
|
|
1179
|
+
}
|
|
1180
|
+
const partial = join(dirname(target), `.ghostly-save-${process.pid}-${toBase64Url(randomBytes$1(6))}.partial`);
|
|
1181
|
+
let out;
|
|
1182
|
+
try {
|
|
1183
|
+
out = await open(partial, "wx", 384);
|
|
1137
1184
|
} catch (error) {
|
|
1138
1185
|
const code = error.code;
|
|
1139
|
-
if (free && code === "EEXIST" && n <= 1e3) {
|
|
1140
|
-
target = `${stem} (${n})${ext}`;
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
if ((code === "EEXIST" || code === "EISDIR") && (await stat(target).catch(() => void 0))?.isDirectory()) throw new CliError("bad_request", `${target} is a folder: name a file, or use dir (--dir ${target})`);
|
|
1144
|
-
if (code === "EEXIST") throw new CliError("confirm", `${target} exists: pass force (--force) to replace it`);
|
|
1145
1186
|
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
1146
1187
|
const folder = dirname(target), there = await stat(folder).catch(() => void 0);
|
|
1147
1188
|
if (!there) throw new CliError("not_found", `No such file or folder: ${folder}`);
|
|
@@ -1165,10 +1206,23 @@ var FILE_METHODS = {
|
|
|
1165
1206
|
await out.write(chunk);
|
|
1166
1207
|
written = chunk.length;
|
|
1167
1208
|
} else throw new CliError("not_found", "The file's bytes are not on this device");
|
|
1168
|
-
complete = true;
|
|
1169
|
-
} finally {
|
|
1170
1209
|
await out.close();
|
|
1171
|
-
|
|
1210
|
+
out = null;
|
|
1211
|
+
for (let n = 2; !complete; n += 1) try {
|
|
1212
|
+
await place(partial, target, force);
|
|
1213
|
+
complete = true;
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
const code = error.code;
|
|
1216
|
+
const refused = code === "EEXIST" || code === "EISDIR" || code === "ENOTEMPTY" ? await taken(target, code) : void 0;
|
|
1217
|
+
if (free && refused?.code === "confirm" && n <= 1e3) {
|
|
1218
|
+
target = `${stem} (${n})${ext}`;
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
throw refused ?? error;
|
|
1222
|
+
}
|
|
1223
|
+
} finally {
|
|
1224
|
+
await out?.close();
|
|
1225
|
+
await rm(partial, { force: true });
|
|
1172
1226
|
}
|
|
1173
1227
|
return {
|
|
1174
1228
|
file: fileId,
|
|
@@ -1377,11 +1431,11 @@ async function sendCard(ctx, params, kind) {
|
|
|
1377
1431
|
}, params, now));
|
|
1378
1432
|
await parentThere(ctx, target, card);
|
|
1379
1433
|
const text = str(params, "text") ?? "";
|
|
1380
|
-
const wait = oneOf(params, "wait",
|
|
1434
|
+
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", [
|
|
1381
1435
|
"none",
|
|
1382
1436
|
"sent",
|
|
1383
1437
|
"delivered"
|
|
1384
|
-
], "none");
|
|
1438
|
+
], ctx.mode === "one-shot" ? "sent" : "none");
|
|
1385
1439
|
const ms = num(params, "timeout", 30, {
|
|
1386
1440
|
min: 1,
|
|
1387
1441
|
max: 3600
|
|
@@ -1447,7 +1501,7 @@ async function updateCard(ctx, params, kind) {
|
|
|
1447
1501
|
}), params));
|
|
1448
1502
|
if (isObject(patch) && patch.parent !== void 0) await parentThere(ctx, target, card);
|
|
1449
1503
|
const text = str(params, "text") ?? "";
|
|
1450
|
-
const wait = oneOf(params, "wait",
|
|
1504
|
+
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none");
|
|
1451
1505
|
const ms = num(params, "timeout", 30, {
|
|
1452
1506
|
min: 1,
|
|
1453
1507
|
max: 3600
|
|
@@ -1526,7 +1580,7 @@ async function reportUsage(ctx, ref, fields, params) {
|
|
|
1526
1580
|
};
|
|
1527
1581
|
checked(report);
|
|
1528
1582
|
const sent = await cardMessage(ctx, target, "usage", id).catch(() => void 0);
|
|
1529
|
-
const wait = oneOf(params, "wait", ["none", "sent"], "none");
|
|
1583
|
+
const wait = oneOf(params, "wait", ["none", "sent"], !target.group && ctx.mode === "one-shot" ? "sent" : "none");
|
|
1530
1584
|
if (!sent || (sent.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) return {
|
|
1531
1585
|
...await sendCard(ctx, {
|
|
1532
1586
|
...params,
|
|
@@ -1675,14 +1729,16 @@ async function holdChat(ctx, link, minutes) {
|
|
|
1675
1729
|
}
|
|
1676
1730
|
/**
|
|
1677
1731
|
* Ends a hold: the chat leaves DHT only, unless someone chose otherwise meanwhile. Whether there was one. `reason`:
|
|
1678
|
-
* expired, connect (`chat connect`) or lifted (`--hold 0`
|
|
1732
|
+
* expired, connect (`chat connect`) or lifted (`--hold 0`, or `chat transport`: `chosen`, the chat's transport was
|
|
1733
|
+
* just chosen, and stays as chosen).
|
|
1679
1734
|
*/
|
|
1680
|
-
async function releaseHold(ctx, linkId, reason) {
|
|
1735
|
+
async function releaseHold(ctx, linkId, reason, chosen = false) {
|
|
1681
1736
|
const holds = readHolds(ctx);
|
|
1682
1737
|
if (!holds[linkId]) return false;
|
|
1683
1738
|
clearTimeout(timersOf(ctx).get(linkId));
|
|
1684
1739
|
timersOf(ctx).delete(linkId);
|
|
1685
|
-
|
|
1740
|
+
const link = state(ctx).links.find((l) => l.id === linkId);
|
|
1741
|
+
if (!chosen && link?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
|
|
1686
1742
|
linkId,
|
|
1687
1743
|
mode: "stream"
|
|
1688
1744
|
});
|
|
@@ -1765,6 +1821,7 @@ function chatDetailsJson(link, showSecret) {
|
|
|
1765
1821
|
rttMs: link.transportRttMs ?? null,
|
|
1766
1822
|
relays: link.transportRelayed?.relays ?? null,
|
|
1767
1823
|
deliveryMode: link.deliveryMode ?? null,
|
|
1824
|
+
peerDeliveryMode: link.dhtDelivery?.peerMode ?? null,
|
|
1768
1825
|
capabilities: link.capabilities ?? null,
|
|
1769
1826
|
hold: link.hold ?? null,
|
|
1770
1827
|
peerOnline: link.peerOnline,
|
|
@@ -2009,7 +2066,7 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2009
2066
|
return view(ctx, group.id, params);
|
|
2010
2067
|
},
|
|
2011
2068
|
async "group.rename"(ctx, params) {
|
|
2012
|
-
const group = groupOf(ctx, params);
|
|
2069
|
+
const group = groupOf(ctx, params, "chat rename <chat> <name...>");
|
|
2013
2070
|
const name = groupName(str(params, "name", true));
|
|
2014
2071
|
if (!name) throw new CliError("bad_request", `A group's name is 1 to 64 characters on one line`);
|
|
2015
2072
|
await node(ctx).renameGroup({
|
|
@@ -2060,9 +2117,12 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2060
2117
|
};
|
|
2061
2118
|
//#endregion
|
|
2062
2119
|
//#region src/identities.ts
|
|
2063
|
-
/**
|
|
2120
|
+
/**
|
|
2121
|
+
* Drafts per daemon: a proof made in two steps needs the same process for both. Kept as long as the engine keeps them,
|
|
2122
|
+
* and the oldest dropped when a fifth begins as the engine drops it, so what `identity add` promises still completes.
|
|
2123
|
+
*/
|
|
2064
2124
|
var drafts = /* @__PURE__ */ new Map();
|
|
2065
|
-
var
|
|
2125
|
+
var NO_DRAFT = `No such draft here: it is kept by the daemon that made it, for ${IDENTITY_DRAFT_TTL_MS / 6e4} minutes and while fewer than 4 newer ones wait`;
|
|
2066
2126
|
function provider(id) {
|
|
2067
2127
|
const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
|
|
2068
2128
|
if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
|
|
@@ -2112,7 +2172,7 @@ function proofJson(p) {
|
|
|
2112
2172
|
};
|
|
2113
2173
|
}
|
|
2114
2174
|
function pruneDrafts(now = Date.now()) {
|
|
2115
|
-
for (const [id, draft] of drafts) if (now - draft.createdAt >
|
|
2175
|
+
for (const [id, draft] of drafts) if (now - draft.createdAt > 18e5) drafts.delete(id);
|
|
2116
2176
|
}
|
|
2117
2177
|
async function begin(ctx, p, subject, params) {
|
|
2118
2178
|
let normalized;
|
|
@@ -2169,10 +2229,11 @@ var IDENTITY_METHODS = {
|
|
|
2169
2229
|
const values = params.fields ?? {};
|
|
2170
2230
|
if (typeof values !== "object" || Array.isArray(values) || Object.values(values).some((v) => typeof v !== "string")) throw new CliError("bad_request", "fields must be an object of strings");
|
|
2171
2231
|
for (const field of signer.fields ?? []) if (!field.optional && !values[field.name]) throw new CliError("bad_request", `${signer.label} needs ${field.name} (${field.label})`);
|
|
2172
|
-
const
|
|
2232
|
+
const seconds = num(params, "timeout", 300, {
|
|
2173
2233
|
min: 5,
|
|
2174
2234
|
max: 3600
|
|
2175
|
-
})
|
|
2235
|
+
});
|
|
2236
|
+
const signal = AbortSignal.timeout(seconds * 1e3);
|
|
2176
2237
|
return {
|
|
2177
2238
|
done: true,
|
|
2178
2239
|
proof: proofJson(await signer.run({
|
|
@@ -2213,6 +2274,9 @@ var IDENTITY_METHODS = {
|
|
|
2213
2274
|
} catch {}
|
|
2214
2275
|
throw error;
|
|
2215
2276
|
}
|
|
2277
|
+
}).catch((error) => {
|
|
2278
|
+
if (!signal.aborted || error instanceof CliError) throw error;
|
|
2279
|
+
throw new CliError("timeout", `Timed out after ${seconds} s waiting for ${signer.label} to approve the ${p.label} proof: --timeout <seconds> waits longer`);
|
|
2216
2280
|
}))
|
|
2217
2281
|
};
|
|
2218
2282
|
}
|
|
@@ -2224,6 +2288,7 @@ var IDENTITY_METHODS = {
|
|
|
2224
2288
|
}
|
|
2225
2289
|
const { draftId, binding } = await begin(ctx, p, subject, params);
|
|
2226
2290
|
const statement = identityStatement(binding);
|
|
2291
|
+
while (drafts.size >= 4) drafts.delete(drafts.keys().next().value);
|
|
2227
2292
|
drafts.set(draftId, {
|
|
2228
2293
|
draftId,
|
|
2229
2294
|
provider: p.id,
|
|
@@ -2238,19 +2303,23 @@ var IDENTITY_METHODS = {
|
|
|
2238
2303
|
signer: signer.id,
|
|
2239
2304
|
statement: statement.text,
|
|
2240
2305
|
instructions: instructionsJson(signer.instructions(statement)),
|
|
2241
|
-
expiresInSeconds:
|
|
2306
|
+
expiresInSeconds: IDENTITY_DRAFT_TTL_MS / 1e3
|
|
2242
2307
|
};
|
|
2243
2308
|
},
|
|
2244
2309
|
/** Finishes a two-step proof: what the tool printed (external-tool), or nothing (publish: the engine looks it up). */
|
|
2245
2310
|
async "identity.complete"(ctx, params) {
|
|
2311
|
+
pruneDrafts();
|
|
2246
2312
|
const draft = drafts.get(str(params, "draft", true));
|
|
2247
|
-
if (!draft) throw new CliError("not_found",
|
|
2313
|
+
if (!draft) throw new CliError("not_found", NO_DRAFT);
|
|
2248
2314
|
const signer = signerOf(provider(draft.provider), draft.signer);
|
|
2249
2315
|
const statement = identityStatement(draft.binding);
|
|
2250
2316
|
let evidence;
|
|
2251
2317
|
try {
|
|
2252
|
-
if (signer.kind === "external-tool")
|
|
2253
|
-
|
|
2318
|
+
if (signer.kind === "external-tool") {
|
|
2319
|
+
const output = str(params, "evidence");
|
|
2320
|
+
if (!output?.trim()) throw new CliError("usage", `Missing what ${signer.label} printed: give it from a file (--evidence-file f) or on stdin (… | ghostly identity complete ${draft.draftId})`, { needs: "evidence" });
|
|
2321
|
+
evidence = await signer.parse(output, statement);
|
|
2322
|
+
} else if (signer.kind === "publish") evidence = await signer.evidence(statement);
|
|
2254
2323
|
else throw new CliError("bad_request", "This draft needs no completion");
|
|
2255
2324
|
} catch (error) {
|
|
2256
2325
|
if (error instanceof CliError) throw error;
|
|
@@ -2268,7 +2337,7 @@ var IDENTITY_METHODS = {
|
|
|
2268
2337
|
},
|
|
2269
2338
|
async "identity.cancel"(ctx, params) {
|
|
2270
2339
|
const draftId = str(params, "draft", true);
|
|
2271
|
-
if (!drafts.delete(draftId)) throw new CliError("not_found",
|
|
2340
|
+
if (!drafts.delete(draftId)) throw new CliError("not_found", NO_DRAFT);
|
|
2272
2341
|
await node(ctx).cancelIdentityProof({ draftId });
|
|
2273
2342
|
return { cancelled: draftId };
|
|
2274
2343
|
},
|
|
@@ -2423,7 +2492,10 @@ var nodeLocalFetch = async (request) => {
|
|
|
2423
2492
|
})() : null
|
|
2424
2493
|
};
|
|
2425
2494
|
};
|
|
2426
|
-
/**
|
|
2495
|
+
/**
|
|
2496
|
+
* Contact services open on loopback ports, by `<peer>/<service>`, while this process runs: each as soon as it starts
|
|
2497
|
+
* opening, so a second `service open` meanwhile answers the same one. A server that could not open is taken out.
|
|
2498
|
+
*/
|
|
2427
2499
|
var open$1 = /* @__PURE__ */ new Map();
|
|
2428
2500
|
var MAX_RESPONSE_BYTES = 33554432;
|
|
2429
2501
|
/** Cookie names an opened service may set and have passed back (browsers keep about 180 per host). */
|
|
@@ -2698,7 +2770,7 @@ var SERVICE_METHODS = {
|
|
|
2698
2770
|
max: 65535,
|
|
2699
2771
|
whole: true
|
|
2700
2772
|
});
|
|
2701
|
-
const already = open$1.get(key);
|
|
2773
|
+
const already = await open$1.get(key)?.catch(() => void 0);
|
|
2702
2774
|
if (already) {
|
|
2703
2775
|
const on = already.server.address().port;
|
|
2704
2776
|
if (port && port !== on) throw new CliError("busy", `That service is open here on port ${on}: ghostly service close ${link.id} ${service} first, or leave out --port`);
|
|
@@ -2710,10 +2782,13 @@ var SERVICE_METHODS = {
|
|
|
2710
2782
|
}
|
|
2711
2783
|
if (!link.peerServices?.some((s) => s.id === service)) throw new CliError("not_found", `The contact shares no service ${service} (or is not live)`);
|
|
2712
2784
|
const peer = link.peerPubKeyZ32;
|
|
2713
|
-
|
|
2785
|
+
if (open$1.has(key)) return SERVICE_METHODS["service.open"](ctx, params);
|
|
2786
|
+
const opening = openServiceServer((request) => node(ctx).request(peer, service, request), port).catch((error) => {
|
|
2787
|
+
if (open$1.get(key) === opening) open$1.delete(key);
|
|
2714
2788
|
throw portError(error, port);
|
|
2715
2789
|
});
|
|
2716
|
-
open$1.set(key,
|
|
2790
|
+
open$1.set(key, opening);
|
|
2791
|
+
const opened = await opening;
|
|
2717
2792
|
return {
|
|
2718
2793
|
chat: link.id,
|
|
2719
2794
|
service,
|
|
@@ -2722,9 +2797,10 @@ var SERVICE_METHODS = {
|
|
|
2722
2797
|
},
|
|
2723
2798
|
async "service.close"(ctx, params) {
|
|
2724
2799
|
const key = `${chatOf(ctx, params).peerPubKeyZ32}/${str(params, "service", true)}`;
|
|
2725
|
-
const
|
|
2726
|
-
if (!entry) throw new CliError("not_found", "That service is not open here");
|
|
2800
|
+
const pending = open$1.get(key);
|
|
2727
2801
|
open$1.delete(key);
|
|
2802
|
+
const entry = await pending?.catch(() => void 0);
|
|
2803
|
+
if (!entry) throw new CliError("not_found", "That service is not open here");
|
|
2728
2804
|
await new Promise((resolve) => {
|
|
2729
2805
|
entry.server.close(() => resolve());
|
|
2730
2806
|
entry.server.closeAllConnections();
|
|
@@ -2916,7 +2992,7 @@ function reportAppFrames(hub, node, profileDir) {
|
|
|
2916
2992
|
/** The chat and the served app a command names, on an engine that speaks apps/1. */
|
|
2917
2993
|
function target(ctx, params) {
|
|
2918
2994
|
const app = servedApp(servedApps(ctx.runtime.paths.dir), str(params, "ref", true));
|
|
2919
|
-
if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon
|
|
2995
|
+
if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon --detach) and open it there");
|
|
2920
2996
|
if (!ctx.runtime.apps) throw new CliError("unavailable", "This daemon started before an app was served, so it offers no apps/1 yet: ghostly daemon restart");
|
|
2921
2997
|
const link = chatOf(ctx, params);
|
|
2922
2998
|
return {
|
|
@@ -3218,6 +3294,18 @@ var WALLET_REFUSALS = [
|
|
|
3218
3294
|
[/^The faucet did not pay: This wallet has no test mint\b/, "unavailable"],
|
|
3219
3295
|
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"]
|
|
3220
3296
|
];
|
|
3297
|
+
/**
|
|
3298
|
+
* `chat pay` or `chat request` refused for want of a Cashu wallet of that network at all: the engine says the wallet
|
|
3299
|
+
* is short of sats, or that no mint could make an invoice, and names nothing to do. `refused` with the command that
|
|
3300
|
+
* makes one, as a contact with no wallet is told; `details.reason` `no_wallet`. With a wallet, the engine's own words.
|
|
3301
|
+
*/
|
|
3302
|
+
function noWalletOf(ctx, n, error) {
|
|
3303
|
+
if ((state(ctx).wallet.wallets ?? []).some((w) => w.type === "cashu" && w.network === n)) return error;
|
|
3304
|
+
return new CliError("refused", `You have no ${n === "mainnet" ? "Mainnet" : "Testnet"} Cashu wallet: ghostly wallet create cashu${n === "mainnet" ? " --network mainnet" : ""}`, { reason: "no_wallet" });
|
|
3305
|
+
}
|
|
3306
|
+
var engineCode = (error) => error instanceof Error ? error.engineCode : void 0;
|
|
3307
|
+
/** What the engine says to a Cashu request it has no mint for: no mint for the invoice, or none to name for ecash. */
|
|
3308
|
+
var NO_MINT = /^(No mint could create an invoice: No mint configured|You have no (Mainnet|Testnet) Cashu wallet: create one in Wallet → New)$/;
|
|
3221
3309
|
function walletRefusal(error) {
|
|
3222
3310
|
if (!(error instanceof Error) || error instanceof CliError) return error;
|
|
3223
3311
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
@@ -3460,6 +3548,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3460
3548
|
network: n,
|
|
3461
3549
|
...memo ? { memo } : {},
|
|
3462
3550
|
...real(params)
|
|
3551
|
+
}).catch((error) => {
|
|
3552
|
+
throw engineCode(error) === "notEnoughSats" ? noWalletOf(ctx, n, error) : error;
|
|
3463
3553
|
});
|
|
3464
3554
|
return {
|
|
3465
3555
|
chat: link.id,
|
|
@@ -3475,15 +3565,18 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3475
3565
|
const method = params.method === void 0 ? void 0 : oneOf(params, "method", PAY_METHODS, "cashu");
|
|
3476
3566
|
const rail = params.rail === void 0 ? void 0 : oneOf(params, "rail", ["cashu", "lightning"], "cashu");
|
|
3477
3567
|
await federationsOpen(ctx);
|
|
3568
|
+
const n = network(params);
|
|
3478
3569
|
const { paymentId } = await node(ctx).requestPayment({
|
|
3479
3570
|
linkId: link.id,
|
|
3480
3571
|
amount,
|
|
3481
3572
|
timestamp: sentAt(),
|
|
3482
|
-
network:
|
|
3573
|
+
network: n,
|
|
3483
3574
|
...memo ? { memo } : {},
|
|
3484
3575
|
...method ? { method } : {},
|
|
3485
3576
|
...rail ? { rail } : {},
|
|
3486
3577
|
...str(params, "card") ? { card: str(params, "card") } : {}
|
|
3578
|
+
}).catch((error) => {
|
|
3579
|
+
throw (!method || method === "cashu") && error instanceof Error && NO_MINT.test(error.message) ? noWalletOf(ctx, n, error) : error;
|
|
3487
3580
|
});
|
|
3488
3581
|
return {
|
|
3489
3582
|
chat: link.id,
|
|
@@ -3697,6 +3790,16 @@ function mentionsFor(text, refs, group) {
|
|
|
3697
3790
|
/** Per host: stops watching the invite it marked as the chat on screen. */
|
|
3698
3791
|
var inviteShown = /* @__PURE__ */ new WeakMap();
|
|
3699
3792
|
/**
|
|
3793
|
+
* Refuses DHT only (a hold, `chat transport dht`) while a call is on in the chat. A call's signals cross the live
|
|
3794
|
+
* link: off it, the call talked on over its own connection, and a hang-up from either side never reached the other
|
|
3795
|
+
* (that call ended only when its media stalled out, 16 s later). Removing the chat (`chat remove`) is refused the same
|
|
3796
|
+
* way: the call talked on in a chat gone from this device, and its hang-up had no chat left to cross.
|
|
3797
|
+
*/
|
|
3798
|
+
function noCallOn(ctx, linkId, then) {
|
|
3799
|
+
const call = ctx.calls.list().find((c) => c.chat === linkId);
|
|
3800
|
+
if (call) throw new CliError("busy", `A call is on in this chat: hang it up first (ghostly call hangup ${linkId}), then ${then}`, { call: call.call });
|
|
3801
|
+
}
|
|
3802
|
+
/**
|
|
3700
3803
|
* Marks a new invite as the chat on screen (native listeners, the quick pace) only until it is paired: a paired chat
|
|
3701
3804
|
* keeps its listeners anyway, and a daemon nobody looks at reads an away contact at the background pace, as its
|
|
3702
3805
|
* other chats and the same chat after a restart do. Nor past its wait for a peer (`AWAITING_PEER_MS`): an invite
|
|
@@ -3760,7 +3863,8 @@ var METHODS = {
|
|
|
3760
3863
|
protocol: s.transport.protocol,
|
|
3761
3864
|
relays: s.transport.relays
|
|
3762
3865
|
},
|
|
3763
|
-
events: { lastSeq: ctx.hub.lastSeq }
|
|
3866
|
+
events: { lastSeq: ctx.hub.lastSeq },
|
|
3867
|
+
...ctx.listen && { listen: true }
|
|
3764
3868
|
};
|
|
3765
3869
|
},
|
|
3766
3870
|
async "profile.get"(ctx) {
|
|
@@ -3833,13 +3937,19 @@ var METHODS = {
|
|
|
3833
3937
|
return p && (p.stage !== "publishing" || ctx.mode === "daemon" && p.relayWaitUntil) ? p : void 0;
|
|
3834
3938
|
}, 2e4, "the invite to be published").catch(() => progressOf(state(ctx)));
|
|
3835
3939
|
const published = !!progress && progress.stage !== "publishing" && progress.reason !== "publish";
|
|
3836
|
-
const
|
|
3837
|
-
return {
|
|
3940
|
+
const answer = {
|
|
3838
3941
|
chat: linkId,
|
|
3839
3942
|
invite: inviteCode,
|
|
3840
3943
|
link: inviteLink(inviteCode),
|
|
3841
|
-
published
|
|
3842
|
-
|
|
3944
|
+
published
|
|
3945
|
+
};
|
|
3946
|
+
if (published) return answer;
|
|
3947
|
+
const waitUntil = progress?.relayWaitUntil;
|
|
3948
|
+
return {
|
|
3949
|
+
...answer,
|
|
3950
|
+
...waitUntil !== void 0 && { retryInMs: Math.max(0, waitUntil - Date.now()) },
|
|
3951
|
+
...progress?.detail && { reason: progress.detail },
|
|
3952
|
+
note: "The invite is good: it goes out by itself once a relay answers, while a daemon runs for this profile"
|
|
3843
3953
|
};
|
|
3844
3954
|
},
|
|
3845
3955
|
async "invite.join"(ctx, params) {
|
|
@@ -3993,32 +4103,53 @@ var METHODS = {
|
|
|
3993
4103
|
...until ? { until } : {}
|
|
3994
4104
|
};
|
|
3995
4105
|
},
|
|
3996
|
-
/**
|
|
4106
|
+
/**
|
|
4107
|
+
* WISP 400 § Reactions: one emoji per person per message, a new one replaces mine; `remove` takes mine back.
|
|
4108
|
+
* `wait: confirmed` (a one-shot's default) stays until the contact confirmed it; `confirmed` says whether it has.
|
|
4109
|
+
*/
|
|
3997
4110
|
async "chat.react"(ctx, params) {
|
|
3998
4111
|
const link = chatNotGroup(ctx, params, "group react", "<message> <emoji>");
|
|
4112
|
+
const { wait, ms } = confirmWait(ctx, params);
|
|
4113
|
+
const before = Math.max(...node(ctx).chatUnconfirmed({ linkId: link.id }).reactions);
|
|
4114
|
+
const result = await react(ctx, link.id, params);
|
|
4115
|
+
const pending = (left) => left.reactions.some((n) => n > before);
|
|
4116
|
+
if (wait === "confirmed") await waitForConfirmed(ctx, link.id, "reaction", pending, ms);
|
|
3999
4117
|
return {
|
|
4000
4118
|
chat: link.id,
|
|
4001
|
-
...
|
|
4119
|
+
...result,
|
|
4120
|
+
confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: link.id }))
|
|
4002
4121
|
};
|
|
4003
4122
|
},
|
|
4004
4123
|
/**
|
|
4005
4124
|
* WISP 400 § Pinned message: one per chat or group, a new pin replaces it; `remove` unpins. In a community only the
|
|
4006
|
-
* admin pins. Answers the chat (or group) and the message now pinned (null once unpinned).
|
|
4125
|
+
* admin pins. Answers the chat (or group) and the message now pinned (null once unpinned). In a 1:1 chat `wait:
|
|
4126
|
+
* confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has.
|
|
4007
4127
|
*/
|
|
4008
4128
|
async "chat.pin"(ctx, params) {
|
|
4009
4129
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4010
4130
|
const remove = bool(params, "remove"), messageId = remove ? str(params, "message") : str(params, "message", true);
|
|
4131
|
+
if (target.group && params.wait === "confirmed") throw new CliError("bad_request", "A group has no receipts: wait confirmed is for a 1:1 chat");
|
|
4132
|
+
const { wait, ms } = confirmWait(ctx, params);
|
|
4011
4133
|
const result = await node(ctx).pinMessage({
|
|
4012
4134
|
linkId: target.linkId,
|
|
4013
4135
|
...messageId && { messageId },
|
|
4014
4136
|
remove
|
|
4015
4137
|
});
|
|
4016
|
-
if (result.error) throw new CliError(
|
|
4017
|
-
return {
|
|
4018
|
-
|
|
4138
|
+
if (result.error) throw new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this chat|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
|
|
4139
|
+
if (target.group) return {
|
|
4140
|
+
group: target.id,
|
|
4019
4141
|
messageId: remove ? null : messageId,
|
|
4020
4142
|
removed: remove
|
|
4021
4143
|
};
|
|
4144
|
+
const mine = node(ctx).chatUnconfirmed({ linkId: target.linkId }).pin;
|
|
4145
|
+
const pending = (left) => mine !== null && left.pin === mine;
|
|
4146
|
+
if (wait === "confirmed") await waitForConfirmed(ctx, target.linkId, "pin", pending, ms);
|
|
4147
|
+
return {
|
|
4148
|
+
chat: target.id,
|
|
4149
|
+
messageId: remove ? null : messageId,
|
|
4150
|
+
removed: remove,
|
|
4151
|
+
confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: target.linkId }))
|
|
4152
|
+
};
|
|
4022
4153
|
},
|
|
4023
4154
|
/** Saved messages: a mark on a message of a chat or a group, kept for this profile on this device; nothing is sent. */
|
|
4024
4155
|
async "saved.add"(ctx, params) {
|
|
@@ -4031,10 +4162,10 @@ var METHODS = {
|
|
|
4031
4162
|
async "saved.list"(ctx) {
|
|
4032
4163
|
const { links, groups } = state(ctx);
|
|
4033
4164
|
const saved = await node(ctx).savedMessages();
|
|
4034
|
-
const
|
|
4035
|
-
for (const linkId of new Set(saved.map((s) => s.message.linkId)))
|
|
4165
|
+
const originals = /* @__PURE__ */ new Map();
|
|
4166
|
+
for (const linkId of new Set(saved.map((s) => s.message.linkId))) originals.set(linkId, await originalsNow(ctx, linkId, saved.flatMap((s) => s.message.linkId === linkId ? [s.message] : [])));
|
|
4036
4167
|
return saved.map(({ savedAt, message }) => {
|
|
4037
|
-
const checked = (json) => quoteChecked(json, message,
|
|
4168
|
+
const checked = (json) => quoteChecked(json, message, originals.get(message.linkId));
|
|
4038
4169
|
if (!message.linkId.startsWith("group:")) return {
|
|
4039
4170
|
chat: message.linkId,
|
|
4040
4171
|
savedAt,
|
|
@@ -4119,7 +4250,7 @@ var METHODS = {
|
|
|
4119
4250
|
};
|
|
4120
4251
|
},
|
|
4121
4252
|
async "chat.retry"(ctx, params) {
|
|
4122
|
-
const link = chatOf(ctx, params);
|
|
4253
|
+
const link = notAGroup(ctx, params, () => chatOf(ctx, params), () => "a group's message is not sent again by hand, it goes by itself when a member's edge opens");
|
|
4123
4254
|
const messageId = str(params, "message", true);
|
|
4124
4255
|
const message = await node(ctx).getMessage(link.id, messageId);
|
|
4125
4256
|
if (!message) throw new CliError("not_found", `No message ${messageId} in this chat`);
|
|
@@ -4137,6 +4268,12 @@ var METHODS = {
|
|
|
4137
4268
|
async "chat.delete"(ctx, params) {
|
|
4138
4269
|
if (bool(params, "everyone")) {
|
|
4139
4270
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4271
|
+
const wait = oneOf(params, "wait", ["none", "confirmed"], !target.group && ctx.mode === "one-shot" ? "confirmed" : "none");
|
|
4272
|
+
if (target.group && wait !== "none") throw new CliError("bad_request", "A group has no receipts: --wait confirmed is for a chat");
|
|
4273
|
+
const ms = num(params, "timeout", 30, {
|
|
4274
|
+
min: 1,
|
|
4275
|
+
max: 3600
|
|
4276
|
+
}) * 1e3;
|
|
4140
4277
|
const ref = str(params, "message", true);
|
|
4141
4278
|
const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
|
|
4142
4279
|
if (!message) throw new CliError("not_found", `No message ${ref} of yours in this ${target.group ? "group" : "chat"}: only your own messages are deleted for everyone`);
|
|
@@ -4145,12 +4282,23 @@ var METHODS = {
|
|
|
4145
4282
|
messageId: message.id
|
|
4146
4283
|
});
|
|
4147
4284
|
if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
|
|
4148
|
-
return {
|
|
4149
|
-
|
|
4285
|
+
if (target.group) return {
|
|
4286
|
+
group: target.id,
|
|
4150
4287
|
messageId: message.id,
|
|
4151
4288
|
deleted: message.id,
|
|
4152
4289
|
everyone: true
|
|
4153
4290
|
};
|
|
4291
|
+
if (wait === "confirmed") await waitForRemoval(ctx, target.linkId, message.id, ms);
|
|
4292
|
+
return {
|
|
4293
|
+
chat: target.id,
|
|
4294
|
+
messageId: message.id,
|
|
4295
|
+
deleted: message.id,
|
|
4296
|
+
everyone: true,
|
|
4297
|
+
confirmed: !node(ctx).removalPending({
|
|
4298
|
+
linkId: target.linkId,
|
|
4299
|
+
messageId: message.id
|
|
4300
|
+
})
|
|
4301
|
+
};
|
|
4154
4302
|
}
|
|
4155
4303
|
const ref = str(params, "message") ?? "<message>";
|
|
4156
4304
|
const link = chatNotGroup(ctx, params, "message delete", `${/^[\w.:<>-]+$/.test(ref) ? ref : JSON.stringify(ref)} --everyone`);
|
|
@@ -4167,13 +4315,14 @@ var METHODS = {
|
|
|
4167
4315
|
everyone: false
|
|
4168
4316
|
};
|
|
4169
4317
|
},
|
|
4318
|
+
/** A chat's or a group's (`group:<id>`, or its name) message, as the app's details show it; a group's said `No chat`. */
|
|
4170
4319
|
async "chat.details"(ctx, params) {
|
|
4171
|
-
const
|
|
4320
|
+
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4172
4321
|
const details = await node(ctx).messageDetails({
|
|
4173
|
-
linkId:
|
|
4322
|
+
linkId: target.linkId,
|
|
4174
4323
|
messageId: str(params, "message", true)
|
|
4175
4324
|
});
|
|
4176
|
-
if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this chat`);
|
|
4325
|
+
if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this ${target.group ? "group" : "chat"}`);
|
|
4177
4326
|
return details;
|
|
4178
4327
|
},
|
|
4179
4328
|
async "chat.rename"(ctx, params) {
|
|
@@ -4186,8 +4335,10 @@ var METHODS = {
|
|
|
4186
4335
|
},
|
|
4187
4336
|
async "chat.remove"(ctx, params) {
|
|
4188
4337
|
const link = chatNotGroup(ctx, params, "group forget", "--yes");
|
|
4189
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Removing a chat deletes its keys and history on this device; pass yes (
|
|
4338
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Removing a chat deletes its keys and history on this device; pass --yes (yes: true over the socket) to go on");
|
|
4339
|
+
noCallOn(ctx, link.id, "remove the chat");
|
|
4190
4340
|
await node(ctx).removeLink({ linkId: link.id });
|
|
4341
|
+
ctx.calls.forgetChat(link.id);
|
|
4191
4342
|
return { removed: link.id };
|
|
4192
4343
|
},
|
|
4193
4344
|
async "chat.transport"(ctx, params) {
|
|
@@ -4195,10 +4346,13 @@ var METHODS = {
|
|
|
4195
4346
|
const name = str(params, "transport", true);
|
|
4196
4347
|
const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
|
|
4197
4348
|
if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
|
|
4349
|
+
if (transport === "dht") noCallOn(ctx, link.id, "put the chat on DHT only");
|
|
4350
|
+
else if (transport !== "auto") transportOffered(link, transport);
|
|
4198
4351
|
await node(ctx).setChatTransport({
|
|
4199
4352
|
linkId: link.id,
|
|
4200
4353
|
transport
|
|
4201
4354
|
});
|
|
4355
|
+
await releaseHold(ctx, link.id, "lifted", true);
|
|
4202
4356
|
return chatDetailsJson(findChat(state(ctx).links, link.id));
|
|
4203
4357
|
},
|
|
4204
4358
|
/** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
|
|
@@ -4206,7 +4360,11 @@ var METHODS = {
|
|
|
4206
4360
|
const link = chatOf(ctx, params);
|
|
4207
4361
|
await releaseHold(ctx, link.id, "connect");
|
|
4208
4362
|
inviteTaken(link);
|
|
4209
|
-
|
|
4363
|
+
dhtOnly(findChat(state(ctx).links, link.id));
|
|
4364
|
+
await connectWithin(ctx, link, num(params, "timeout", CONNECT_MAX_SECONDS, {
|
|
4365
|
+
min: 1,
|
|
4366
|
+
max: CONNECT_MAX_SECONDS
|
|
4367
|
+
}) * 1e3);
|
|
4210
4368
|
return chatJson(findChat(state(ctx).links, link.id));
|
|
4211
4369
|
},
|
|
4212
4370
|
/**
|
|
@@ -4223,6 +4381,7 @@ var METHODS = {
|
|
|
4223
4381
|
min: 0,
|
|
4224
4382
|
max: HOLD_MAX_MINUTES
|
|
4225
4383
|
});
|
|
4384
|
+
if (minutes > 0) noCallOn(ctx, link.id, "hold the chat");
|
|
4226
4385
|
if (minutes === 0) await releaseHold(ctx, link.id, "lifted");
|
|
4227
4386
|
else await holdChat(ctx, link, minutes);
|
|
4228
4387
|
return {
|
|
@@ -4289,14 +4448,14 @@ var METHODS = {
|
|
|
4289
4448
|
return { groups: state(ctx).groups.map((g) => groupJson(g, showSecret)).sort((a, b) => b.lastMessageAt - a.lastMessageAt) };
|
|
4290
4449
|
},
|
|
4291
4450
|
async "group.get"(ctx, params) {
|
|
4292
|
-
return groupJson(groupOf(ctx, params), bool(params, "showSecret"));
|
|
4451
|
+
return groupJson(groupOf(ctx, params, "chat show <chat>"), bool(params, "showSecret"));
|
|
4293
4452
|
},
|
|
4294
4453
|
async "group.history"(ctx, params) {
|
|
4295
|
-
const group = groupOf(ctx, params);
|
|
4454
|
+
const group = groupOf(ctx, params, "chat history <chat>");
|
|
4296
4455
|
return historyOf(ctx, `group:${group.id}`, params, (m) => groupMessageJson(m, group));
|
|
4297
4456
|
},
|
|
4298
4457
|
async "group.send"(ctx, params) {
|
|
4299
|
-
const group = groupOf(ctx, params);
|
|
4458
|
+
const group = groupOf(ctx, params, "send <chat> [text...]");
|
|
4300
4459
|
const text = str(params, "text", true);
|
|
4301
4460
|
checkTextSize(text);
|
|
4302
4461
|
if (!bool(params, "force")) {
|
|
@@ -4339,10 +4498,10 @@ var METHODS = {
|
|
|
4339
4498
|
/**
|
|
4340
4499
|
* WISP 902 § Edits: the whole new text of one of my messages in a group. It shows here at once and goes to the members
|
|
4341
4500
|
* (a private group's over the edges that are up, the others when theirs open; a community's through the group).
|
|
4342
|
-
* `mentions`: members the new text names beyond those the message named. `sent`:
|
|
4501
|
+
* `mentions`: members the new text names beyond those the message named. `sent`: whether an edge took it, as for group send.
|
|
4343
4502
|
*/
|
|
4344
4503
|
async "group.edit"(ctx, params) {
|
|
4345
|
-
const group = groupOf(ctx, params);
|
|
4504
|
+
const group = groupOf(ctx, params, "edit <chat> <message> <text...>");
|
|
4346
4505
|
const messageId = str(params, "message", true);
|
|
4347
4506
|
const text = str(params, "text", true);
|
|
4348
4507
|
if (!bool(params, "force")) {
|
|
@@ -4364,8 +4523,7 @@ var METHODS = {
|
|
|
4364
4523
|
...mentions.length ? { mentions } : {}
|
|
4365
4524
|
});
|
|
4366
4525
|
if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId, "group", result.error, result.refused);
|
|
4367
|
-
const
|
|
4368
|
-
const edits = message?.edit?.seq ?? 0;
|
|
4526
|
+
const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
|
|
4369
4527
|
if (edits === before) return {
|
|
4370
4528
|
group: group.id,
|
|
4371
4529
|
messageId,
|
|
@@ -4383,12 +4541,12 @@ var METHODS = {
|
|
|
4383
4541
|
group: group.id,
|
|
4384
4542
|
messageId,
|
|
4385
4543
|
edits,
|
|
4386
|
-
sent: edges > 0
|
|
4544
|
+
sent: edges > 0,
|
|
4387
4545
|
edges
|
|
4388
4546
|
};
|
|
4389
4547
|
},
|
|
4390
4548
|
async "group.react"(ctx, params) {
|
|
4391
|
-
const group = groupOf(ctx, params);
|
|
4549
|
+
const group = groupOf(ctx, params, "react <chat> <message> <emoji>");
|
|
4392
4550
|
return {
|
|
4393
4551
|
group: group.id,
|
|
4394
4552
|
...await react(ctx, `group:${group.id}`, params)
|
|
@@ -4399,7 +4557,7 @@ var METHODS = {
|
|
|
4399
4557
|
* how many members), with the same kinds, status rules, 6 s hold and `for`. A community does not carry typing yet.
|
|
4400
4558
|
*/
|
|
4401
4559
|
async "group.typing"(ctx, params) {
|
|
4402
|
-
const group = groupOf(ctx, params);
|
|
4560
|
+
const group = groupOf(ctx, params, "typing <chat>");
|
|
4403
4561
|
if (group.profile !== "mesh") throw new CliError("unavailable", "A community does not carry typing yet: only a private group does");
|
|
4404
4562
|
const typing = !bool(params, "stop");
|
|
4405
4563
|
const { kind, status } = typingWord(params, typing);
|
|
@@ -4412,7 +4570,7 @@ var METHODS = {
|
|
|
4412
4570
|
max: 600
|
|
4413
4571
|
});
|
|
4414
4572
|
if (!typing && seconds) throw new CliError("bad_request", "for keeps typing on: not with stop");
|
|
4415
|
-
if (typing && group.status !== "active") throw new CliError("
|
|
4573
|
+
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? "You are not in this group");
|
|
4416
4574
|
const target = { groupId: group.id };
|
|
4417
4575
|
endTyping(ctx, target, false);
|
|
4418
4576
|
sayTyping(ctx, target, typing, word);
|
|
@@ -4432,7 +4590,7 @@ var METHODS = {
|
|
|
4432
4590
|
},
|
|
4433
4591
|
async "group.leave"(ctx, params) {
|
|
4434
4592
|
const group = groupOf(ctx, params);
|
|
4435
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass yes (
|
|
4593
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass --yes (yes: true over the socket) to go on");
|
|
4436
4594
|
const { admin } = await node(ctx).leaveGroup({ groupId: group.id });
|
|
4437
4595
|
const next = admin ? group.members.find((m) => m.key === admin) : void 0;
|
|
4438
4596
|
return {
|
|
@@ -4444,8 +4602,8 @@ var METHODS = {
|
|
|
4444
4602
|
};
|
|
4445
4603
|
},
|
|
4446
4604
|
async "group.forget"(ctx, params) {
|
|
4447
|
-
const group = groupOf(ctx, params);
|
|
4448
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass yes (
|
|
4605
|
+
const group = groupOf(ctx, params, "chat remove <chat> --yes");
|
|
4606
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass --yes (yes: true over the socket) to go on");
|
|
4449
4607
|
await node(ctx).forgetGroup({ groupId: group.id });
|
|
4450
4608
|
return { forgotten: group.id };
|
|
4451
4609
|
},
|
|
@@ -4470,7 +4628,8 @@ var METHODS = {
|
|
|
4470
4628
|
setTimeout(() => ctx.stop(), 10);
|
|
4471
4629
|
return {
|
|
4472
4630
|
stopping: true,
|
|
4473
|
-
pid: process.pid
|
|
4631
|
+
pid: process.pid,
|
|
4632
|
+
...ctx.listen && { listen: true }
|
|
4474
4633
|
};
|
|
4475
4634
|
},
|
|
4476
4635
|
async "engine.call"(ctx, params) {
|
|
@@ -4498,7 +4657,9 @@ var METHODS = {
|
|
|
4498
4657
|
const target = node(ctx)[method];
|
|
4499
4658
|
if (typeof target !== "function") throw new CliError("not_found", `The engine has no call ${method}`);
|
|
4500
4659
|
try {
|
|
4501
|
-
|
|
4660
|
+
const result = await target.call(node(ctx), args) ?? null;
|
|
4661
|
+
if (method === "removeLink") ctx.calls.forgetChat(str(args ?? {}, "linkId", true));
|
|
4662
|
+
return result;
|
|
4502
4663
|
} catch (error) {
|
|
4503
4664
|
if (error instanceof TypeError && BAD_VALUE.test(error.message)) throw wrong("a parameter of the wrong kind", error.message);
|
|
4504
4665
|
throw error;
|
|
@@ -4561,6 +4722,19 @@ async function guardEngineSend(ctx, method, args) {
|
|
|
4561
4722
|
const secret = secretIn(texts);
|
|
4562
4723
|
if (secret) throw new CliError("confirm", `The text looks like ${secret.kind === "cashu" ? "a Cashu token (money anyone who reads it can take)" : "a secret (a seed or a private key)"}; call ${method} with --force if you mean to`, { kind: secret.kind });
|
|
4563
4724
|
}
|
|
4725
|
+
/**
|
|
4726
|
+
* How long `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed (as `edit`), since what
|
|
4727
|
+
* is not said yet leaves with the process; a daemon goes on saying it, so it answers at once unless asked to wait.
|
|
4728
|
+
*/
|
|
4729
|
+
function confirmWait(ctx, params) {
|
|
4730
|
+
return {
|
|
4731
|
+
wait: oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none"),
|
|
4732
|
+
ms: num(params, "timeout", 30, {
|
|
4733
|
+
min: 1,
|
|
4734
|
+
max: 3600
|
|
4735
|
+
}) * 1e3
|
|
4736
|
+
};
|
|
4737
|
+
}
|
|
4564
4738
|
/** Reacts to a message of a chat or a group (`group:<id>`): `emoji`, or `remove` for "" (WISP 400 § Reactions). */
|
|
4565
4739
|
async function react(ctx, linkId, params) {
|
|
4566
4740
|
const messageId = str(params, "message", true);
|
|
@@ -4609,28 +4783,31 @@ function groupSendRefused(error) {
|
|
|
4609
4783
|
return new CliError("unavailable", error);
|
|
4610
4784
|
}
|
|
4611
4785
|
/**
|
|
4612
|
-
* A chat command given a group's id, prefix or name: `not_found` that says it is a group, with the group
|
|
4613
|
-
* takes it (`react` on a group, where `group react` is meant)
|
|
4786
|
+
* A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
|
|
4787
|
+
* command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
|
|
4788
|
+
* the form `pin` and `saved` take, is that group too (it read "No chat" before). A name no chat and no group has stays
|
|
4789
|
+
* the chat's error.
|
|
4614
4790
|
*/
|
|
4615
|
-
function notAGroup(ctx, params, chat,
|
|
4791
|
+
function notAGroup(ctx, params, chat, hint) {
|
|
4616
4792
|
try {
|
|
4617
4793
|
return chat();
|
|
4618
4794
|
} catch (error) {
|
|
4619
4795
|
if (!(error instanceof CliError) || error.code !== "not_found") throw error;
|
|
4620
4796
|
const ref = str(params, "chat", true);
|
|
4797
|
+
const named = ref.startsWith("group:") ? ref.slice(6) : ref;
|
|
4621
4798
|
let group;
|
|
4622
4799
|
try {
|
|
4623
|
-
group = findGroup(state(ctx).groups,
|
|
4800
|
+
group = findGroup(state(ctx).groups, named);
|
|
4624
4801
|
} catch {
|
|
4625
4802
|
throw error;
|
|
4626
4803
|
}
|
|
4627
|
-
const shown = /^[\w.:-]+$/.test(
|
|
4628
|
-
throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat:
|
|
4804
|
+
const shown = /^[\w.:-]+$/.test(named) ? named : JSON.stringify(named);
|
|
4805
|
+
throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ${hint(shown)}`, { group: group.id });
|
|
4629
4806
|
}
|
|
4630
4807
|
}
|
|
4631
4808
|
/** The chat a chat command with a group twin names: a group's name says so, with `command`, the twin (see `notAGroup`). */
|
|
4632
4809
|
function chatNotGroup(ctx, params, command, rest = "") {
|
|
4633
|
-
return notAGroup(ctx, params, () => chatOf(ctx, params), command
|
|
4810
|
+
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
|
|
4634
4811
|
}
|
|
4635
4812
|
/**
|
|
4636
4813
|
* An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), naming the id
|
|
@@ -4641,10 +4818,29 @@ function editRefused(message, ref, where, error, refused) {
|
|
|
4641
4818
|
if (refused && !message) return new CliError("not_found", `No message ${JSON.stringify(ref)} in this ${where}: give the messageId ${where === "group" ? "group send" : "send"} printed`);
|
|
4642
4819
|
return new CliError(refused ? "refused" : "unavailable", error);
|
|
4643
4820
|
}
|
|
4821
|
+
/** The chat link's own wait for a contact (`GhostLink.connect`): `chat connect --timeout` waits at most that long. */
|
|
4822
|
+
var CONNECT_MAX_SECONDS = 90;
|
|
4644
4823
|
/**
|
|
4645
|
-
*
|
|
4646
|
-
*
|
|
4824
|
+
* `chat connect`, waiting at most `ms` for the contact; the link's dial goes on behind a shorter wait. Timed out (here,
|
|
4825
|
+
* or by the link's own 90 s), it says what happens next: before, it waited a fixed 90 s and ended "Timed out connecting
|
|
4826
|
+
* to the peer", with no next step.
|
|
4647
4827
|
*/
|
|
4828
|
+
async function connectWithin(ctx, link, ms) {
|
|
4829
|
+
const dial = node(ctx).connect({ linkId: link.id });
|
|
4830
|
+
let timer;
|
|
4831
|
+
const late = new Promise((resolve) => {
|
|
4832
|
+
timer = setTimeout(() => resolve("late"), ms);
|
|
4833
|
+
});
|
|
4834
|
+
try {
|
|
4835
|
+
if (await Promise.race([dial, late]) !== "late") return;
|
|
4836
|
+
} catch (error) {
|
|
4837
|
+
if (asCliError(error).code !== "timeout") throw error;
|
|
4838
|
+
} finally {
|
|
4839
|
+
clearTimeout(timer);
|
|
4840
|
+
}
|
|
4841
|
+
const shown = /^[\w.:-]+$/.test(link.label ?? "") ? link.label : link.id;
|
|
4842
|
+
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact did not answer. ${ctx.mode === "one-shot" ? "Try again later, or keep this profile online with `ghostly daemon --detach`: it reconnects by itself" : `It reconnects by itself while this profile is online; ghostly chat wait ${shown} --until live waits for it`}`, { chat: link.id });
|
|
4843
|
+
}
|
|
4648
4844
|
async function saveMark(ctx, params, remove) {
|
|
4649
4845
|
const target = chatOrGroup(ctx, str(params, "chat", true)), messageId = str(params, "message", true);
|
|
4650
4846
|
const result = await node(ctx).saveMessage({
|
|
@@ -4660,57 +4856,63 @@ async function saveMark(ctx, params, remove) {
|
|
|
4660
4856
|
saved: !remove
|
|
4661
4857
|
};
|
|
4662
4858
|
}
|
|
4859
|
+
/**
|
|
4860
|
+
* A page of a chat's or a group's history: only that page is read from the store (the newest, those before `before`,
|
|
4861
|
+
* or the oldest after `after`), so a long chat's is as quick as a short one's.
|
|
4862
|
+
*/
|
|
4663
4863
|
async function historyOf(ctx, chat, params, json = messageJson) {
|
|
4664
|
-
if (params.after !== void 0 && params.after !== null) {
|
|
4665
|
-
const whole = await node(ctx).getMessages(chat), { messages, more } = history(whole, params);
|
|
4666
|
-
const gone = await originalsGone(ctx, chat, messages, whole);
|
|
4667
|
-
return {
|
|
4668
|
-
messages: messages.map((m) => quoteChecked(json(m), m, gone)),
|
|
4669
|
-
more
|
|
4670
|
-
};
|
|
4671
|
-
}
|
|
4672
4864
|
const limit = num(params, "limit", 50, {
|
|
4673
4865
|
min: 1,
|
|
4674
4866
|
max: 1e4,
|
|
4675
4867
|
whole: true
|
|
4676
4868
|
});
|
|
4677
|
-
const
|
|
4678
|
-
|
|
4869
|
+
const bound = (side) => {
|
|
4870
|
+
const value = params[side] ?? void 0;
|
|
4871
|
+
if (value !== void 0 && typeof value !== "number" && typeof value !== "string") throw new CliError("bad_request", `${side} must be a timestamp or a message id`);
|
|
4872
|
+
return value;
|
|
4873
|
+
};
|
|
4874
|
+
const before = bound("before"), after = bound("after");
|
|
4679
4875
|
const page = await node(ctx).messagePage({
|
|
4680
4876
|
linkId: chat,
|
|
4681
4877
|
limit,
|
|
4682
|
-
before
|
|
4878
|
+
before,
|
|
4879
|
+
...after !== void 0 && { after }
|
|
4683
4880
|
}).catch((error) => {
|
|
4684
|
-
throw error instanceof Error && error.message === `No message ${
|
|
4881
|
+
throw error instanceof Error && [before, after].some((id) => error.message === `No message ${id}`) ? new CliError("not_found", error.message) : error;
|
|
4685
4882
|
});
|
|
4686
|
-
const
|
|
4883
|
+
const originals = await originalsNow(ctx, chat, page.messages);
|
|
4687
4884
|
return {
|
|
4688
|
-
messages: page.messages.map((m) => quoteChecked(json(m), m,
|
|
4885
|
+
messages: page.messages.map((m) => quoteChecked(json(m), m, originals)),
|
|
4689
4886
|
more: page.more
|
|
4690
4887
|
};
|
|
4691
4888
|
}
|
|
4692
4889
|
/** Past this many originals outside a page, its history is read once instead of row by row. */
|
|
4693
4890
|
var ORIGINAL_READS = 32;
|
|
4694
4891
|
/**
|
|
4695
|
-
* The originals a page's replies found here when they came
|
|
4696
|
-
* by their author
|
|
4697
|
-
* a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the
|
|
4698
|
-
* already. Before, such a reply still said `found`, with the original's text.
|
|
4892
|
+
* The originals a page's replies found here when they came, as they are now: gone (deleted on this device, or for
|
|
4893
|
+
* everyone by their author: WISP 400 § Delete for everyone), or the row, edited since or not. Each is looked for in the
|
|
4894
|
+
* page, else read as its one row, one at a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the
|
|
4895
|
+
* chat's whole history when it was read already. Before, such a reply still said `found`, with the original's text.
|
|
4699
4896
|
*/
|
|
4700
|
-
async function
|
|
4701
|
-
const here = new
|
|
4702
|
-
const
|
|
4703
|
-
|
|
4704
|
-
if (asked.length > ORIGINAL_READS) return
|
|
4705
|
-
const
|
|
4706
|
-
for (const id of asked)
|
|
4707
|
-
return
|
|
4708
|
-
}
|
|
4709
|
-
/**
|
|
4710
|
-
|
|
4897
|
+
async function originalsNow(ctx, chat, page, whole = page) {
|
|
4898
|
+
const here = new Map(whole.map((m) => [m.id, m]));
|
|
4899
|
+
const named = [...new Set(page.flatMap((m) => m.replyTo?.messageId ? [m.replyTo.messageId] : []))];
|
|
4900
|
+
const asked = named.filter((id) => !here.has(id));
|
|
4901
|
+
if (whole === page && asked.length > ORIGINAL_READS) return originalsNow(ctx, chat, page, await node(ctx).getMessages(chat));
|
|
4902
|
+
const originals = new Map(named.flatMap((id) => here.has(id) ? [[id, here.get(id)]] : []));
|
|
4903
|
+
for (const id of asked) originals.set(id, whole === page ? await node(ctx).getMessage(chat, id) : void 0);
|
|
4904
|
+
return originals;
|
|
4905
|
+
}
|
|
4906
|
+
/**
|
|
4907
|
+
* A reply's quote as the apps show it (`quoteFor`): an original gone reads "Original message deleted", not found and
|
|
4908
|
+
* none of its text; one edited since the reply quotes its text as it reads now. A button press keeps the question as
|
|
4909
|
+
* it was answered (WISP 406 · Message Buttons), and a card's or a file's line stays the one the reply carries.
|
|
4910
|
+
*/
|
|
4911
|
+
function quoteChecked(json, message, originals) {
|
|
4711
4912
|
const id = message.replyTo?.messageId;
|
|
4712
|
-
if (!json.replyTo || !id || !
|
|
4713
|
-
|
|
4913
|
+
if (!json.replyTo || !id || !originals.has(id)) return json;
|
|
4914
|
+
const original = originals.get(id);
|
|
4915
|
+
if (!original) return {
|
|
4714
4916
|
...json,
|
|
4715
4917
|
replyTo: {
|
|
4716
4918
|
...json.replyTo,
|
|
@@ -4719,30 +4921,13 @@ function quoteChecked(json, message, gone) {
|
|
|
4719
4921
|
deleted: true
|
|
4720
4922
|
}
|
|
4721
4923
|
};
|
|
4722
|
-
|
|
4723
|
-
function history(messages, params) {
|
|
4724
|
-
const limit = num(params, "limit", 50, {
|
|
4725
|
-
min: 1,
|
|
4726
|
-
max: 1e4,
|
|
4727
|
-
whole: true
|
|
4728
|
-
});
|
|
4729
|
-
const before = params.before;
|
|
4730
|
-
const after = params.after;
|
|
4731
|
-
const sorted = messages.slice().sort((a, b) => a.timestamp - b.timestamp);
|
|
4732
|
-
const bound = (value, side) => {
|
|
4733
|
-
if (value === void 0 || value === null) return;
|
|
4734
|
-
if (typeof value === "number") return (m) => side === "before" ? m.timestamp < value : m.timestamp > value;
|
|
4735
|
-
if (typeof value !== "string") throw new CliError("bad_request", `${side} must be a timestamp or a message id`);
|
|
4736
|
-
const index = sorted.findIndex((m) => m.id === value);
|
|
4737
|
-
if (index === -1) throw new CliError("not_found", `No message ${value}`);
|
|
4738
|
-
return (_, at) => side === "before" ? at < index : at > index;
|
|
4739
|
-
};
|
|
4740
|
-
const bounds = [bound(before, "before"), bound(after, "after")].filter((b) => b !== void 0);
|
|
4741
|
-
const list = sorted.filter((m, at) => bounds.every((within) => within(m, at)));
|
|
4742
|
-
const more = after !== void 0 && after !== null ? list.length > limit : list.length > limit;
|
|
4924
|
+
if (!original.edit || json.replyTo.button || original.card || original.file) return json;
|
|
4743
4925
|
return {
|
|
4744
|
-
|
|
4745
|
-
|
|
4926
|
+
...json,
|
|
4927
|
+
replyTo: {
|
|
4928
|
+
...json.replyTo,
|
|
4929
|
+
snippet: replySnippet(original.text)
|
|
4930
|
+
}
|
|
4746
4931
|
};
|
|
4747
4932
|
}
|
|
4748
4933
|
var API_METHODS = Object.keys(METHODS);
|
|
@@ -4756,4 +4941,4 @@ async function callApi(ctx, method, params = {}) {
|
|
|
4756
4941
|
//#endregion
|
|
4757
4942
|
export { flushCardUpdates as _, hideStateSecrets as a, paymentJson as c, nodeLocalFetch as d, chatJson as f, resumeHolds as g, groupMessageJson as h, groupSendRefused as i, reportAppFrames as l, groupJson as m, SETTABLE as n, mentionsFor as o, chatMessageJson as p, callApi as r, redactSettings as s, API_METHODS as t, servedApps as u };
|
|
4758
4943
|
|
|
4759
|
-
//# sourceMappingURL=api-
|
|
4944
|
+
//# sourceMappingURL=api-D3i2hwy0.js.map
|