@ghostlytools/cli 1.10.6 → 1.11.1
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 +27 -22
- package/SKILL.md +8 -5
- package/dist/assets/api-D89ubgas.js +3 -0
- package/dist/assets/{api-DppWqAP3.js → api-DL0Uazf6.js} +543 -204
- package/dist/assets/api-DL0Uazf6.js.map +1 -0
- package/dist/assets/{apiKit-DFIho4Ev.js → apiKit-D78MXTrk.js} +97 -13
- package/dist/assets/apiKit-D78MXTrk.js.map +1 -0
- package/dist/assets/{apps-yBnbEtfV.js → apps--pAqmfgQ.js} +16 -4
- package/dist/assets/apps--pAqmfgQ.js.map +1 -0
- package/dist/assets/{apps-1MkGMH8m.js → apps-BlSl1nGn.js} +1 -1
- package/dist/assets/{arkade-bFAS6imn.js → arkade-DxB-MR43.js} +2 -2
- package/dist/assets/{arkade-bFAS6imn.js.map → arkade-DxB-MR43.js.map} +1 -1
- package/dist/assets/{backup-vj4J7M3e.js → backup-B3JJd75o.js} +35 -7
- package/dist/assets/backup-B3JJd75o.js.map +1 -0
- package/dist/assets/{backup-ejIX59o7.js → backup-T7gFpU80.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{blobFiles-XZ9PEXYy.js → blobFiles-BmsrvZc3.js} +3 -3
- package/dist/assets/{blobFiles-XZ9PEXYy.js.map → blobFiles-BmsrvZc3.js.map} +1 -1
- package/dist/assets/{buttons-BoDMx3Ky.js → buttons-C1VbDihe.js} +61 -30
- package/dist/assets/buttons-C1VbDihe.js.map +1 -0
- package/dist/assets/buttons-DwWuK_uN.js +2 -0
- package/dist/assets/{client-BQArefYa.js → client-CGLuWFRV.js} +55 -10
- package/dist/assets/client-CGLuWFRV.js.map +1 -0
- package/dist/assets/{codec-_MwTUz5E.js → codec-YGJDr7uH.js} +2 -2
- package/dist/assets/{codec-_MwTUz5E.js.map → codec-YGJDr7uH.js.map} +1 -1
- package/dist/assets/{envelope-CeZBNGX-.js → envelope-Dwq8EN8x.js} +2 -2
- package/dist/assets/{envelope-CeZBNGX-.js.map → envelope-Dwq8EN8x.js.map} +1 -1
- package/dist/assets/{irohWeb-C_Wnw7Q9.js → fedimintSdk-CqTeMdF0.js} +2 -354
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +1 -0
- package/dist/assets/{fileBytes-DqnfKIkj.js → fileBytes-B0z9A6Le.js} +2 -2
- package/dist/assets/{fileBytes-DqnfKIkj.js.map → fileBytes-B0z9A6Le.js.map} +1 -1
- package/dist/assets/{fileBytes-BABGEF13.js → fileBytes-BLPZq9YU.js} +3 -3
- package/dist/assets/{fileBytes-BABGEF13.js.map → fileBytes-BLPZq9YU.js.map} +1 -1
- package/dist/assets/{fileBytes-CQQK2uOh.js → fileBytes-BtIyoDF2.js} +1 -1
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js → fileBytesIdb-Bmlrl9EO.js} +3 -3
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js.map → fileBytesIdb-Bmlrl9EO.js.map} +1 -1
- package/dist/assets/fileBytesIdb-D8mAK4pF.js +2 -0
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js → fileBytesOpfs-DBS0kbPT.js} +3 -3
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js.map → fileBytesOpfs-DBS0kbPT.js.map} +1 -1
- package/dist/assets/{fixedHosts-B_2Rvyja.js → fixedHosts-CINXidpd.js} +3 -3
- package/dist/assets/{fixedHosts-B_2Rvyja.js.map → fixedHosts-CINXidpd.js.map} +1 -1
- package/dist/assets/{host-DFLzzKNr.js → host-CGlHkiQv.js} +336 -84
- package/dist/assets/host-CGlHkiQv.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js → hyperdhtRelay-Bj5jJT5w.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js.map → hyperdhtRelay-Bj5jJT5w.js.map} +1 -1
- package/dist/assets/{idb-BHsAqENE.js → idb-CEuoNsTv.js} +16 -5
- package/dist/assets/idb-CEuoNsTv.js.map +1 -0
- package/dist/assets/{groupFiles-D-ZUUHrx.js → irohWeb-CYn0uB_A.js} +471 -18
- package/dist/assets/irohWeb-CYn0uB_A.js.map +1 -0
- package/dist/assets/{main-DxRwajM_.js → main-CgLW_Gyx.js} +409 -126
- package/dist/assets/main-CgLW_Gyx.js.map +1 -0
- package/dist/assets/{mainline-Bx184Ixg.js → mainline-B0h8RchD.js} +2 -2
- package/dist/assets/{mainline-Bx184Ixg.js.map → mainline-B0h8RchD.js.map} +1 -1
- package/dist/assets/{networkReason-BlQhTbXk.js → networkReason-BBosp2KG.js} +4 -4
- package/dist/assets/{networkReason-BlQhTbXk.js.map → networkReason-BBosp2KG.js.map} +1 -1
- package/dist/assets/{nwc-B3-PHX0L.js → nwc-SSNS1aJ-.js} +4 -4
- package/dist/assets/nwc-SSNS1aJ-.js.map +1 -0
- package/dist/assets/{nwcProvider-BeQBPB2q.js → nwcProvider-BXqJmM98.js} +11 -3
- package/dist/assets/nwcProvider-BXqJmM98.js.map +1 -0
- package/dist/assets/{ownDid-DAzW-Urb.js → ownDid--DtH_Jdi.js} +2 -2
- package/dist/assets/{ownDid-DAzW-Urb.js.map → ownDid--DtH_Jdi.js.map} +1 -1
- package/dist/assets/{words-BvdNuw_v.js → ownStatus-CQPGjCUR.js} +56 -4
- package/dist/assets/ownStatus-CQPGjCUR.js.map +1 -0
- package/dist/assets/{profiles-Bg43mRXu.js → profiles-4UQ1Hsds.js} +22 -12
- package/dist/assets/profiles-4UQ1Hsds.js.map +1 -0
- package/dist/assets/{registry-CAk2-5BQ.js → registry-B6BXKv6Q.js} +1 -1
- package/dist/assets/{registry-BDnsZJBi.js → registry-BKCFTEYp.js} +123 -99
- package/dist/assets/registry-BKCFTEYp.js.map +1 -0
- package/dist/assets/{resolve-UAfshn6j.js → resolve-MFeFljsN.js} +2 -2
- package/dist/assets/{resolve-UAfshn6j.js.map → resolve-MFeFljsN.js.map} +1 -1
- package/dist/assets/{restoredRows-YhlbokEE.js → restoredRows-C3LcxmOw.js} +4 -4
- package/dist/assets/{restoredRows-YhlbokEE.js.map → restoredRows-C3LcxmOw.js.map} +1 -1
- package/dist/assets/{server-DYdR0_Fj.js → server-rHKhnog1.js} +2100 -685
- package/dist/assets/server-rHKhnog1.js.map +1 -0
- package/dist/assets/{src-BTRPAi5X.js → src-BzsyAvPf.js} +1604 -305
- package/dist/assets/src-BzsyAvPf.js.map +1 -0
- package/dist/assets/{sshForges-KtHK5x1x.js → sshForges-qITn-RoV.js} +2 -2
- package/dist/assets/{sshForges-KtHK5x1x.js.map → sshForges-qITn-RoV.js.map} +1 -1
- package/dist/assets/{translate-CYuygrvA.js → translate-Bkr_iDgp.js} +9 -7
- package/dist/assets/translate-Bkr_iDgp.js.map +1 -0
- package/dist/assets/{usdt-Dw9IENe_.js → usdt-Bp7T2iqt.js} +3 -3
- package/dist/assets/{usdt-Dw9IENe_.js.map → usdt-Bp7T2iqt.js.map} +1 -1
- package/dist/assets/{waitNotice-Ce3YCinu.js → waitNotice-Cn0WJ-He.js} +3 -1
- package/dist/assets/waitNotice-Cn0WJ-He.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/claude-code-agent.sh +5 -0
- package/package.json +2 -2
- package/dist/assets/api-DppWqAP3.js.map +0 -1
- package/dist/assets/api-K-i5MrP-.js +0 -3
- package/dist/assets/apiKit-DFIho4Ev.js.map +0 -1
- package/dist/assets/apps-yBnbEtfV.js.map +0 -1
- package/dist/assets/backup-vj4J7M3e.js.map +0 -1
- package/dist/assets/buttons-BoDMx3Ky.js.map +0 -1
- package/dist/assets/buttons-DG1CKgAI.js +0 -2
- package/dist/assets/client-BQArefYa.js.map +0 -1
- package/dist/assets/fileBytesIdb-BtXATa7j.js +0 -2
- package/dist/assets/groupFiles-D-ZUUHrx.js.map +0 -1
- package/dist/assets/host-DFLzzKNr.js.map +0 -1
- package/dist/assets/idb-BHsAqENE.js.map +0 -1
- package/dist/assets/irohWeb-C_Wnw7Q9.js.map +0 -1
- package/dist/assets/main-DxRwajM_.js.map +0 -1
- package/dist/assets/nwc-B3-PHX0L.js.map +0 -1
- package/dist/assets/nwcProvider-BeQBPB2q.js.map +0 -1
- package/dist/assets/profiles-Bg43mRXu.js.map +0 -1
- package/dist/assets/registry-BDnsZJBi.js.map +0 -1
- package/dist/assets/server-DYdR0_Fj.js.map +0 -1
- package/dist/assets/src-BTRPAi5X.js.map +0 -1
- package/dist/assets/translate-CYuygrvA.js.map +0 -1
- package/dist/assets/waitNotice-Ce3YCinu.js.map +0 -1
- package/dist/assets/words-BvdNuw_v.js.map +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as IDENTITY_PROVIDERS } from "./registry-
|
|
1
|
+
import { Ba as PLAYABLE_AUDIO, Bo as MESSAGE_CLOCK_SKEW_MS, Di as APP_DATA_MAX_BYTES, Gu as relayUrlProblem, Ha as VOICE_METER, Hn as withoutVideoMetadata, Ho as claimedTime, Io as checkStatusCard, Ja as voiceLevel, Ka as parseVoiceMeta, Kl as readImageMeta, Kn as stripPictureMetadata, Ml as appRef, Mo as appCardUrl, Po as cardLine, Ra as sanitizeFileName, Rl as isAppRef, Ro as statusCardBytes, Ua as baseMime, Un as NO_PICTURE_METADATA, Va as VOICE_LIMITS, Wa as downsamplePeaks, Wu as normalizeRelayUrl, Yi as identityStatement, _d as randomBytes$1, _s as parseLocalTarget, ar as GROUP_FILE_LIMITS, bo as replySnippet, cu as ownInviteRefusal, hs as GhostlyHttpError, ii as sanitizeTypingStatus, jo as appCardId, ko as STATUS_CARD_LIMITS, ld as MAX_AVATAR_LENGTH, ni as TYPING_REFRESH_MS, ou as inviteLink, qa as voiceDownloadName, qn as withoutPictureMetadata, ss as AWAITING_PEER_MS, ti as TYPING_KINDS, ud as sanitizeAvatar, vd as toBase64Url, wl as isAppUrl, yl as APP_PERMISSIONS, ys as LIMITS, za as sanitizeMime, zn as withoutAudioMetadata } from "./src-BzsyAvPf.js";
|
|
2
|
+
import { p as fileStore } from "./idb-CEuoNsTv.js";
|
|
3
|
+
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BLPZq9YU.js";
|
|
4
|
+
import { $ as iceServerProblem, M as waitingGroupFile, N as IDENTITY_DRAFT_TTL_MS, S as paymentNetwork, c as groupOfFile, et as iceServerSetting, k as removeStored, o as groupFileId, p as replyRef, t as DEFAULT_IROH_RELAYS } from "./irohWeb-CYn0uB_A.js";
|
|
5
|
+
import { t as IDENTITY_PROVIDERS } from "./registry-BKCFTEYp.js";
|
|
6
6
|
import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-B7Hj0Kvz.js";
|
|
7
7
|
import { i as localFileError, r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
|
|
8
|
-
import { a as
|
|
9
|
-
import {
|
|
8
|
+
import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-CQPGjCUR.js";
|
|
9
|
+
import { A as sinceSeq, D as oneShotWaits, E as oneOf, F as transportOffered, I as waitForState, N as state, O as sentAt, P as str, S as nobodyJoined, T as num, _ as messageOf, b as noFile, c as findChatOrGroup, d as groupNameOf, f as groupOf, g as list, h as keptForJoin, i as chatOrGroup, j as somebodyJoined, k as shownName, l as findGroup, m as inviteTaken, n as bool, o as dhtOnly, p as groupPrefixed, r as chatOf, s as findChat, u as findOwnNamedChat, w as node, x as noMessage } from "./apiKit-D78MXTrk.js";
|
|
10
10
|
import { t as childEnv } from "./childEnv-BVOQK9EA.js";
|
|
11
|
-
import {
|
|
12
|
-
import { t as
|
|
13
|
-
import { a as
|
|
14
|
-
import { t as BACKUP_METHODS } from "./backup-
|
|
15
|
-
import { o as checkedBundle } from "./apps
|
|
11
|
+
import { t as chatState } from "./waitNotice-Cn0WJ-He.js";
|
|
12
|
+
import { a as goesOn, c as waitForGroupFrame, i as pressable, l as waitForMessage, n as buttonsCard, o as waitForConfirmed, s as waitForEdit, t as BUTTON_METHODS, u as waitForRemoval } from "./buttons-C1VbDihe.js";
|
|
13
|
+
import { a as checkShownName } from "./profiles-4UQ1Hsds.js";
|
|
14
|
+
import { t as BACKUP_METHODS } from "./backup-B3JJd75o.js";
|
|
15
|
+
import { o as checkedBundle } from "./apps--pAqmfgQ.js";
|
|
16
16
|
import { generateMnemonic } from "@scure/bip39";
|
|
17
17
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
18
18
|
import { execFile, spawn } from "node:child_process";
|
|
19
19
|
import { openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { access, constants as constants$1, copyFile, link, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
21
|
-
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
21
|
+
import { basename, dirname, extname, join, resolve, sep } from "node:path";
|
|
22
22
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
23
23
|
import { createServer } from "node:http";
|
|
24
24
|
import { Readable } from "node:stream";
|
|
@@ -793,15 +793,21 @@ function fileChat(ctx, params, fileId) {
|
|
|
793
793
|
const groupId = groupOfFile(fileId, state(ctx).groups.map((g) => g.id));
|
|
794
794
|
if (groupId) {
|
|
795
795
|
const named = params.chat === void 0 ? void 0 : chatOrGroupOf(ctx, params);
|
|
796
|
-
if (named && !("group" in named && named.group.id === groupId)) throw
|
|
796
|
+
if (named && !("group" in named && named.group.id === groupId)) throw noFile(fileId, {
|
|
797
|
+
group: "group" in named,
|
|
798
|
+
ref: str(params, "chat", true)
|
|
799
|
+
});
|
|
797
800
|
return {
|
|
798
801
|
linkId: `group:${groupId}`,
|
|
799
802
|
where: { group: groupId }
|
|
800
803
|
};
|
|
801
804
|
}
|
|
802
805
|
const link = params.chat === void 0 ? state(ctx).links.find((l) => fileId.startsWith(`${l.id}-in-`) || fileId.startsWith(`${l.id}-out-`)) : chatOf(ctx, params);
|
|
803
|
-
if (!link) throw
|
|
804
|
-
if (!fileId.startsWith(`${link.id}-`)) throw
|
|
806
|
+
if (!link) throw noFile(fileId);
|
|
807
|
+
if (!fileId.startsWith(`${link.id}-`)) throw noFile(fileId, {
|
|
808
|
+
group: false,
|
|
809
|
+
ref: str(params, "chat", true)
|
|
810
|
+
});
|
|
805
811
|
return {
|
|
806
812
|
linkId: link.id,
|
|
807
813
|
where: { chat: link.id }
|
|
@@ -842,17 +848,38 @@ async function voiceOf(params, path, mime, size) {
|
|
|
842
848
|
throw new CliError("bad_request", `A voice note's waveform is 1 to ${VOICE_LIMITS.maxBars} peaks from 0 to 255`);
|
|
843
849
|
}
|
|
844
850
|
/**
|
|
845
|
-
* The file at `path` as it is sent, as the apps send it (platform/services.ts `sendable`): a picture
|
|
846
|
-
* QuickTime video without its metadata (where it was taken or recorded, the device, the time
|
|
847
|
-
* and its digest computed. One whose metadata cannot be removed is
|
|
851
|
+
* The file at `path` as it is sent, as the apps send it (platform/services.ts `sendable`): a picture, an MP4 or
|
|
852
|
+
* QuickTime video or an audio file without its metadata (where it was taken or recorded, the device, the time, an
|
|
853
|
+
* audio file's tags), before its size is read and its digest computed. One whose metadata cannot be removed is
|
|
854
|
+
* refused, never sent as it was. A voice note is a file made anywhere, so its tags go too.
|
|
848
855
|
*/
|
|
849
|
-
async function sendable(path, mime
|
|
856
|
+
async function sendable(path, mime) {
|
|
850
857
|
const source = await openAsBlob(path, { type: mime });
|
|
851
|
-
if (voice) return source;
|
|
852
858
|
try {
|
|
853
|
-
return await withoutPictureMetadata(source, mime) ?? await withoutVideoMetadata(source, mime) ?? source;
|
|
859
|
+
return await withoutPictureMetadata(source, mime) ?? await withoutVideoMetadata(source, mime) ?? await withoutAudioMetadata(source, mime) ?? source;
|
|
860
|
+
} catch (error) {
|
|
861
|
+
if (error instanceof Error && [
|
|
862
|
+
"This picture cannot be sent: Ghostly could not remove the details saved in it, like where it was taken",
|
|
863
|
+
"This video cannot be sent: Ghostly could not remove the details saved in it, like where it was recorded",
|
|
864
|
+
"This audio cannot be sent: Ghostly could not remove the details saved in it, like where it was recorded"
|
|
865
|
+
].includes(error.message)) throw new CliError("refused", error.message);
|
|
866
|
+
throw error;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* A read of the file at `path` through the Blob `openAsBlob` gave it. Node refuses every read of that Blob once the file
|
|
871
|
+
* changed on disk (it grew, shrank or was written again: a log still written to, a file being saved), with a bare
|
|
872
|
+
* DOMException "The blob could not be read" that named neither the file nor why, as `engine`. Said with its path, as
|
|
873
|
+
* `unavailable`: sent again once nothing writes to it, it goes, and nothing of this try was kept (`stage` removes its copy).
|
|
874
|
+
*/
|
|
875
|
+
async function whileUnchanged(path, read) {
|
|
876
|
+
try {
|
|
877
|
+
return await read();
|
|
854
878
|
} catch (error) {
|
|
855
|
-
if (error
|
|
879
|
+
if (error && typeof error === "object" && error.name === "NotReadableError") throw new CliError("unavailable", `${path} changed while it was being sent: send it again once nothing is writing to it`, {
|
|
880
|
+
reason: "file_changed",
|
|
881
|
+
path
|
|
882
|
+
});
|
|
856
883
|
throw error;
|
|
857
884
|
}
|
|
858
885
|
}
|
|
@@ -866,14 +893,17 @@ async function sendToGroup(ctx, params, group, path, picked) {
|
|
|
866
893
|
const mime = mimeOf(path, str(params, "mime"));
|
|
867
894
|
const replyTo = str(params, "reply");
|
|
868
895
|
if (replyTo) {
|
|
869
|
-
if (!await findMessage(ctx, `group:${group.id}`, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw
|
|
896
|
+
if (!await findMessage(ctx, `group:${group.id}`, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw noMessage(replyTo, {
|
|
897
|
+
group: true,
|
|
898
|
+
ref: str(params, "chat", true)
|
|
899
|
+
}, { tail: ", or it cannot be replied to" });
|
|
870
900
|
}
|
|
871
901
|
const check = await node(ctx).groupFileCheck({ groupId: group.id });
|
|
872
902
|
if (check.error) throw check.refused ? new CliError("refused", check.error) : groupSendRefused(check.error);
|
|
873
903
|
const { voice, warning } = await voiceOf(params, path, mime, picked);
|
|
874
|
-
const source = await sendable(path, mime
|
|
904
|
+
const source = await whileUnchanged(path, () => sendable(path, mime));
|
|
875
905
|
const size = source.size;
|
|
876
|
-
const image = voice ? void 0 : await readImageMeta(source, mime);
|
|
906
|
+
const image = voice ? void 0 : await whileUnchanged(path, () => readImageMeta(source, mime));
|
|
877
907
|
const fileId = groupFileId(group.id, "out");
|
|
878
908
|
const file = {
|
|
879
909
|
id: fileId,
|
|
@@ -885,7 +915,7 @@ async function sendToGroup(ctx, params, group, path, picked) {
|
|
|
885
915
|
};
|
|
886
916
|
const timestamp = Date.now();
|
|
887
917
|
const bytes = await fileBytes();
|
|
888
|
-
const digest = await bytes.stage(fileId, source);
|
|
918
|
+
const digest = await whileUnchanged(path, () => bytes.stage(fileId, source));
|
|
889
919
|
await fileStore.put({
|
|
890
920
|
id: fileId,
|
|
891
921
|
linkId: `group:${group.id}`,
|
|
@@ -1002,6 +1032,55 @@ var ACTIONS = [
|
|
|
1002
1032
|
"resend",
|
|
1003
1033
|
"request"
|
|
1004
1034
|
];
|
|
1035
|
+
/**
|
|
1036
|
+
* `file wait`: until a transfer ends: done answers, failed is an `engine` error with the transfer's words (and whether
|
|
1037
|
+
* `file resend` can go on). A file whose transfer this run has not seen answers from the file store. `stopping`: the
|
|
1038
|
+
* daemon's stop ends it as well (`waitForState`), for `file send --wait`, which answers with what it knows then.
|
|
1039
|
+
*/
|
|
1040
|
+
async function waitForFile(ctx, params, stopping) {
|
|
1041
|
+
const fileId = str(params, "file", true);
|
|
1042
|
+
const { where } = fileChat(ctx, params, fileId);
|
|
1043
|
+
const stored = await fileStore.get(fileId);
|
|
1044
|
+
if (!stored && !state(ctx).transfers[fileId]) throw noFile(fileId);
|
|
1045
|
+
const ms = num(params, "timeout", 300, {
|
|
1046
|
+
min: 1,
|
|
1047
|
+
max: 86400
|
|
1048
|
+
}) * 1e3;
|
|
1049
|
+
const transfer = await waitForState(ctx, (s) => {
|
|
1050
|
+
const now = s.transfers[fileId] ?? stored?.transfer;
|
|
1051
|
+
return now && (now.state === "done" || now.state === "failed" || now.stage === "asking" && now.direction === "in") ? now : void 0;
|
|
1052
|
+
}, ms, `file ${fileId} to arrive`, stopping).catch((error) => {
|
|
1053
|
+
const now = state(ctx).transfers[fileId];
|
|
1054
|
+
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${stageWords(now)}` : ""})`, {
|
|
1055
|
+
file: fileId,
|
|
1056
|
+
transferred: now.transferred,
|
|
1057
|
+
size: now.size,
|
|
1058
|
+
stage: now.stage ?? null,
|
|
1059
|
+
...error.details?.reason ? { reason: error.details.reason } : {}
|
|
1060
|
+
});
|
|
1061
|
+
throw error;
|
|
1062
|
+
});
|
|
1063
|
+
if (transfer.state === "failed") throw new CliError("engine", transfer.error ?? "The transfer failed", {
|
|
1064
|
+
file: fileId,
|
|
1065
|
+
...where,
|
|
1066
|
+
retry: !!transfer.retry
|
|
1067
|
+
});
|
|
1068
|
+
if (transfer.state !== "done") {
|
|
1069
|
+
const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
|
|
1070
|
+
throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
1071
|
+
file: fileId,
|
|
1072
|
+
...where,
|
|
1073
|
+
size: transfer.size,
|
|
1074
|
+
stage: "asking"
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
return {
|
|
1078
|
+
...where,
|
|
1079
|
+
file: fileId,
|
|
1080
|
+
state: "done",
|
|
1081
|
+
size: transfer.size
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1005
1084
|
var FILE_METHODS = {
|
|
1006
1085
|
async "file.send"(ctx, params) {
|
|
1007
1086
|
guardText(str(params, "name"), bool(params, "force"), "file's name", "send it");
|
|
@@ -1015,7 +1094,7 @@ var FILE_METHODS = {
|
|
|
1015
1094
|
}
|
|
1016
1095
|
if (!info.isFile()) throw new CliError("bad_request", `${path} is not a file`);
|
|
1017
1096
|
await access(path, constants$1.R_OK);
|
|
1018
|
-
const wait = oneOf(params, "wait", "group" in target ? ["none"] : ["none", "sent"], !("group" in target) && ctx.
|
|
1097
|
+
const wait = oneOf(params, "wait", "group" in target ? ["none"] : ["none", "sent"], !("group" in target) && oneShotWaits(ctx, target.link.id) ? "sent" : "none");
|
|
1019
1098
|
const seconds = num(params, "timeout", 300, {
|
|
1020
1099
|
min: 1,
|
|
1021
1100
|
max: 86400
|
|
@@ -1028,11 +1107,14 @@ var FILE_METHODS = {
|
|
|
1028
1107
|
const mime = mimeOf(path, str(params, "mime"));
|
|
1029
1108
|
const replyTo = str(params, "reply");
|
|
1030
1109
|
if (replyTo) {
|
|
1031
|
-
if (!await findMessage(ctx, link.id, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw
|
|
1110
|
+
if (!await findMessage(ctx, link.id, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw noMessage(replyTo, {
|
|
1111
|
+
group: false,
|
|
1112
|
+
ref: str(params, "chat", true)
|
|
1113
|
+
}, { tail: ", or it cannot be replied to" });
|
|
1032
1114
|
}
|
|
1033
1115
|
const { voice, warning } = await voiceOf(params, path, mime, info.size);
|
|
1034
|
-
const source = await sendable(path, mime
|
|
1035
|
-
const image = voice ? void 0 : await readImageMeta(source, mime);
|
|
1116
|
+
const source = await whileUnchanged(path, () => sendable(path, mime));
|
|
1117
|
+
const image = voice ? void 0 : await whileUnchanged(path, () => readImageMeta(source, mime));
|
|
1036
1118
|
const wireId = toBase64Url(randomBytes$1(12));
|
|
1037
1119
|
const file = {
|
|
1038
1120
|
id: `${link.id}-out-${wireId}`,
|
|
@@ -1044,7 +1126,7 @@ var FILE_METHODS = {
|
|
|
1044
1126
|
};
|
|
1045
1127
|
const timestamp = sentAt();
|
|
1046
1128
|
const bytes = await fileBytes();
|
|
1047
|
-
const digest = await bytes.stage(file.id, source);
|
|
1129
|
+
const digest = await whileUnchanged(path, () => bytes.stage(file.id, source));
|
|
1048
1130
|
await fileStore.put({
|
|
1049
1131
|
id: file.id,
|
|
1050
1132
|
linkId: link.id,
|
|
@@ -1079,14 +1161,23 @@ var FILE_METHODS = {
|
|
|
1079
1161
|
await removeStored(file.id).catch(() => {});
|
|
1080
1162
|
throw new CliError("refused", error instanceof Error ? error.message : String(error));
|
|
1081
1163
|
}
|
|
1082
|
-
|
|
1164
|
+
const messageId = `me_${timestamp}`;
|
|
1165
|
+
if (wait === "sent") await waitForFile(ctx, {
|
|
1083
1166
|
chat: link.id,
|
|
1084
1167
|
file: file.id,
|
|
1085
1168
|
timeout: seconds
|
|
1169
|
+
}, ctx.stopping).catch((error) => {
|
|
1170
|
+
if (!(error instanceof CliError) || error.code !== "timeout") throw error;
|
|
1171
|
+
throw new CliError("timeout", `${error.message}. It is kept here and ${goesOn(ctx, link.id)}`, {
|
|
1172
|
+
...error.details,
|
|
1173
|
+
chat: link.id,
|
|
1174
|
+
messageId,
|
|
1175
|
+
file: file.id
|
|
1176
|
+
});
|
|
1086
1177
|
});
|
|
1087
1178
|
return {
|
|
1088
1179
|
chat: link.id,
|
|
1089
|
-
messageId
|
|
1180
|
+
messageId,
|
|
1090
1181
|
file: {
|
|
1091
1182
|
id: file.id,
|
|
1092
1183
|
name: file.name,
|
|
@@ -1095,7 +1186,8 @@ var FILE_METHODS = {
|
|
|
1095
1186
|
...voice ? { voice: true } : {},
|
|
1096
1187
|
...image ? { image } : {}
|
|
1097
1188
|
},
|
|
1098
|
-
...warning ? { warning } : {}
|
|
1189
|
+
...warning ? { warning } : {},
|
|
1190
|
+
...keptForJoin(ctx, link.id, "the file")
|
|
1099
1191
|
};
|
|
1100
1192
|
},
|
|
1101
1193
|
async "file.list"(ctx, params) {
|
|
@@ -1105,20 +1197,23 @@ var FILE_METHODS = {
|
|
|
1105
1197
|
const kept = f.transfer?.state === "done" ? {
|
|
1106
1198
|
...f.transfer,
|
|
1107
1199
|
direction: f.direction
|
|
1200
|
+
} : !("group" in target) && f.transfer?.state === "transferring" && f.direction === "out" ? {
|
|
1201
|
+
...f.transfer,
|
|
1202
|
+
direction: f.direction,
|
|
1203
|
+
stage: "waiting",
|
|
1204
|
+
waitingFor: "contact"
|
|
1108
1205
|
} : waitingGroupFile(f);
|
|
1109
1206
|
return kept ? [[f.id, kept]] : [];
|
|
1110
1207
|
}));
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1118
|
-
const kept = await keptOf(target.link.id);
|
|
1119
|
-
return {
|
|
1208
|
+
const linkId = "group" in target ? `group:${target.group.id}` : target.link.id;
|
|
1209
|
+
const kept = await keptOf(linkId);
|
|
1210
|
+
const files = filesOf(await node(ctx).fileMessages(linkId), (id) => withWaitingFor(views[id] ?? kept.get(id)));
|
|
1211
|
+
return "group" in target ? {
|
|
1212
|
+
group: target.group.id,
|
|
1213
|
+
files
|
|
1214
|
+
} : {
|
|
1120
1215
|
chat: target.link.id,
|
|
1121
|
-
files
|
|
1216
|
+
files
|
|
1122
1217
|
};
|
|
1123
1218
|
},
|
|
1124
1219
|
/**
|
|
@@ -1182,52 +1277,8 @@ var FILE_METHODS = {
|
|
|
1182
1277
|
transfer: state(ctx).transfers[fileId] ?? null
|
|
1183
1278
|
};
|
|
1184
1279
|
},
|
|
1185
|
-
/**
|
|
1186
|
-
* Until a transfer ends: done answers, failed is an `engine` error with the transfer's words (and whether `file
|
|
1187
|
-
* resend` can go on). A file whose transfer this run has not seen answers from the file store.
|
|
1188
|
-
*/
|
|
1189
1280
|
async "file.wait"(ctx, params) {
|
|
1190
|
-
|
|
1191
|
-
const { where } = fileChat(ctx, params, fileId);
|
|
1192
|
-
const stored = await fileStore.get(fileId);
|
|
1193
|
-
if (!stored && !state(ctx).transfers[fileId]) throw new CliError("not_found", `No file ${fileId}`);
|
|
1194
|
-
const ms = num(params, "timeout", 300, {
|
|
1195
|
-
min: 1,
|
|
1196
|
-
max: 86400
|
|
1197
|
-
}) * 1e3;
|
|
1198
|
-
const transfer = await waitForState(ctx, (s) => {
|
|
1199
|
-
const now = s.transfers[fileId] ?? stored?.transfer;
|
|
1200
|
-
return now && (now.state === "done" || now.state === "failed" || now.stage === "asking" && now.direction === "in") ? now : void 0;
|
|
1201
|
-
}, ms, `file ${fileId} to arrive`).catch((error) => {
|
|
1202
|
-
const now = state(ctx).transfers[fileId];
|
|
1203
|
-
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${stageWords(now)}` : ""})`, {
|
|
1204
|
-
file: fileId,
|
|
1205
|
-
transferred: now.transferred,
|
|
1206
|
-
size: now.size,
|
|
1207
|
-
stage: now.stage ?? null
|
|
1208
|
-
});
|
|
1209
|
-
throw error;
|
|
1210
|
-
});
|
|
1211
|
-
if (transfer.state === "failed") throw new CliError("engine", transfer.error ?? "The transfer failed", {
|
|
1212
|
-
file: fileId,
|
|
1213
|
-
...where,
|
|
1214
|
-
retry: !!transfer.retry
|
|
1215
|
-
});
|
|
1216
|
-
if (transfer.state !== "done") {
|
|
1217
|
-
const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
|
|
1218
|
-
throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
1219
|
-
file: fileId,
|
|
1220
|
-
...where,
|
|
1221
|
-
size: transfer.size,
|
|
1222
|
-
stage: "asking"
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
return {
|
|
1226
|
-
...where,
|
|
1227
|
-
file: fileId,
|
|
1228
|
-
state: "done",
|
|
1229
|
-
size: transfer.size
|
|
1230
|
-
};
|
|
1281
|
+
return waitForFile(ctx, params);
|
|
1231
1282
|
},
|
|
1232
1283
|
/**
|
|
1233
1284
|
* Writes a received (or sent) file to disk: into `dir` under its own name (`saveName`), a voice message under the one
|
|
@@ -1242,13 +1293,15 @@ var FILE_METHODS = {
|
|
|
1242
1293
|
timeout: params.timeout
|
|
1243
1294
|
});
|
|
1244
1295
|
const stored = await fileStore.get(fileId);
|
|
1245
|
-
if (!stored?.metadata) throw
|
|
1296
|
+
if (!stored?.metadata) throw noFile(fileId);
|
|
1246
1297
|
if (stored.leftOut) throw new CliError("not_found", "Not in this backup: the light backup this profile was restored from left the file out");
|
|
1247
1298
|
const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? stored.transfer;
|
|
1248
1299
|
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1249
1300
|
if (transfer && transfer.state !== "done") throw new CliError("unavailable", `The file is not all here yet (${transfer.transferred} of ${transfer.size} bytes)`);
|
|
1250
1301
|
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));
|
|
1251
1302
|
const force = bool(params, "force");
|
|
1303
|
+
const path = str(params, "path");
|
|
1304
|
+
if (path && (path.endsWith("/") || path.endsWith(sep)) && !(await stat(named).catch(() => void 0))?.isDirectory()) throw new CliError("bad_request", `${path} names a folder: name a file, or use --dir ${named} (dir over the socket)`);
|
|
1252
1305
|
const free = !force && !str(params, "path") && !!stored.metadata.voice;
|
|
1253
1306
|
const ext = extname(named), stem = named.slice(0, named.length - ext.length);
|
|
1254
1307
|
const taken = async (target, code) => {
|
|
@@ -1540,7 +1593,7 @@ async function sendCard(ctx, params, kind) {
|
|
|
1540
1593
|
"none",
|
|
1541
1594
|
"sent",
|
|
1542
1595
|
"delivered"
|
|
1543
|
-
], ctx.
|
|
1596
|
+
], oneShotWaits(ctx, target.linkId) ? "sent" : "none");
|
|
1544
1597
|
const ms = num(params, "timeout", 30, {
|
|
1545
1598
|
min: 1,
|
|
1546
1599
|
max: 3600
|
|
@@ -1571,7 +1624,23 @@ async function sendCard(ctx, params, kind) {
|
|
|
1571
1624
|
if (wait !== "none") message = await waitForMessage(ctx, target.linkId, result.messageId, wait, ms);
|
|
1572
1625
|
return answer(target, kind, id, result.messageId, {
|
|
1573
1626
|
card,
|
|
1574
|
-
delivery: message?.delivery ?? null
|
|
1627
|
+
delivery: message?.delivery ?? null,
|
|
1628
|
+
...keptForJoin(ctx, target.linkId, "the card")
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* A card's own kept times (a task's start, a routine's runs) later than the sender's rule takes: the device's clock
|
|
1633
|
+
* went back since they were set. Said as that, not as a time the person gave in the future; fields the update gives
|
|
1634
|
+
* are checked as given.
|
|
1635
|
+
*/
|
|
1636
|
+
function clockWentBack(base, patch, kind) {
|
|
1637
|
+
const latest = Date.now() + MESSAGE_CLOCK_SKEW_MS;
|
|
1638
|
+
const ahead = (value) => typeof value === "number" && value > latest;
|
|
1639
|
+
const at = (run) => isObject(run) && ahead(run.at);
|
|
1640
|
+
const field = kind === "task" ? patch.startedAt === void 0 && ahead(base.startedAt) ? "startedAt" : void 0 : kind === "routine" ? patch.lastRun === void 0 && at(base.lastRun) ? "lastRun.at" : patch.runs === void 0 && Array.isArray(base.runs) && base.runs.some(at) ? "runs[].at" : void 0 : void 0;
|
|
1641
|
+
if (field) throw new CliError("bad_request", `This device's clock went back since the ${kind} was sent: its ${field} is later than now. Update it once the clock is right, or start a new card with ghostly ${kind} send`, {
|
|
1642
|
+
field,
|
|
1643
|
+
now: Date.now()
|
|
1575
1644
|
});
|
|
1576
1645
|
}
|
|
1577
1646
|
/** Edits the card's message with its merged card, now. */
|
|
@@ -1600,18 +1669,22 @@ async function updateCard(ctx, params, kind) {
|
|
|
1600
1669
|
edits: message.edit.seq
|
|
1601
1670
|
});
|
|
1602
1671
|
const pace = paceOf(ctx, `${target.linkId}\n${message.id}`);
|
|
1603
|
-
const
|
|
1672
|
+
const base = pace.next ?? message.card;
|
|
1673
|
+
clockWentBack(base, patch, kind);
|
|
1674
|
+
const startedAt = typeof base.startedAt === "number" && patch.startedAt === void 0 ? base.startedAt : 0;
|
|
1675
|
+
const card = checked(withRun(mergeCard(base, {
|
|
1604
1676
|
...patch,
|
|
1605
|
-
...kind === "task" && { updatedAt: Date.now() }
|
|
1677
|
+
...kind === "task" && { updatedAt: Math.max(Date.now(), startedAt) }
|
|
1606
1678
|
}), params));
|
|
1607
1679
|
if (isObject(patch) && patch.parent !== void 0) await parentThere(ctx, target, card);
|
|
1608
1680
|
const text = str(params, "text") ?? "";
|
|
1609
|
-
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], ctx.
|
|
1681
|
+
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], oneShotWaits(ctx, target.linkId) ? "confirmed" : "none");
|
|
1610
1682
|
const ms = num(params, "timeout", 30, {
|
|
1611
1683
|
min: 1,
|
|
1612
1684
|
max: 3600
|
|
1613
1685
|
}) * 1e3;
|
|
1614
|
-
const
|
|
1686
|
+
const last = Math.max(pace.last, message.edit?.at ?? message.timestamp);
|
|
1687
|
+
const due = Math.min(last + CARD_UPDATE_GAP_MS - Date.now(), CARD_UPDATE_GAP_MS);
|
|
1615
1688
|
let queued = false;
|
|
1616
1689
|
if (due > 0 && ctx.mode === "daemon") {
|
|
1617
1690
|
pace.next = card;
|
|
@@ -1642,7 +1715,10 @@ async function updateCard(ctx, params, kind) {
|
|
|
1642
1715
|
card,
|
|
1643
1716
|
queued,
|
|
1644
1717
|
edits: edited?.edit?.seq ?? 0,
|
|
1645
|
-
...target.group ? { ...edges !== void 0 && { edges } } : {
|
|
1718
|
+
...target.group ? { ...edges !== void 0 && { edges } } : {
|
|
1719
|
+
confirmed: (!queued || wait !== "none") && !!edited && !edited.edit?.pending,
|
|
1720
|
+
...keptForJoin(ctx, target.linkId, "the update")
|
|
1721
|
+
}
|
|
1646
1722
|
});
|
|
1647
1723
|
}
|
|
1648
1724
|
/**
|
|
@@ -1685,7 +1761,7 @@ async function reportUsage(ctx, ref, fields, params) {
|
|
|
1685
1761
|
};
|
|
1686
1762
|
checked(report);
|
|
1687
1763
|
const sent = await cardMessage(ctx, target, "usage", id).catch(() => void 0);
|
|
1688
|
-
const wait = oneOf(params, "wait", ["none", "sent"], !target.group && ctx.
|
|
1764
|
+
const wait = oneOf(params, "wait", ["none", "sent"], !target.group && oneShotWaits(ctx, target.linkId) ? "sent" : "none");
|
|
1689
1765
|
if (!sent || (sent.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) return {
|
|
1690
1766
|
...await sendCard(ctx, {
|
|
1691
1767
|
...params,
|
|
@@ -1771,6 +1847,7 @@ var STATUS_CARD_METHODS = {
|
|
|
1771
1847
|
* chosen before (that one is not a hold).
|
|
1772
1848
|
*/
|
|
1773
1849
|
var HOLD_MAX_MINUTES = 10080;
|
|
1850
|
+
/** Per chat held: what stops its wait (the timer, or the wait for the chat to open: `expire`). */
|
|
1774
1851
|
var timers = /* @__PURE__ */ new WeakMap();
|
|
1775
1852
|
function holdsFile(ctx) {
|
|
1776
1853
|
return join(ctx.runtime.paths.dir, "holds.json");
|
|
@@ -1792,19 +1869,47 @@ function timersOf(ctx) {
|
|
|
1792
1869
|
if (!map) timers.set(ctx, map = /* @__PURE__ */ new Map());
|
|
1793
1870
|
return map;
|
|
1794
1871
|
}
|
|
1872
|
+
function stopWait(ctx, linkId) {
|
|
1873
|
+
timersOf(ctx).get(linkId)?.();
|
|
1874
|
+
timersOf(ctx).delete(linkId);
|
|
1875
|
+
}
|
|
1795
1876
|
function schedule(ctx, linkId, until) {
|
|
1796
|
-
|
|
1797
|
-
clearTimeout(map.get(linkId));
|
|
1877
|
+
stopWait(ctx, linkId);
|
|
1798
1878
|
const timer = setTimeout(() => {
|
|
1799
|
-
|
|
1800
|
-
|
|
1879
|
+
timersOf(ctx).delete(linkId);
|
|
1880
|
+
expire(ctx, linkId);
|
|
1801
1881
|
}, Math.max(0, until - Date.now()));
|
|
1802
1882
|
timer.unref?.();
|
|
1803
|
-
|
|
1883
|
+
timersOf(ctx).set(linkId, () => clearTimeout(timer));
|
|
1804
1884
|
}
|
|
1805
|
-
/**
|
|
1885
|
+
/**
|
|
1886
|
+
* Whether the chat leaves DHT only in this run: the engine switches only a chat it opened (`runnableTransports` is
|
|
1887
|
+
* there once it did). A one-shot that only reads opens none, and one about another chat not this one.
|
|
1888
|
+
*/
|
|
1889
|
+
var switchable = (link) => !link || link.deliveryMode !== "dht" || !!link.runnableTransports;
|
|
1890
|
+
/**
|
|
1891
|
+
* A hold whose time is up ends. On a chat this run has not opened it ends once the chat opens, or at the next start
|
|
1892
|
+
* that opens it; it is no longer reported meanwhile (`holdOf`). Each read said on stderr that it "could not end:
|
|
1893
|
+
* Delivery method unavailable." and kept its past `heldUntil`.
|
|
1894
|
+
*/
|
|
1895
|
+
function expire(ctx, linkId) {
|
|
1896
|
+
const opened = (links) => switchable(links.find((l) => l.id === linkId));
|
|
1897
|
+
if (!opened(state(ctx).links)) {
|
|
1898
|
+
const off = ctx.hub.onState((s) => {
|
|
1899
|
+
if (opened(s.links)) {
|
|
1900
|
+
stopWait(ctx, linkId);
|
|
1901
|
+
expire(ctx, linkId);
|
|
1902
|
+
}
|
|
1903
|
+
});
|
|
1904
|
+
timersOf(ctx).set(linkId, off);
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
releaseHold(ctx, linkId, "expired").catch((error) => process.stderr.write(`ghostly: the hold on ${linkId} could not end: ${error instanceof Error ? error.message : String(error)}\n`));
|
|
1908
|
+
}
|
|
1909
|
+
/** When the chat's hold ends, or null (its time is up, also while it waits for the chat to open: `expire`). */
|
|
1806
1910
|
function holdOf(ctx, linkId) {
|
|
1807
|
-
|
|
1911
|
+
const until = readHolds(ctx)[linkId]?.until;
|
|
1912
|
+
return until !== void 0 && until > Date.now() ? until : null;
|
|
1808
1913
|
}
|
|
1809
1914
|
/** Keeps the chat off its direct link for `minutes` (again: from now). */
|
|
1810
1915
|
async function holdChat(ctx, link, minutes) {
|
|
@@ -1840,8 +1945,7 @@ async function holdChat(ctx, link, minutes) {
|
|
|
1840
1945
|
async function releaseHold(ctx, linkId, reason, chosen = false) {
|
|
1841
1946
|
const holds = readHolds(ctx);
|
|
1842
1947
|
if (!holds[linkId]) return false;
|
|
1843
|
-
|
|
1844
|
-
timersOf(ctx).delete(linkId);
|
|
1948
|
+
stopWait(ctx, linkId);
|
|
1845
1949
|
const link = state(ctx).links.find((l) => l.id === linkId);
|
|
1846
1950
|
if (!chosen && link?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
|
|
1847
1951
|
linkId,
|
|
@@ -1871,6 +1975,22 @@ function isLive(link) {
|
|
|
1871
1975
|
if (link.textDelivery !== "stream" || link.dataLink !== "open") return false;
|
|
1872
1976
|
return !link.profile || link.pairing?.status === "ready" && !!link.pairing.transport;
|
|
1873
1977
|
}
|
|
1978
|
+
/**
|
|
1979
|
+
* The app's connection failure (ChatConnection's `connectionFailure`), with the relays' words made plain: the engine's
|
|
1980
|
+
* "Publish failed on every relay: Error: http://… responded 503" reads as the CLI failing, a class name per relay.
|
|
1981
|
+
*/
|
|
1982
|
+
function connectionError(link) {
|
|
1983
|
+
const pair = link.pairing;
|
|
1984
|
+
const dht = link.deliveryMode === "dht" || link.textDelivery === "dht";
|
|
1985
|
+
const detail = pair?.transitionError || (pair?.status === "error" ? pair.error : "") || (dht ? link.dhtDelivery?.error : "");
|
|
1986
|
+
if (!detail) return null;
|
|
1987
|
+
const at = detail.indexOf("Publish failed on every relay:");
|
|
1988
|
+
if (at < 0) return detail;
|
|
1989
|
+
const tail = detail.slice(at);
|
|
1990
|
+
const hosts = [...new Set([...tail.matchAll(/\bhttps?:\/\/[^\s;,]+/g)].map(([url]) => URL.canParse(url) ? new URL(url).host : url))];
|
|
1991
|
+
const said = / responded \d{3}\b/.test(tail) ? `${at ? "n" : "N"}o relay took it` : `${at ? "n" : "N"}o relay answered`;
|
|
1992
|
+
return `${detail.slice(0, at)}${said}${hosts.length ? ` (${hosts.join(", ")})` : ""}`;
|
|
1993
|
+
}
|
|
1874
1994
|
function chatJson(link, showSecret) {
|
|
1875
1995
|
const label = link.label?.trim() || null;
|
|
1876
1996
|
const peerName = link.peerNick?.trim() || null;
|
|
@@ -1882,11 +2002,12 @@ function chatJson(link, showSecret) {
|
|
|
1882
2002
|
peerName,
|
|
1883
2003
|
peer: link.peerPubKeyZ32,
|
|
1884
2004
|
createdAt: link.createdAt,
|
|
1885
|
-
lastMessageAt: link.lastMessageAt,
|
|
2005
|
+
lastMessageAt: link.lastMessageAt || null,
|
|
1886
2006
|
live,
|
|
1887
2007
|
transport: live ? link.pairing?.transport ?? link.pairingProgress?.transport ?? null : null,
|
|
1888
2008
|
text: link.textDelivery ?? (link.profile ? "unavailable" : "dht"),
|
|
1889
2009
|
pairing: link.pairing?.status ?? null,
|
|
2010
|
+
connectionError: connectionError(link),
|
|
1890
2011
|
stage: link.pairingProgress?.stage ?? null,
|
|
1891
2012
|
verified: !!link.peerVerified,
|
|
1892
2013
|
invite: link.pairing?.status === "ready" || !link.inviteCode ? null : showSecret === true ? link.inviteCode : "<hidden>",
|
|
@@ -2059,7 +2180,7 @@ function groupJson(group, showSecret = false) {
|
|
|
2059
2180
|
me: group.myKey ?? null,
|
|
2060
2181
|
canSend: group.canSend,
|
|
2061
2182
|
link: group.entryLink ? showSecret ? group.entryLink : "<hidden>" : null,
|
|
2062
|
-
lastMessageAt: group.lastMessageAt,
|
|
2183
|
+
lastMessageAt: group.lastMessageAt || null,
|
|
2063
2184
|
members: group.members.map((m) => ({
|
|
2064
2185
|
key: m.key,
|
|
2065
2186
|
name: m.nick ?? null,
|
|
@@ -2136,7 +2257,9 @@ async function pictureFrom(path) {
|
|
|
2136
2257
|
}
|
|
2137
2258
|
const url = `data:image/jpeg;base64,${(parts ? Buffer.concat(parts) : bytes).toString("base64")}`;
|
|
2138
2259
|
const checked = sanitizeAvatar(url);
|
|
2139
|
-
|
|
2260
|
+
const bounds = `a JPEG of at most 512×512 px and about ${Math.floor(MAX_AVATAR_LENGTH * .74 / 1e3)} KB (128×128 is what the app sends)`;
|
|
2261
|
+
if (!checked && !(bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255)) throw new CliError("bad_request", `${path} is not a JPEG: convert it to ${bounds}`);
|
|
2262
|
+
if (!checked) throw new CliError("bad_request", `A picture is ${bounds}: resize it first`);
|
|
2140
2263
|
return checked;
|
|
2141
2264
|
}
|
|
2142
2265
|
async function picture(params) {
|
|
@@ -2189,9 +2312,7 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2189
2312
|
},
|
|
2190
2313
|
async "group.rename"(ctx, params) {
|
|
2191
2314
|
const group = groupOf(ctx, params, "chat rename <chat> <name...>");
|
|
2192
|
-
const
|
|
2193
|
-
const name = clean && groupName(clean);
|
|
2194
|
-
if (!name) throw new CliError("bad_request", `A group's name is 1 to 64 characters on one line`);
|
|
2315
|
+
const name = groupNameOf(params);
|
|
2195
2316
|
guardText(name, bool(params, "force"), "group's name", "rename it");
|
|
2196
2317
|
await node(ctx).renameGroup({
|
|
2197
2318
|
groupId: group.id,
|
|
@@ -2706,6 +2827,11 @@ function sameSecret(a, b) {
|
|
|
2706
2827
|
*/
|
|
2707
2828
|
var OPENED_SERVICE_CSP = "default-src 'self' https: data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; form-action 'self'";
|
|
2708
2829
|
/**
|
|
2830
|
+
* The policy while Hide my IP from contacts is on (`relayOnly`): no `https:`, so the page loads nothing but its own
|
|
2831
|
+
* origin. A picture or script from a server the contact names would show that server this machine's address.
|
|
2832
|
+
*/
|
|
2833
|
+
var OPENED_SERVICE_CSP_RELAY_ONLY = "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; form-action 'self'";
|
|
2834
|
+
/**
|
|
2709
2835
|
* The contact's headers that are not passed on: each makes the browser send something to a place it names, outside
|
|
2710
2836
|
* `connect-src` (violation and network-error reports, and the endpoints they go to; `Link` preloads, prefetches and
|
|
2711
2837
|
* early connections). Only the contact's server is reached.
|
|
@@ -2723,6 +2849,8 @@ var OPENED_SERVICE_DROPPED_DIRECTIVES = ["report-uri", "report-to"];
|
|
|
2723
2849
|
function withoutReports(value) {
|
|
2724
2850
|
return value.split(",").map((policy) => policy.split(";").filter((directive) => !OPENED_SERVICE_DROPPED_DIRECTIVES.includes(directive.trim().split(/\s+/)[0].toLowerCase())).join(";").trim()).filter((policy) => policy.replaceAll(";", "").trim()).join(", ");
|
|
2725
2851
|
}
|
|
2852
|
+
/** `service open` while Hide my IP from contacts is on (as the browser extension refuses to open one). */
|
|
2853
|
+
var SERVICE_OPEN_OFF_RELAY_ONLY = "A contact's app does not open here while Hide my IP from contacts is on: a browser tab cannot keep its page off WebRTC";
|
|
2726
2854
|
function plain(response, status, text, headers = {}) {
|
|
2727
2855
|
response.writeHead(status, {
|
|
2728
2856
|
"content-type": "text/plain; charset=utf-8",
|
|
@@ -2736,8 +2864,10 @@ function plain(response, status, text, headers = {}) {
|
|
|
2736
2864
|
* cookies and storage are its own, apart from any other app on 127.0.0.1 or localhost, and a name that merely
|
|
2737
2865
|
* resolves here (DNS rebinding) is not it. Only a browser given the link (which sets `OPEN_COOKIE`) is served; anyone
|
|
2738
2866
|
* else on this machine who finds the port gets 404. The body streams through, bounded by `MAX_RESPONSE_BYTES`.
|
|
2867
|
+
* `relayOnly`: Hide my IP from contacts was on when it opened (`OPENED_SERVICE_CSP_RELAY_ONLY`).
|
|
2739
2868
|
*/
|
|
2740
|
-
async function openServiceServer(send, port = 0) {
|
|
2869
|
+
async function openServiceServer(send, port = 0, { relayOnly = false } = {}) {
|
|
2870
|
+
const policy = relayOnly ? OPENED_SERVICE_CSP_RELAY_ONLY : OPENED_SERVICE_CSP;
|
|
2741
2871
|
const name = `${randomBytes(16).toString("hex")}.localhost`;
|
|
2742
2872
|
const token = randomBytes(32).toString("hex");
|
|
2743
2873
|
const cookies = /* @__PURE__ */ new Set();
|
|
@@ -2768,7 +2898,7 @@ async function openServiceServer(send, port = 0) {
|
|
|
2768
2898
|
chunks.push(chunk);
|
|
2769
2899
|
});
|
|
2770
2900
|
request.on("end", () => {
|
|
2771
|
-
if (!refused) proxy(request, response, chunks, send, cookies);
|
|
2901
|
+
if (!refused) proxy(request, response, chunks, send, cookies, policy);
|
|
2772
2902
|
});
|
|
2773
2903
|
});
|
|
2774
2904
|
await new Promise((resolve, reject) => {
|
|
@@ -2785,7 +2915,7 @@ async function openServiceServer(send, port = 0) {
|
|
|
2785
2915
|
url: `http://${host}${OPEN_PATH}${token}`
|
|
2786
2916
|
};
|
|
2787
2917
|
}
|
|
2788
|
-
async function proxy(request, response, chunks, send, cookies) {
|
|
2918
|
+
async function proxy(request, response, chunks, send, cookies, policy) {
|
|
2789
2919
|
const stop = new AbortController();
|
|
2790
2920
|
response.on("close", () => {
|
|
2791
2921
|
if (!response.writableFinished) stop.abort();
|
|
@@ -2818,7 +2948,7 @@ async function proxy(request, response, chunks, send, cookies) {
|
|
|
2818
2948
|
if (policy) out[lower] = [...out[lower] ?? [], policy];
|
|
2819
2949
|
} else out[lower] = value;
|
|
2820
2950
|
}
|
|
2821
|
-
out["content-security-policy"] = [...out["content-security-policy"] ?? [],
|
|
2951
|
+
out["content-security-policy"] = [...out["content-security-policy"] ?? [], policy];
|
|
2822
2952
|
response.writeHead(answer.status, out);
|
|
2823
2953
|
await pipeline(Readable.from(answer.body, { objectMode: false }), response);
|
|
2824
2954
|
} catch (error) {
|
|
@@ -2933,6 +3063,7 @@ var SERVICE_METHODS = {
|
|
|
2933
3063
|
/** A contact's shared app on a loopback port of this machine, as the Desktop opens it in a window. */
|
|
2934
3064
|
async "service.open"(ctx, params) {
|
|
2935
3065
|
if (ctx.mode !== "daemon") throw new CliError("unavailable", "An opened service lives in the daemon: start `ghostly daemon --detach` first");
|
|
3066
|
+
if (state(ctx).settings?.relayOnly === true) throw new CliError("unavailable", SERVICE_OPEN_OFF_RELAY_ONLY);
|
|
2936
3067
|
const link = chatOf(ctx, params);
|
|
2937
3068
|
const service = str(params, "service", true);
|
|
2938
3069
|
const key = `${link.peerPubKeyZ32}/${service}`;
|
|
@@ -3360,7 +3491,7 @@ function walletJson(instance, s) {
|
|
|
3360
3491
|
break;
|
|
3361
3492
|
case "lightning": {
|
|
3362
3493
|
const card = view?.lightnings?.find((c) => c.card === instance.card);
|
|
3363
|
-
balance = card?.balance ?? null;
|
|
3494
|
+
balance = (card?.providerId === "cashu-mint" ? view?.balance : card?.balance) ?? null;
|
|
3364
3495
|
status = card?.status ?? null;
|
|
3365
3496
|
error = card?.error ?? null;
|
|
3366
3497
|
break;
|
|
@@ -3451,10 +3582,13 @@ function badMintUrl(error) {
|
|
|
3451
3582
|
const code = error instanceof Error ? error.engineCode : void 0;
|
|
3452
3583
|
return code === "invalidMintUrl" || code === "mintNotHttps";
|
|
3453
3584
|
}
|
|
3585
|
+
/** What the engine's faucet says with no test mint to ask. */
|
|
3586
|
+
var NO_TEST_MINT = /^The faucet did not pay: This wallet has no test mint\b/;
|
|
3454
3587
|
/**
|
|
3455
3588
|
* The engine's wallet refusals about what the person asked, by the words it writes (they carry no `engineCode`): a
|
|
3456
3589
|
* wallet or card that is not there, a token or invoice that is not one, a wallet already made, no mint or source to do
|
|
3457
|
-
* it with. Before, each was `engine` (exit 1), which a bot reads as the engine failing and may retry.
|
|
3590
|
+
* it with. Before, each was `engine` (exit 1), which a bot reads as the engine failing and may retry. With no wallet of
|
|
3591
|
+
* the type at all, `wallet faucet`, `wallet receive` and `wallet address` say which to make first (`noWalletOf`).
|
|
3458
3592
|
*/
|
|
3459
3593
|
var WALLET_REFUSALS = [
|
|
3460
3594
|
[/^There is no .+ to remove$/, "not_found"],
|
|
@@ -3463,23 +3597,38 @@ var WALLET_REFUSALS = [
|
|
|
3463
3597
|
[/^You already have a .+ wallet$/, "refused"],
|
|
3464
3598
|
[/^No mint could create an invoice: No mint configured$/, "unavailable"],
|
|
3465
3599
|
[/^No Bitcoin source is set up$/, "unavailable"],
|
|
3466
|
-
[
|
|
3467
|
-
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"]
|
|
3600
|
+
[NO_TEST_MINT, "unavailable"],
|
|
3601
|
+
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"],
|
|
3602
|
+
[/^Nothing to (reclaim|take back)$/, "refused"],
|
|
3603
|
+
[/^This request is no longer open$/, "refused"],
|
|
3604
|
+
[/^This invoice is already paid$/, "refused"]
|
|
3468
3605
|
];
|
|
3606
|
+
var WALLET_NAMES = {
|
|
3607
|
+
cashu: "Cashu",
|
|
3608
|
+
lightning: "Lightning",
|
|
3609
|
+
arkade: "Arkade",
|
|
3610
|
+
bark: "Bark",
|
|
3611
|
+
spark: "Spark",
|
|
3612
|
+
bitcoin: "Bitcoin",
|
|
3613
|
+
fedimint: "Fedimint",
|
|
3614
|
+
usdt: "USDT"
|
|
3615
|
+
};
|
|
3469
3616
|
/**
|
|
3470
|
-
*
|
|
3471
|
-
*
|
|
3472
|
-
*
|
|
3617
|
+
* A request refused for want of a wallet of that type and network at all: `chat pay`, `chat request`, `wallet receive`
|
|
3618
|
+
* and the Cashu faucet with no Cashu wallet, an address with no wallet of its type. The engine says the wallet is short
|
|
3619
|
+
* of sats, that it has no mint or source, and names nothing to do. `refused` with the command that makes one, as a
|
|
3620
|
+
* contact with no wallet is told; `details.reason` `no_wallet`. With a wallet, the engine's own words.
|
|
3473
3621
|
*/
|
|
3474
|
-
function noWalletOf(ctx, n, error) {
|
|
3475
|
-
if ((state(ctx).wallet.wallets ?? []).some((w) => w.type ===
|
|
3476
|
-
return new CliError("refused", `You have no ${n === "mainnet" ? "Mainnet" : "Testnet"}
|
|
3622
|
+
function noWalletOf(ctx, n, error, type = "cashu") {
|
|
3623
|
+
if ((state(ctx).wallet.wallets ?? []).some((w) => w.type === type && w.network === n)) return error;
|
|
3624
|
+
return new CliError("refused", `You have no ${n === "mainnet" ? "Mainnet" : "Testnet"} ${WALLET_NAMES[type]} wallet: ghostly wallet create ${type}${n === "mainnet" ? " --network mainnet" : ""}`, { reason: "no_wallet" });
|
|
3477
3625
|
}
|
|
3478
3626
|
var engineCode = (error) => error instanceof Error ? error.engineCode : void 0;
|
|
3479
3627
|
/** What the engine says to a Cashu request it has no mint for: no mint for the invoice, or none to name for ecash. */
|
|
3480
3628
|
var NO_MINT = /^(No mint could create an invoice: No mint configured|You have no (Mainnet|Testnet) Cashu wallet: create one in Wallet → New)$/;
|
|
3481
3629
|
function walletRefusal(error) {
|
|
3482
3630
|
if (!(error instanceof Error) || error instanceof CliError) return error;
|
|
3631
|
+
if (error.name === "SwapUnsettledError") return new CliError("unavailable", error.message);
|
|
3483
3632
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
3484
3633
|
return code ? new CliError(code, error.message) : error;
|
|
3485
3634
|
}
|
|
@@ -3566,6 +3715,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3566
3715
|
type,
|
|
3567
3716
|
network: "testnet",
|
|
3568
3717
|
...card ? { card } : {}
|
|
3718
|
+
}).catch((error) => {
|
|
3719
|
+
throw error instanceof Error && NO_TEST_MINT.test(error.message) ? noWalletOf(ctx, "testnet", error) : error;
|
|
3569
3720
|
});
|
|
3570
3721
|
},
|
|
3571
3722
|
async "wallet.history"(ctx, params) {
|
|
@@ -3591,6 +3742,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3591
3742
|
amount,
|
|
3592
3743
|
network: n,
|
|
3593
3744
|
...card ? { card } : {}
|
|
3745
|
+
}).catch((error) => {
|
|
3746
|
+
throw error instanceof Error && NO_MINT.test(error.message) ? noWalletOf(ctx, n, error) : error;
|
|
3594
3747
|
});
|
|
3595
3748
|
return {
|
|
3596
3749
|
network: n,
|
|
@@ -3607,11 +3760,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3607
3760
|
if (type === "bitcoin") return {
|
|
3608
3761
|
type,
|
|
3609
3762
|
network: n,
|
|
3610
|
-
address: await node(ctx).bitcoinReceiveAddress({ network: n })
|
|
3763
|
+
address: await node(ctx).bitcoinReceiveAddress({ network: n }).catch((error) => {
|
|
3764
|
+
throw error instanceof Error && /^No Bitcoin source is set up$/.test(error.message) ? noWalletOf(ctx, n, error, "bitcoin") : error;
|
|
3765
|
+
})
|
|
3611
3766
|
};
|
|
3612
3767
|
const view = netView(state(ctx), n);
|
|
3613
3768
|
const address = type === "arkade" ? view?.ark?.address : type === "spark" ? view?.spark?.address : view?.usdt?.address;
|
|
3614
|
-
if (!address) throw new CliError("unavailable", `No ${type} wallet with an address on ${n}`);
|
|
3769
|
+
if (!address) throw noWalletOf(ctx, n, new CliError("unavailable", `No ${type} wallet with an address on ${n}`), type);
|
|
3615
3770
|
return {
|
|
3616
3771
|
type,
|
|
3617
3772
|
network: n,
|
|
@@ -3821,7 +3976,9 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3821
3976
|
},
|
|
3822
3977
|
async "payment.check"(ctx, params) {
|
|
3823
3978
|
const link = chatOf(ctx, params);
|
|
3824
|
-
|
|
3979
|
+
const p = state(ctx).payments[str(params, "payment", true)];
|
|
3980
|
+
if (p?.linkId !== link.id) throw new CliError("not_found", `No payment ${JSON.stringify(str(params, "payment", true))} in this chat (ghostly payment list --chat ${link.id})`);
|
|
3981
|
+
if (p.kind !== "request" || p.direction !== "in") throw new CliError("bad_request", `${JSON.stringify(p.id)} is ${p.kind === "request" ? "your own request" : p.direction === "out" ? "a payment you sent" : "a payment you received"}: payment check is for a request the contact made of you`);
|
|
3825
3982
|
await node(ctx).checkPayment({
|
|
3826
3983
|
linkId: link.id,
|
|
3827
3984
|
paymentId: str(params, "payment", true)
|
|
@@ -3889,7 +4046,7 @@ function redactSettings(settings, showSecret = false) {
|
|
|
3889
4046
|
};
|
|
3890
4047
|
}
|
|
3891
4048
|
/** Settings a command may change; the rest are the app's to manage. */
|
|
3892
|
-
var
|
|
4049
|
+
var SETTABLE_KINDS = {
|
|
3893
4050
|
relays: "strings",
|
|
3894
4051
|
irohRelays: "strings",
|
|
3895
4052
|
hyperdhtRelay: "string",
|
|
@@ -3902,6 +4059,30 @@ var SETTABLE = {
|
|
|
3902
4059
|
autoDownloads: "boolean",
|
|
3903
4060
|
serveFiles: "boolean"
|
|
3904
4061
|
};
|
|
4062
|
+
var SETTABLE = SETTABLE_KINDS;
|
|
4063
|
+
/**
|
|
4064
|
+
* What a setting of the table reads as while the engine keeps none (types.ts `Settings`): a switch that is on and the
|
|
4065
|
+
* default relays are kept as absent (node.ts `updateSettings` deletes `sendTyping: true`, an empty `irohRelays`...).
|
|
4066
|
+
* Every key of the table the engine may leave out needs one here, or tsc fails.
|
|
4067
|
+
*/
|
|
4068
|
+
var SETTING_DEFAULTS = {
|
|
4069
|
+
irohRelays: () => [...DEFAULT_IROH_RELAYS],
|
|
4070
|
+
hyperdhtRelay: () => "",
|
|
4071
|
+
publicProfiles: () => true,
|
|
4072
|
+
shareProfile: () => true,
|
|
4073
|
+
sendTyping: () => true,
|
|
4074
|
+
autoDownloads: () => true,
|
|
4075
|
+
serveFiles: () => true
|
|
4076
|
+
};
|
|
4077
|
+
/**
|
|
4078
|
+
* The settings as `settings get` and `settings set` answer them: each key `settings set` takes, with its value in
|
|
4079
|
+
* effect. Before, a switch that is on (absent as kept) was never shown, and a fresh profile showed 4 of the 11 keys.
|
|
4080
|
+
*/
|
|
4081
|
+
function settingsInEffect(settings) {
|
|
4082
|
+
const filled = { ...settings };
|
|
4083
|
+
for (const key of Object.keys(SETTABLE_KINDS)) if (filled[key] === void 0 && Object.hasOwn(SETTING_DEFAULTS, key)) filled[key] = SETTING_DEFAULTS[key]();
|
|
4084
|
+
return filled;
|
|
4085
|
+
}
|
|
3905
4086
|
/**
|
|
3906
4087
|
* A relay address the engine refuses (node.ts `updateSettings`, irohWeb.ts, hyperdhtRelay.ts): the person's value, so
|
|
3907
4088
|
* `bad_request` named by its key, in a terminal's words ("give", not the app's "Enter"). Before, `engine` (exit 1). A
|
|
@@ -3919,7 +4100,7 @@ function relayRefused(error, patch) {
|
|
|
3919
4100
|
/** The engine keeps a chat's name to 48 characters (code points: `renameLink`). */
|
|
3920
4101
|
var CHAT_NAME_LENGTH = 48;
|
|
3921
4102
|
/**
|
|
3922
|
-
* A chat's name on this side (`chat rename`, an invite's `--label`), as the engine stores it (`
|
|
4103
|
+
* A chat's name on this side (`chat rename`, an invite's `--label`), as the engine stores it (`shownName`): a tab or a
|
|
3923
4104
|
* line break is a space, invisible characters go, and what is left is counted. Longer than the engine keeps whole is
|
|
3924
4105
|
* refused, not cut. An empty name (or spaces) is the documented one of `chat rename` (the contact's own name) and no
|
|
3925
4106
|
* label for an invite; a name with nothing that shows is refused: given as is, the engine cleared the chat's name. A
|
|
@@ -3928,9 +4109,7 @@ var CHAT_NAME_LENGTH = 48;
|
|
|
3928
4109
|
function chatName(params, name) {
|
|
3929
4110
|
const value = str(params, name);
|
|
3930
4111
|
if (value === void 0 || !value.trim()) return value === void 0 ? void 0 : "";
|
|
3931
|
-
const clean =
|
|
3932
|
-
if (clean === void 0) throw new CliError("bad_request", `A chat's name is up to ${CHAT_NAME_LENGTH} characters on one line`);
|
|
3933
|
-
if (!clean) throw new CliError("bad_request", `A chat's name needs a character that shows (an empty name gives back the contact's own)`);
|
|
4112
|
+
const clean = shownName(value, CHAT_NAME_LENGTH, "A chat's name", " (an empty name gives back the contact's own)");
|
|
3934
4113
|
if (groupPrefixed(clean) !== null) throw new CliError("bad_request", `A chat's name can't start with "group:": that names a group`);
|
|
3935
4114
|
return clean;
|
|
3936
4115
|
}
|
|
@@ -4065,6 +4244,32 @@ var METHODS = {
|
|
|
4065
4244
|
...ctx.listen && { listen: true }
|
|
4066
4245
|
};
|
|
4067
4246
|
},
|
|
4247
|
+
/**
|
|
4248
|
+
* This profile's status (WISP 401 § Presence and status), said to every paired contact whose app offers `status/1`:
|
|
4249
|
+
* at once on a live session, else on each chat's next one. A new one replaces the one before, whole.
|
|
4250
|
+
*/
|
|
4251
|
+
async "status.get"(ctx) {
|
|
4252
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4253
|
+
},
|
|
4254
|
+
async "status.set"(ctx, params) {
|
|
4255
|
+
const until = params.until === void 0 ? void 0 : num(params, "until", 0, {
|
|
4256
|
+
min: 1,
|
|
4257
|
+
whole: true
|
|
4258
|
+
});
|
|
4259
|
+
const status = checkOwnStatus({
|
|
4260
|
+
text: str(params, "text"),
|
|
4261
|
+
emoji: str(params, "emoji"),
|
|
4262
|
+
availability: str(params, "availability"),
|
|
4263
|
+
until
|
|
4264
|
+
}, (field) => field, "bad_request");
|
|
4265
|
+
guardText(status.text, bool(params, "force"), "status", "set it");
|
|
4266
|
+
await node(ctx).setOwnStatus({ status });
|
|
4267
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4268
|
+
},
|
|
4269
|
+
async "status.clear"(ctx) {
|
|
4270
|
+
await node(ctx).clearOwnStatus();
|
|
4271
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4272
|
+
},
|
|
4068
4273
|
async "profile.get"(ctx) {
|
|
4069
4274
|
const { settings } = state(ctx);
|
|
4070
4275
|
return {
|
|
@@ -4084,7 +4289,7 @@ var METHODS = {
|
|
|
4084
4289
|
return METHODS["profile.get"](ctx, {});
|
|
4085
4290
|
},
|
|
4086
4291
|
async "settings.get"(ctx, params) {
|
|
4087
|
-
return redactSettings(state(ctx).settings, bool(params, "showSecret"));
|
|
4292
|
+
return redactSettings(settingsInEffect(state(ctx).settings), bool(params, "showSecret"));
|
|
4088
4293
|
},
|
|
4089
4294
|
async "settings.set"(ctx, params) {
|
|
4090
4295
|
const patch = {};
|
|
@@ -4121,7 +4326,7 @@ var METHODS = {
|
|
|
4121
4326
|
throw relayRefused(error, patch);
|
|
4122
4327
|
});
|
|
4123
4328
|
return {
|
|
4124
|
-
...redactSettings(state(ctx).settings),
|
|
4329
|
+
...redactSettings(settingsInEffect(state(ctx).settings)),
|
|
4125
4330
|
...warning ? { warning } : {}
|
|
4126
4331
|
};
|
|
4127
4332
|
},
|
|
@@ -4178,7 +4383,7 @@ var METHODS = {
|
|
|
4178
4383
|
},
|
|
4179
4384
|
async "chat.list"(ctx, params) {
|
|
4180
4385
|
const showSecret = bool(params, "showSecret");
|
|
4181
|
-
return { chats: state(ctx).links.map((link) => chatJson(link, showSecret)).sort((a, b) => b.lastMessageAt - a.lastMessageAt || b.createdAt - a.createdAt) };
|
|
4386
|
+
return { chats: state(ctx).links.map((link) => chatJson(link, showSecret)).sort((a, b) => (b.lastMessageAt ?? 0) - (a.lastMessageAt ?? 0) || b.createdAt - a.createdAt) };
|
|
4182
4387
|
},
|
|
4183
4388
|
async "chat.get"(ctx, params) {
|
|
4184
4389
|
const link = chatNotGroup(ctx, params, "group show");
|
|
@@ -4199,11 +4404,12 @@ var METHODS = {
|
|
|
4199
4404
|
const secret = findSecret(text);
|
|
4200
4405
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; send it with --force if you mean to`, { kind: secret.kind });
|
|
4201
4406
|
}
|
|
4407
|
+
const unjoined = nobodyJoined(link);
|
|
4202
4408
|
const wait = oneOf(params, "wait", [
|
|
4203
4409
|
"none",
|
|
4204
4410
|
"sent",
|
|
4205
4411
|
"delivered"
|
|
4206
|
-
], "none");
|
|
4412
|
+
], ctx.mode === "one-shot" && !unjoined ? "sent" : "none");
|
|
4207
4413
|
const ms = num(params, "timeout", 30, {
|
|
4208
4414
|
min: 1,
|
|
4209
4415
|
max: 3600
|
|
@@ -4217,7 +4423,10 @@ var METHODS = {
|
|
|
4217
4423
|
...replyTo ? { replyTo } : {},
|
|
4218
4424
|
...card ? { card } : {}
|
|
4219
4425
|
});
|
|
4220
|
-
if (result.error) throw
|
|
4426
|
+
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
4427
|
+
group: false,
|
|
4428
|
+
ref: str(params, "chat", true)
|
|
4429
|
+
}) || (/not in this chat|cannot be replied to/.test(result.error) ? new CliError("not_found", result.error) : new CliError(result.refused ? "refused" : "unavailable", result.error));
|
|
4221
4430
|
if (!result.messageId) throw new CliError("bad_request", "Nothing to send");
|
|
4222
4431
|
let message = await node(ctx).getMessage(link.id, result.messageId);
|
|
4223
4432
|
if (wait !== "none") message = await waitForMessage(ctx, link.id, result.messageId, wait, ms);
|
|
@@ -4229,7 +4438,8 @@ var METHODS = {
|
|
|
4229
4438
|
buttons: card.id,
|
|
4230
4439
|
card,
|
|
4231
4440
|
pressable: pressable(link)
|
|
4232
|
-
} : {}
|
|
4441
|
+
} : {},
|
|
4442
|
+
...unjoined && message?.delivery === "waiting" && { note: `Nobody joined this chat yet: the message goes once they join${ctx.mode === "one-shot" ? " while this profile is online (`ghostly daemon --detach`)" : ""}` }
|
|
4233
4443
|
};
|
|
4234
4444
|
},
|
|
4235
4445
|
/**
|
|
@@ -4244,25 +4454,26 @@ var METHODS = {
|
|
|
4244
4454
|
const secret = findSecret(text);
|
|
4245
4455
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; edit with --force if you mean to`, { kind: secret.kind });
|
|
4246
4456
|
}
|
|
4247
|
-
const wait =
|
|
4248
|
-
const ms = num(params, "timeout", 30, {
|
|
4249
|
-
min: 1,
|
|
4250
|
-
max: 3600
|
|
4251
|
-
}) * 1e3;
|
|
4457
|
+
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
4252
4458
|
const result = await node(ctx).editMessage({
|
|
4253
4459
|
linkId: link.id,
|
|
4254
4460
|
messageId,
|
|
4255
4461
|
text
|
|
4256
4462
|
});
|
|
4257
|
-
if (result.error) throw editRefused(await messageOf(ctx, link.id, messageId), messageId,
|
|
4463
|
+
if (result.error) throw editRefused(await messageOf(ctx, link.id, messageId), messageId, {
|
|
4464
|
+
group: false,
|
|
4465
|
+
ref: str(params, "chat", true)
|
|
4466
|
+
}, result.error, result.refused);
|
|
4258
4467
|
const id = result.messageId ?? messageId;
|
|
4259
4468
|
let message = await node(ctx).getMessage(link.id, id);
|
|
4260
4469
|
if (wait === "confirmed" && message?.edit?.pending) message = await waitForEdit(ctx, link.id, id, ms);
|
|
4470
|
+
const confirmed = !!message && !message.edit?.pending;
|
|
4261
4471
|
return {
|
|
4262
4472
|
chat: link.id,
|
|
4263
4473
|
messageId: id,
|
|
4264
4474
|
edits: message?.edit?.seq ?? 0,
|
|
4265
|
-
confirmed
|
|
4475
|
+
confirmed,
|
|
4476
|
+
...!confirmed && keptForJoin(ctx, link.id, "the edit")
|
|
4266
4477
|
};
|
|
4267
4478
|
},
|
|
4268
4479
|
/**
|
|
@@ -4311,46 +4522,77 @@ var METHODS = {
|
|
|
4311
4522
|
*/
|
|
4312
4523
|
async "chat.react"(ctx, params) {
|
|
4313
4524
|
const link = chatNotGroup(ctx, params, "group react", "<message> <emoji>");
|
|
4314
|
-
const { wait, ms } = confirmWait(ctx, params);
|
|
4525
|
+
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
4315
4526
|
const before = Math.max(...node(ctx).chatUnconfirmed({ linkId: link.id }).reactions);
|
|
4316
|
-
const result = await react(ctx, link.id, params
|
|
4527
|
+
const result = await react(ctx, link.id, params, {
|
|
4528
|
+
group: false,
|
|
4529
|
+
ref: str(params, "chat", true)
|
|
4530
|
+
});
|
|
4317
4531
|
const pending = (left) => left.reactions.some((n) => n > before);
|
|
4318
4532
|
if (wait === "confirmed") await waitForConfirmed(ctx, link.id, "reaction", pending, ms);
|
|
4533
|
+
const confirmed = !pending(node(ctx).chatUnconfirmed({ linkId: link.id }));
|
|
4319
4534
|
return {
|
|
4320
4535
|
chat: link.id,
|
|
4321
4536
|
...result,
|
|
4322
|
-
confirmed
|
|
4537
|
+
confirmed,
|
|
4538
|
+
...!confirmed && keptForJoin(ctx, link.id, "the reaction")
|
|
4323
4539
|
};
|
|
4324
4540
|
},
|
|
4325
4541
|
/**
|
|
4326
4542
|
* WISP 400 § Pinned message: one per chat or group, a new pin replaces it; `remove` unpins. In a community only the
|
|
4327
4543
|
* admin pins. Answers the chat (or group) and the message now pinned (null once unpinned). In a 1:1 chat `wait:
|
|
4328
|
-
* confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has.
|
|
4544
|
+
* confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has. A
|
|
4545
|
+
* group has no receipts: `wait: sent` (a one-shot's default) stays until an edge took it, and `edges` and `sent` say
|
|
4546
|
+
* how many did, as for `group react`.
|
|
4329
4547
|
*/
|
|
4330
4548
|
async "chat.pin"(ctx, params) {
|
|
4331
4549
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4332
4550
|
const remove = bool(params, "remove"), messageId = remove ? str(params, "message") : str(params, "message", true);
|
|
4333
|
-
if (target.group && params.wait === "confirmed") throw new CliError("bad_request", "A group has no receipts: wait confirmed is for a 1:1 chat");
|
|
4334
|
-
|
|
4551
|
+
if (target.group && params.wait === "confirmed") throw new CliError("bad_request", "A group has no receipts: wait confirmed is for a 1:1 chat (wait sent waits until a member's edge took it)");
|
|
4552
|
+
if (!target.group && params.wait === "sent") throw new CliError("bad_request", "wait sent is for a group: a 1:1 chat's pin waits with wait confirmed");
|
|
4553
|
+
const { wait, ms } = target.group ? {
|
|
4554
|
+
wait: oneOf(params, "wait", ["none", "sent"], ctx.mode === "one-shot" ? "sent" : "none"),
|
|
4555
|
+
ms: num(params, "timeout", 30, {
|
|
4556
|
+
min: 1,
|
|
4557
|
+
max: 3600
|
|
4558
|
+
}) * 1e3
|
|
4559
|
+
} : confirmWait(ctx, params, target.linkId);
|
|
4335
4560
|
const result = await node(ctx).pinMessage({
|
|
4336
4561
|
linkId: target.linkId,
|
|
4337
4562
|
...messageId && { messageId },
|
|
4338
4563
|
remove
|
|
4339
4564
|
});
|
|
4565
|
+
const gone = result.error && messageId ? notHere(result.error, messageId, {
|
|
4566
|
+
group: target.group,
|
|
4567
|
+
ref: str(params, "chat", true)
|
|
4568
|
+
}) : void 0;
|
|
4569
|
+
if (gone) throw gone;
|
|
4340
4570
|
if (result.error) throw new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this (?:chat|group)|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
|
|
4341
|
-
if (target.group)
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4571
|
+
if (target.group) {
|
|
4572
|
+
const n = result.n, pinned = remove ? null : messageId;
|
|
4573
|
+
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, target.id, messageId ?? "", { pin: n }, ms) : node(ctx).groupTaken({
|
|
4574
|
+
groupId: target.id,
|
|
4575
|
+
messageId: messageId ?? "",
|
|
4576
|
+
pin: n
|
|
4577
|
+
});
|
|
4578
|
+
return {
|
|
4579
|
+
group: target.id,
|
|
4580
|
+
messageId: pinned,
|
|
4581
|
+
removed: remove,
|
|
4582
|
+
sent: edges > 0,
|
|
4583
|
+
edges
|
|
4584
|
+
};
|
|
4585
|
+
}
|
|
4346
4586
|
const mine = node(ctx).chatUnconfirmed({ linkId: target.linkId }).pin;
|
|
4347
4587
|
const pending = (left) => mine !== null && left.pin === mine;
|
|
4348
4588
|
if (wait === "confirmed") await waitForConfirmed(ctx, target.linkId, "pin", pending, ms);
|
|
4589
|
+
const confirmed = !pending(node(ctx).chatUnconfirmed({ linkId: target.linkId }));
|
|
4349
4590
|
return {
|
|
4350
4591
|
chat: target.id,
|
|
4351
4592
|
messageId: remove ? null : messageId,
|
|
4352
4593
|
removed: remove,
|
|
4353
|
-
confirmed
|
|
4594
|
+
confirmed,
|
|
4595
|
+
...!confirmed && keptForJoin(ctx, target.linkId, remove ? "the unpin" : "the pin")
|
|
4354
4596
|
};
|
|
4355
4597
|
},
|
|
4356
4598
|
/** Saved messages: a mark on a message of a chat or a group, kept for this profile on this device; nothing is sent. */
|
|
@@ -4396,7 +4638,10 @@ var METHODS = {
|
|
|
4396
4638
|
const chosen = [];
|
|
4397
4639
|
for (const id of messageIds) {
|
|
4398
4640
|
const message = await node(ctx).getMessage(from.linkId, id);
|
|
4399
|
-
if (!message) throw
|
|
4641
|
+
if (!message) throw noMessage(id, {
|
|
4642
|
+
group: from.group,
|
|
4643
|
+
ref: str(params, "chat", true)
|
|
4644
|
+
});
|
|
4400
4645
|
chosen.push(message);
|
|
4401
4646
|
}
|
|
4402
4647
|
if (!bool(params, "force")) for (const message of chosen) {
|
|
@@ -4407,6 +4652,7 @@ var METHODS = {
|
|
|
4407
4652
|
});
|
|
4408
4653
|
}
|
|
4409
4654
|
const wait = oneOf(params, "wait", ["none", "sent"], "none");
|
|
4655
|
+
const groupWait = params.wait === void 0 && ctx.mode === "one-shot" ? "sent" : wait;
|
|
4410
4656
|
const ms = num(params, "timeout", 30, {
|
|
4411
4657
|
min: 1,
|
|
4412
4658
|
max: 3600
|
|
@@ -4428,11 +4674,19 @@ var METHODS = {
|
|
|
4428
4674
|
sent: result.sent,
|
|
4429
4675
|
error: result.error
|
|
4430
4676
|
}));
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4677
|
+
for (const [i, result] of out.entries()) if (to[i].group) {
|
|
4678
|
+
let edges;
|
|
4679
|
+
for (const messageId of result.messageIds) {
|
|
4680
|
+
const took = groupWait === "sent" ? await waitForGroupFrame(ctx, to[i].id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
4681
|
+
groupId: to[i].id,
|
|
4682
|
+
messageId
|
|
4683
|
+
});
|
|
4684
|
+
edges = Math.min(edges ?? took, took);
|
|
4435
4685
|
}
|
|
4686
|
+
result.edges = edges ?? 0;
|
|
4687
|
+
}
|
|
4688
|
+
if (wait === "sent") for (const [i, result] of out.entries()) for (const messageId of result.messageIds) {
|
|
4689
|
+
if (to[i].group) continue;
|
|
4436
4690
|
const sent = await node(ctx).getMessage(to[i].id, messageId);
|
|
4437
4691
|
if (sent?.file) await FILE_METHODS["file.wait"](ctx, {
|
|
4438
4692
|
chat: to[i].id,
|
|
@@ -4455,8 +4709,15 @@ var METHODS = {
|
|
|
4455
4709
|
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");
|
|
4456
4710
|
const messageId = str(params, "message", true);
|
|
4457
4711
|
const message = await node(ctx).getMessage(link.id, messageId);
|
|
4458
|
-
|
|
4459
|
-
|
|
4712
|
+
const place = {
|
|
4713
|
+
group: false,
|
|
4714
|
+
ref: str(params, "chat", true)
|
|
4715
|
+
};
|
|
4716
|
+
if (!message) throw noMessage(messageId, place);
|
|
4717
|
+
if (message.sender !== "me") throw noMessage(messageId, place, {
|
|
4718
|
+
whose: "of yours",
|
|
4719
|
+
tail: ": only your own messages are sent again"
|
|
4720
|
+
});
|
|
4460
4721
|
if (message.delivery === "delivered") throw new CliError("refused", "Nothing to send again: it was delivered");
|
|
4461
4722
|
await node(ctx).retryMessage({
|
|
4462
4723
|
linkId: link.id,
|
|
@@ -4483,7 +4744,13 @@ var METHODS = {
|
|
|
4483
4744
|
}) * 1e3;
|
|
4484
4745
|
const ref = str(params, "message", true);
|
|
4485
4746
|
const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
|
|
4486
|
-
if (!message) throw
|
|
4747
|
+
if (!message) throw noMessage(ref, {
|
|
4748
|
+
group: target.group,
|
|
4749
|
+
ref: str(params, "chat", true)
|
|
4750
|
+
}, {
|
|
4751
|
+
whose: "of yours",
|
|
4752
|
+
tail: ": only your own messages are deleted for everyone"
|
|
4753
|
+
});
|
|
4487
4754
|
const result = await node(ctx).removeMessage({
|
|
4488
4755
|
linkId: target.linkId,
|
|
4489
4756
|
messageId: message.id
|
|
@@ -4520,8 +4787,11 @@ var METHODS = {
|
|
|
4520
4787
|
const ref = str(params, "message") ?? "<message>";
|
|
4521
4788
|
const link = chatNotGroup(ctx, params, "message delete", `${/^[\w.:<>-]+$/.test(ref) ? ref : JSON.stringify(ref)} --everyone`);
|
|
4522
4789
|
const messageId = str(params, "message", true);
|
|
4523
|
-
if (!await node(ctx).getMessage(link.id, messageId)) throw
|
|
4524
|
-
|
|
4790
|
+
if (!await node(ctx).getMessage(link.id, messageId)) throw noMessage(messageId, {
|
|
4791
|
+
group: false,
|
|
4792
|
+
ref: str(params, "chat", true)
|
|
4793
|
+
});
|
|
4794
|
+
const { everyone } = node(ctx).deleteMessage({
|
|
4525
4795
|
linkId: link.id,
|
|
4526
4796
|
messageId
|
|
4527
4797
|
});
|
|
@@ -4529,17 +4799,21 @@ var METHODS = {
|
|
|
4529
4799
|
chat: link.id,
|
|
4530
4800
|
messageId,
|
|
4531
4801
|
deleted: messageId,
|
|
4532
|
-
everyone
|
|
4802
|
+
everyone
|
|
4533
4803
|
};
|
|
4534
4804
|
},
|
|
4535
4805
|
/** 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`. */
|
|
4536
4806
|
async "chat.details"(ctx, params) {
|
|
4537
4807
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4808
|
+
const messageId = str(params, "message", true);
|
|
4538
4809
|
const details = await node(ctx).messageDetails({
|
|
4539
4810
|
linkId: target.linkId,
|
|
4540
|
-
messageId
|
|
4811
|
+
messageId
|
|
4812
|
+
});
|
|
4813
|
+
if (!details) throw noMessage(messageId, {
|
|
4814
|
+
group: target.group,
|
|
4815
|
+
ref: str(params, "chat", true)
|
|
4541
4816
|
});
|
|
4542
|
-
if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this ${target.group ? "group" : "chat"}`);
|
|
4543
4817
|
return details;
|
|
4544
4818
|
},
|
|
4545
4819
|
async "chat.rename"(ctx, params) {
|
|
@@ -4556,6 +4830,7 @@ var METHODS = {
|
|
|
4556
4830
|
noCallOn(ctx, link.id, "remove the chat");
|
|
4557
4831
|
await node(ctx).removeLink({ linkId: link.id });
|
|
4558
4832
|
ctx.calls.forgetChat(link.id);
|
|
4833
|
+
ctx.groupAuto.forgetChat(link.id);
|
|
4559
4834
|
return { removed: link.id };
|
|
4560
4835
|
},
|
|
4561
4836
|
async "chat.transport"(ctx, params) {
|
|
@@ -4590,14 +4865,15 @@ var METHODS = {
|
|
|
4590
4865
|
*/
|
|
4591
4866
|
async "chat.disconnect"(ctx, params) {
|
|
4592
4867
|
const link = chatOf(ctx, params);
|
|
4593
|
-
|
|
4594
|
-
node(ctx).disconnect({ linkId: link.id });
|
|
4595
|
-
return chatJson(findChat(state(ctx).links, link.id));
|
|
4596
|
-
}
|
|
4597
|
-
const minutes = num(params, "hold", 0, {
|
|
4868
|
+
const minutes = params.hold === void 0 ? void 0 : num(params, "hold", 0, {
|
|
4598
4869
|
min: 0,
|
|
4599
4870
|
max: HOLD_MAX_MINUTES
|
|
4600
4871
|
});
|
|
4872
|
+
if (minutes !== 0) somebodyJoined(link);
|
|
4873
|
+
if (minutes === void 0) {
|
|
4874
|
+
node(ctx).disconnect({ linkId: link.id });
|
|
4875
|
+
return chatJson(findChat(state(ctx).links, link.id));
|
|
4876
|
+
}
|
|
4601
4877
|
if (minutes > 0) noCallOn(ctx, link.id, "hold the chat");
|
|
4602
4878
|
if (minutes === 0) await releaseHold(ctx, link.id, "lifted");
|
|
4603
4879
|
else await holdChat(ctx, link, minutes);
|
|
@@ -4636,9 +4912,7 @@ var METHODS = {
|
|
|
4636
4912
|
}, ms, `chat ${link.id} ${chatState(until).to}`));
|
|
4637
4913
|
},
|
|
4638
4914
|
async "group.create"(ctx, params) {
|
|
4639
|
-
const
|
|
4640
|
-
const name = clean && groupName(clean);
|
|
4641
|
-
if (!name) throw new CliError("bad_request", `A group's name is 1 to 64 characters on one line`);
|
|
4915
|
+
const name = groupNameOf(params);
|
|
4642
4916
|
guardText(name, bool(params, "force"), "group's name", "create it");
|
|
4643
4917
|
const profile = oneOf(params, "profile", ["community", "mesh"], "community");
|
|
4644
4918
|
const { groupId } = await node(ctx).createGroup({
|
|
@@ -4664,7 +4938,18 @@ var METHODS = {
|
|
|
4664
4938
|
},
|
|
4665
4939
|
async "group.list"(ctx, params) {
|
|
4666
4940
|
const showSecret = bool(params, "showSecret");
|
|
4667
|
-
return {
|
|
4941
|
+
return {
|
|
4942
|
+
groups: state(ctx).groups.map((g) => groupJson(g, showSecret)).sort((a, b) => (b.lastMessageAt ?? 0) - (a.lastMessageAt ?? 0)),
|
|
4943
|
+
autoJoin: ctx.groupAuto.get()
|
|
4944
|
+
};
|
|
4945
|
+
},
|
|
4946
|
+
/** Invitations over the chats named accepted by the daemon itself (`group auto on --from`); no argument: the setting. */
|
|
4947
|
+
async "group.auto"(ctx, params) {
|
|
4948
|
+
if (params.on === void 0) return { autoJoin: ctx.groupAuto.get() };
|
|
4949
|
+
return { autoJoin: ctx.groupAuto.set({
|
|
4950
|
+
on: bool(params, "on"),
|
|
4951
|
+
from: list(params, "from")
|
|
4952
|
+
}) };
|
|
4668
4953
|
},
|
|
4669
4954
|
async "group.get"(ctx, params) {
|
|
4670
4955
|
return groupJson(groupOf(ctx, params, "chat show <chat>"), bool(params, "showSecret"));
|
|
@@ -4697,7 +4982,10 @@ var METHODS = {
|
|
|
4697
4982
|
...replyTo ? { replyTo } : {},
|
|
4698
4983
|
...card ? { card } : {}
|
|
4699
4984
|
});
|
|
4700
|
-
if (result.error) throw
|
|
4985
|
+
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
4986
|
+
group: true,
|
|
4987
|
+
ref: str(params, "group", true)
|
|
4988
|
+
}) || (result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
4701
4989
|
const messageId = result.messageId ?? null;
|
|
4702
4990
|
const edges = messageId ? wait === "sent" ? await waitForGroupFrame(ctx, group.id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
4703
4991
|
groupId: group.id,
|
|
@@ -4741,7 +5029,10 @@ var METHODS = {
|
|
|
4741
5029
|
text,
|
|
4742
5030
|
...mentions.length ? { mentions } : {}
|
|
4743
5031
|
});
|
|
4744
|
-
if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId,
|
|
5032
|
+
if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId, {
|
|
5033
|
+
group: true,
|
|
5034
|
+
ref: str(params, "group", true)
|
|
5035
|
+
}, result.error, result.refused);
|
|
4745
5036
|
const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
|
|
4746
5037
|
if (edits === before) return {
|
|
4747
5038
|
group: group.id,
|
|
@@ -4764,11 +5055,31 @@ var METHODS = {
|
|
|
4764
5055
|
edges
|
|
4765
5056
|
};
|
|
4766
5057
|
},
|
|
5058
|
+
/**
|
|
5059
|
+
* WISP 400 § Reactions in a group, which has no receipts: `edges` says how many took it, `sent` whether one did.
|
|
5060
|
+
* `wait: sent` (a one-shot's default: what is not said yet leaves with the process) stays until an edge took it.
|
|
5061
|
+
*/
|
|
4767
5062
|
async "group.react"(ctx, params) {
|
|
4768
5063
|
const group = groupOf(ctx, params, "react <chat> <message> <emoji>");
|
|
5064
|
+
const wait = oneOf(params, "wait", ["none", "sent"], ctx.mode === "one-shot" ? "sent" : "none");
|
|
5065
|
+
const ms = num(params, "timeout", 30, {
|
|
5066
|
+
min: 1,
|
|
5067
|
+
max: 3600
|
|
5068
|
+
}) * 1e3;
|
|
5069
|
+
const { n, ...said } = await react(ctx, `group:${group.id}`, params, {
|
|
5070
|
+
group: true,
|
|
5071
|
+
ref: str(params, "group", true)
|
|
5072
|
+
});
|
|
5073
|
+
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, group.id, said.messageId, { reaction: n }, ms) : node(ctx).groupTaken({
|
|
5074
|
+
groupId: group.id,
|
|
5075
|
+
messageId: said.messageId,
|
|
5076
|
+
reaction: n
|
|
5077
|
+
});
|
|
4769
5078
|
return {
|
|
4770
5079
|
group: group.id,
|
|
4771
|
-
...
|
|
5080
|
+
...said,
|
|
5081
|
+
sent: edges > 0,
|
|
5082
|
+
edges
|
|
4772
5083
|
};
|
|
4773
5084
|
},
|
|
4774
5085
|
/**
|
|
@@ -4838,7 +5149,7 @@ var METHODS = {
|
|
|
4838
5149
|
},
|
|
4839
5150
|
async "events.replay"(ctx, params) {
|
|
4840
5151
|
return {
|
|
4841
|
-
events: ctx.hub.replay(
|
|
5152
|
+
events: ctx.hub.replay(sinceSeq(params, 0)),
|
|
4842
5153
|
lastSeq: ctx.hub.lastSeq
|
|
4843
5154
|
};
|
|
4844
5155
|
},
|
|
@@ -4881,7 +5192,10 @@ var METHODS = {
|
|
|
4881
5192
|
if (typeof target !== "function") throw new CliError("not_found", `The engine has no call ${method}`);
|
|
4882
5193
|
try {
|
|
4883
5194
|
const result = await target.call(node(ctx), args) ?? null;
|
|
4884
|
-
if (method === "removeLink")
|
|
5195
|
+
if (method === "removeLink") {
|
|
5196
|
+
ctx.calls.forgetChat(str(args ?? {}, "linkId", true));
|
|
5197
|
+
ctx.groupAuto.forgetChat(str(args ?? {}, "linkId", true));
|
|
5198
|
+
}
|
|
4885
5199
|
return result;
|
|
4886
5200
|
} catch (error) {
|
|
4887
5201
|
if (error instanceof TypeError && BAD_VALUE.test(error.message)) throw wrong("a parameter of the wrong kind", error.message);
|
|
@@ -4957,20 +5271,24 @@ async function guardEngineSend(ctx, method, args) {
|
|
|
4957
5271
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; call ${method} with --force if you mean to`, { kind: secret.kind });
|
|
4958
5272
|
}
|
|
4959
5273
|
/**
|
|
4960
|
-
* How long `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed
|
|
4961
|
-
*
|
|
5274
|
+
* How long `edit`, `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed, since what is
|
|
5275
|
+
* not said yet leaves with the process; a daemon goes on saying it, so it answers at once unless asked to wait, as a
|
|
5276
|
+
* one-shot does on a chat nobody joined yet (`oneShotWaits`).
|
|
4962
5277
|
*/
|
|
4963
|
-
function confirmWait(ctx, params) {
|
|
5278
|
+
function confirmWait(ctx, params, chat) {
|
|
4964
5279
|
return {
|
|
4965
|
-
wait: oneOf(params, "wait", ["none", "confirmed"], ctx
|
|
5280
|
+
wait: oneOf(params, "wait", ["none", "confirmed"], oneShotWaits(ctx, chat) ? "confirmed" : "none"),
|
|
4966
5281
|
ms: num(params, "timeout", 30, {
|
|
4967
5282
|
min: 1,
|
|
4968
5283
|
max: 3600
|
|
4969
5284
|
}) * 1e3
|
|
4970
5285
|
};
|
|
4971
5286
|
}
|
|
4972
|
-
/**
|
|
4973
|
-
|
|
5287
|
+
/**
|
|
5288
|
+
* Reacts to a message of a chat or a group (`group:<id>`): `emoji`, or `remove` for "" (WISP 400 § Reactions). In a
|
|
5289
|
+
* group, `n` is the reaction's number, for `groupTaken`.
|
|
5290
|
+
*/
|
|
5291
|
+
async function react(ctx, linkId, params, place) {
|
|
4974
5292
|
const messageId = str(params, "message", true);
|
|
4975
5293
|
const removed = bool(params, "remove");
|
|
4976
5294
|
const emoji = removed ? "" : str(params, "emoji");
|
|
@@ -4980,11 +5298,14 @@ async function react(ctx, linkId, params) {
|
|
|
4980
5298
|
messageId,
|
|
4981
5299
|
emoji: emoji ?? ""
|
|
4982
5300
|
});
|
|
5301
|
+
const gone = result.error ? notHere(result.error, messageId, place) : void 0;
|
|
5302
|
+
if (gone) throw gone;
|
|
4983
5303
|
if (result.error) throw new CliError(result.refused ? "refused" : /not in this (?:chat|group)|No reaction of yours/.test(result.error) ? "not_found" : "bad_request", result.error);
|
|
4984
5304
|
return {
|
|
4985
5305
|
messageId,
|
|
4986
5306
|
emoji: emoji || null,
|
|
4987
|
-
removed
|
|
5307
|
+
removed,
|
|
5308
|
+
...result.n ? { n: result.n } : {}
|
|
4988
5309
|
};
|
|
4989
5310
|
}
|
|
4990
5311
|
/**
|
|
@@ -5044,14 +5365,23 @@ function chatNotGroup(ctx, params, command, rest = "") {
|
|
|
5044
5365
|
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
|
|
5045
5366
|
}
|
|
5046
5367
|
/**
|
|
5047
|
-
* An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3),
|
|
5048
|
-
*
|
|
5049
|
-
*
|
|
5368
|
+
* An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), said as every
|
|
5369
|
+
* message id is (`noMessage`); before, a mistyped or lost id read "Only your own text messages can be edited"
|
|
5370
|
+
* (`refused`, exit 1), as if the message were someone else's.
|
|
5050
5371
|
*/
|
|
5051
|
-
function editRefused(message, ref,
|
|
5052
|
-
if (refused && !message) return
|
|
5372
|
+
function editRefused(message, ref, place, error, refused) {
|
|
5373
|
+
if (refused && !message) return noMessage(ref, place);
|
|
5053
5374
|
return new CliError(refused ? "refused" : "unavailable", error);
|
|
5054
5375
|
}
|
|
5376
|
+
/**
|
|
5377
|
+
* The engine's "That message is not in this chat" (", or takes no reaction", ", or cannot be pinned", ", or cannot be
|
|
5378
|
+
* replied to") for the message `id`, said as `noMessage` says it, with that reason kept; undefined for any other error.
|
|
5379
|
+
* The engine says "chat" in a group for a reply and a save: `place` says which it is.
|
|
5380
|
+
*/
|
|
5381
|
+
function notHere(error, id, place) {
|
|
5382
|
+
const said = /^That message is not in this (?:chat|group)(?:, or (.+))?$/.exec(error);
|
|
5383
|
+
return said ? noMessage(id, place, said[1] ? { tail: `, or it ${said[1]}` } : {}) : void 0;
|
|
5384
|
+
}
|
|
5055
5385
|
/** The chat link's own wait for a contact (`GhostLink.connect`): `chat connect --timeout` waits at most that long. */
|
|
5056
5386
|
var CONNECT_MAX_SECONDS = 90;
|
|
5057
5387
|
/**
|
|
@@ -5083,7 +5413,10 @@ async function saveMark(ctx, params, remove) {
|
|
|
5083
5413
|
remove
|
|
5084
5414
|
});
|
|
5085
5415
|
const where = target.group ? "group" : "chat";
|
|
5086
|
-
if (result.error && /not in this chat/.test(result.error)) throw new CliError("not_found",
|
|
5416
|
+
if (result.error && /not in this chat/.test(result.error)) throw remove ? new CliError("not_found", `No saved message ${JSON.stringify(messageId)} in this ${where} (ghostly saved list shows the saved ones)`) : noMessage(messageId, {
|
|
5417
|
+
group: target.group,
|
|
5418
|
+
ref: str(params, "chat", true)
|
|
5419
|
+
});
|
|
5087
5420
|
if (result.error) throw new CliError("bad_request", result.error);
|
|
5088
5421
|
return {
|
|
5089
5422
|
[target.group ? "group" : "chat"]: target.id,
|
|
@@ -5113,7 +5446,13 @@ async function historyOf(ctx, chat, params, json = messageJson) {
|
|
|
5113
5446
|
before,
|
|
5114
5447
|
...after !== void 0 && { after }
|
|
5115
5448
|
}).catch((error) => {
|
|
5116
|
-
|
|
5449
|
+
const missing = [before, after].find((id) => error instanceof Error && error.message === `No message ${id}`);
|
|
5450
|
+
if (missing === void 0) throw error;
|
|
5451
|
+
const group = chat.startsWith("group:");
|
|
5452
|
+
throw noMessage(String(missing), {
|
|
5453
|
+
group,
|
|
5454
|
+
ref: str(params, group ? "group" : "chat", true)
|
|
5455
|
+
});
|
|
5117
5456
|
});
|
|
5118
5457
|
const originals = await originalsNow(ctx, chat, page.messages);
|
|
5119
5458
|
return {
|
|
@@ -5174,6 +5513,6 @@ async function callApi(ctx, method, params = {}) {
|
|
|
5174
5513
|
return run(ctx, await withStoredIds(ctx, params));
|
|
5175
5514
|
}
|
|
5176
5515
|
//#endregion
|
|
5177
|
-
export {
|
|
5516
|
+
export { resumeHolds as _, hideStateSecrets as a, settingsInEffect as c, servedApps as d, nodeLocalFetch as f, groupMessageJson as g, groupJson as h, groupSendRefused as i, paymentJson as l, chatMessageJson as m, SETTABLE as n, mentionsFor as o, chatJson as p, callApi as r, redactSettings as s, API_METHODS as t, reportAppFrames as u, flushCardUpdates as v };
|
|
5178
5517
|
|
|
5179
|
-
//# sourceMappingURL=api-
|
|
5518
|
+
//# sourceMappingURL=api-DL0Uazf6.js.map
|