@ghostlytools/cli 1.10.5 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -22
- package/SKILL.md +8 -5
- package/dist/assets/api-B-52sVYp.js +3 -0
- package/dist/assets/{api-DppWqAP3.js → api-CTqIcdu7.js} +532 -197
- package/dist/assets/api-CTqIcdu7.js.map +1 -0
- package/dist/assets/{apiKit-DFIho4Ev.js → apiKit-CZq4Lq4f.js} +97 -13
- package/dist/assets/apiKit-CZq4Lq4f.js.map +1 -0
- package/dist/assets/{apps-yBnbEtfV.js → apps-C_X0zgSG.js} +16 -4
- package/dist/assets/apps-C_X0zgSG.js.map +1 -0
- package/dist/assets/{apps-1MkGMH8m.js → apps-kRsY9S2S.js} +1 -1
- package/dist/assets/{arkade-bFAS6imn.js → arkade-_aaB7VbW.js} +2 -2
- package/dist/assets/{arkade-bFAS6imn.js.map → arkade-_aaB7VbW.js.map} +1 -1
- package/dist/assets/{backup-ejIX59o7.js → backup-DBg388Ke.js} +1 -1
- package/dist/assets/{backup-vj4J7M3e.js → backup-OTvrmk-w.js} +35 -7
- package/dist/assets/backup-OTvrmk-w.js.map +1 -0
- 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-4EKtQl-7.js +2 -0
- package/dist/assets/{buttons-BoDMx3Ky.js → buttons-DUu7hxxT.js} +61 -30
- package/dist/assets/buttons-DUu7hxxT.js.map +1 -0
- package/dist/assets/{client-BQArefYa.js → client-DDpZP1R1.js} +55 -10
- package/dist/assets/client-DDpZP1R1.js.map +1 -0
- package/dist/assets/{codec-_MwTUz5E.js → codec-DrryGcPT.js} +2 -2
- package/dist/assets/{codec-_MwTUz5E.js.map → codec-DrryGcPT.js.map} +1 -1
- package/dist/assets/{envelope-CeZBNGX-.js → envelope-Q_rMgoE9.js} +2 -2
- package/dist/assets/{envelope-CeZBNGX-.js.map → envelope-Q_rMgoE9.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-BV5GDiTU.js} +3 -3
- package/dist/assets/{fixedHosts-B_2Rvyja.js.map → fixedHosts-BV5GDiTU.js.map} +1 -1
- package/dist/assets/{host-DFLzzKNr.js → host-BlUzZgQL.js} +336 -84
- package/dist/assets/host-BlUzZgQL.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js → hyperdhtRelay-BvI_uNZO.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js.map → hyperdhtRelay-BvI_uNZO.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-CqPN8VPY.js} +469 -16
- package/dist/assets/irohWeb-CqPN8VPY.js.map +1 -0
- package/dist/assets/{main-xO8MnXxD.js → main-vQjlgEnt.js} +409 -126
- package/dist/assets/main-vQjlgEnt.js.map +1 -0
- package/dist/assets/{mainline-Bx184Ixg.js → mainline-p6HOW7sb.js} +2 -2
- package/dist/assets/{mainline-Bx184Ixg.js.map → mainline-p6HOW7sb.js.map} +1 -1
- package/dist/assets/{networkReason-BlQhTbXk.js → networkReason-DMffkiJ6.js} +4 -4
- package/dist/assets/{networkReason-BlQhTbXk.js.map → networkReason-DMffkiJ6.js.map} +1 -1
- package/dist/assets/{nwc-B3-PHX0L.js → nwc-2vH18oNy.js} +4 -4
- package/dist/assets/nwc-2vH18oNy.js.map +1 -0
- package/dist/assets/{nwcProvider-BeQBPB2q.js → nwcProvider-DpeDy0bV.js} +11 -3
- package/dist/assets/nwcProvider-DpeDy0bV.js.map +1 -0
- package/dist/assets/{ownDid-DAzW-Urb.js → ownDid-iKz8u_fM.js} +2 -2
- package/dist/assets/{ownDid-DAzW-Urb.js.map → ownDid-iKz8u_fM.js.map} +1 -1
- package/dist/assets/{words-BvdNuw_v.js → ownStatus-BlRKnM5F.js} +56 -4
- package/dist/assets/ownStatus-BlRKnM5F.js.map +1 -0
- package/dist/assets/{profiles-Bg43mRXu.js → profiles-B5e0TyvS.js} +22 -12
- package/dist/assets/profiles-B5e0TyvS.js.map +1 -0
- package/dist/assets/{registry-CAk2-5BQ.js → registry-Cc_PQb3k.js} +1 -1
- package/dist/assets/{registry-BDnsZJBi.js → registry-CnFO2Pp5.js} +123 -99
- package/dist/assets/registry-CnFO2Pp5.js.map +1 -0
- package/dist/assets/{resolve-UAfshn6j.js → resolve-DI8uAM_Y.js} +2 -2
- package/dist/assets/{resolve-UAfshn6j.js.map → resolve-DI8uAM_Y.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-DdtPxkqI.js} +2057 -655
- package/dist/assets/server-DdtPxkqI.js.map +1 -0
- package/dist/assets/{src-BTRPAi5X.js → src-BnpEQqzk.js} +813 -144
- package/dist/assets/src-BnpEQqzk.js.map +1 -0
- package/dist/assets/{sshForges-KtHK5x1x.js → sshForges-cdIAraDw.js} +2 -2
- package/dist/assets/{sshForges-KtHK5x1x.js.map → sshForges-cdIAraDw.js.map} +1 -1
- package/dist/assets/{translate-CYuygrvA.js → translate-kNopA04L.js} +2 -2
- package/dist/assets/{translate-CYuygrvA.js.map → translate-kNopA04L.js.map} +1 -1
- package/dist/assets/{usdt-Dw9IENe_.js → usdt-CDaLhEYh.js} +3 -3
- package/dist/assets/{usdt-Dw9IENe_.js.map → usdt-CDaLhEYh.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-xO8MnXxD.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/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 { $r as TYPING_REFRESH_MS, Ba as baseMime, Bn as NO_PICTURE_METADATA, Eo as STATUS_CARD_LIMITS, Fa as sanitizeFileName, Fl as isAppRef, Fo as statusCardBytes, Ga as voiceLevel, Hu as relayUrlProblem, Ia as sanitizeMime, Ki as identityStatement, La as PLAYABLE_AUDIO, Lo as MESSAGE_CLOCK_SKEW_MS, No as checkStatusCard, Oo as appCardId, Qr as TYPING_KINDS, Ra as VOICE_LIMITS, Ua as parseVoiceMeta, Ul as readImageMeta, Un as stripPictureMetadata, Va as downsamplePeaks, Vu as normalizeRelayUrl, Wa as voiceDownloadName, Wn as withoutPictureMetadata, _o as replySnippet, au as ownInviteRefusal, fs as GhostlyHttpError, gl as APP_PERMISSIONS, gs as LIMITS, hd as toBase64Url, is as AWAITING_PEER_MS, jo as cardLine, kl as appRef, ko as appCardUrl, md as randomBytes$1, ms as parseLocalTarget, nr as GROUP_FILE_LIMITS, od as MAX_AVATAR_LENGTH, ru as inviteLink, sd as sanitizeAvatar, ti as sanitizeTypingStatus, wi as APP_DATA_MAX_BYTES, xl as isAppUrl, za as VOICE_METER, zn as withoutVideoMetadata, zo as claimedTime } from "./src-BnpEQqzk.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-CqPN8VPY.js";
|
|
5
|
+
import { t as IDENTITY_PROVIDERS } from "./registry-CnFO2Pp5.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-BlRKnM5F.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-CZq4Lq4f.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-DUu7hxxT.js";
|
|
13
|
+
import { a as checkShownName } from "./profiles-B5e0TyvS.js";
|
|
14
|
+
import { t as BACKUP_METHODS } from "./backup-OTvrmk-w.js";
|
|
15
|
+
import { o as checkedBundle } from "./apps-C_X0zgSG.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 }
|
|
@@ -857,6 +863,23 @@ async function sendable(path, mime, voice) {
|
|
|
857
863
|
}
|
|
858
864
|
}
|
|
859
865
|
/**
|
|
866
|
+
* A read of the file at `path` through the Blob `openAsBlob` gave it. Node refuses every read of that Blob once the file
|
|
867
|
+
* changed on disk (it grew, shrank or was written again: a log still written to, a file being saved), with a bare
|
|
868
|
+
* DOMException "The blob could not be read" that named neither the file nor why, as `engine`. Said with its path, as
|
|
869
|
+
* `unavailable`: sent again once nothing writes to it, it goes, and nothing of this try was kept (`stage` removes its copy).
|
|
870
|
+
*/
|
|
871
|
+
async function whileUnchanged(path, read) {
|
|
872
|
+
try {
|
|
873
|
+
return await read();
|
|
874
|
+
} catch (error) {
|
|
875
|
+
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`, {
|
|
876
|
+
reason: "file_changed",
|
|
877
|
+
path
|
|
878
|
+
});
|
|
879
|
+
throw error;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
860
883
|
* A file announced in a group (WISP 503): its bytes staged under a group file id with their digest, as a chat's are, then
|
|
861
884
|
* the announcement. This device is its first holder and serves the members who ask.
|
|
862
885
|
*/
|
|
@@ -866,14 +889,17 @@ async function sendToGroup(ctx, params, group, path, picked) {
|
|
|
866
889
|
const mime = mimeOf(path, str(params, "mime"));
|
|
867
890
|
const replyTo = str(params, "reply");
|
|
868
891
|
if (replyTo) {
|
|
869
|
-
if (!await findMessage(ctx, `group:${group.id}`, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw
|
|
892
|
+
if (!await findMessage(ctx, `group:${group.id}`, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw noMessage(replyTo, {
|
|
893
|
+
group: true,
|
|
894
|
+
ref: str(params, "chat", true)
|
|
895
|
+
}, { tail: ", or it cannot be replied to" });
|
|
870
896
|
}
|
|
871
897
|
const check = await node(ctx).groupFileCheck({ groupId: group.id });
|
|
872
898
|
if (check.error) throw check.refused ? new CliError("refused", check.error) : groupSendRefused(check.error);
|
|
873
899
|
const { voice, warning } = await voiceOf(params, path, mime, picked);
|
|
874
|
-
const source = await sendable(path, mime, voice);
|
|
900
|
+
const source = await whileUnchanged(path, () => sendable(path, mime, voice));
|
|
875
901
|
const size = source.size;
|
|
876
|
-
const image = voice ? void 0 : await readImageMeta(source, mime);
|
|
902
|
+
const image = voice ? void 0 : await whileUnchanged(path, () => readImageMeta(source, mime));
|
|
877
903
|
const fileId = groupFileId(group.id, "out");
|
|
878
904
|
const file = {
|
|
879
905
|
id: fileId,
|
|
@@ -885,7 +911,7 @@ async function sendToGroup(ctx, params, group, path, picked) {
|
|
|
885
911
|
};
|
|
886
912
|
const timestamp = Date.now();
|
|
887
913
|
const bytes = await fileBytes();
|
|
888
|
-
const digest = await bytes.stage(fileId, source);
|
|
914
|
+
const digest = await whileUnchanged(path, () => bytes.stage(fileId, source));
|
|
889
915
|
await fileStore.put({
|
|
890
916
|
id: fileId,
|
|
891
917
|
linkId: `group:${group.id}`,
|
|
@@ -1002,6 +1028,55 @@ var ACTIONS = [
|
|
|
1002
1028
|
"resend",
|
|
1003
1029
|
"request"
|
|
1004
1030
|
];
|
|
1031
|
+
/**
|
|
1032
|
+
* `file wait`: until a transfer ends: done answers, failed is an `engine` error with the transfer's words (and whether
|
|
1033
|
+
* `file resend` can go on). A file whose transfer this run has not seen answers from the file store. `stopping`: the
|
|
1034
|
+
* daemon's stop ends it as well (`waitForState`), for `file send --wait`, which answers with what it knows then.
|
|
1035
|
+
*/
|
|
1036
|
+
async function waitForFile(ctx, params, stopping) {
|
|
1037
|
+
const fileId = str(params, "file", true);
|
|
1038
|
+
const { where } = fileChat(ctx, params, fileId);
|
|
1039
|
+
const stored = await fileStore.get(fileId);
|
|
1040
|
+
if (!stored && !state(ctx).transfers[fileId]) throw noFile(fileId);
|
|
1041
|
+
const ms = num(params, "timeout", 300, {
|
|
1042
|
+
min: 1,
|
|
1043
|
+
max: 86400
|
|
1044
|
+
}) * 1e3;
|
|
1045
|
+
const transfer = await waitForState(ctx, (s) => {
|
|
1046
|
+
const now = s.transfers[fileId] ?? stored?.transfer;
|
|
1047
|
+
return now && (now.state === "done" || now.state === "failed" || now.stage === "asking" && now.direction === "in") ? now : void 0;
|
|
1048
|
+
}, ms, `file ${fileId} to arrive`, stopping).catch((error) => {
|
|
1049
|
+
const now = state(ctx).transfers[fileId];
|
|
1050
|
+
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${stageWords(now)}` : ""})`, {
|
|
1051
|
+
file: fileId,
|
|
1052
|
+
transferred: now.transferred,
|
|
1053
|
+
size: now.size,
|
|
1054
|
+
stage: now.stage ?? null,
|
|
1055
|
+
...error.details?.reason ? { reason: error.details.reason } : {}
|
|
1056
|
+
});
|
|
1057
|
+
throw error;
|
|
1058
|
+
});
|
|
1059
|
+
if (transfer.state === "failed") throw new CliError("engine", transfer.error ?? "The transfer failed", {
|
|
1060
|
+
file: fileId,
|
|
1061
|
+
...where,
|
|
1062
|
+
retry: !!transfer.retry
|
|
1063
|
+
});
|
|
1064
|
+
if (transfer.state !== "done") {
|
|
1065
|
+
const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
|
|
1066
|
+
throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
1067
|
+
file: fileId,
|
|
1068
|
+
...where,
|
|
1069
|
+
size: transfer.size,
|
|
1070
|
+
stage: "asking"
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
return {
|
|
1074
|
+
...where,
|
|
1075
|
+
file: fileId,
|
|
1076
|
+
state: "done",
|
|
1077
|
+
size: transfer.size
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1005
1080
|
var FILE_METHODS = {
|
|
1006
1081
|
async "file.send"(ctx, params) {
|
|
1007
1082
|
guardText(str(params, "name"), bool(params, "force"), "file's name", "send it");
|
|
@@ -1015,7 +1090,7 @@ var FILE_METHODS = {
|
|
|
1015
1090
|
}
|
|
1016
1091
|
if (!info.isFile()) throw new CliError("bad_request", `${path} is not a file`);
|
|
1017
1092
|
await access(path, constants$1.R_OK);
|
|
1018
|
-
const wait = oneOf(params, "wait", "group" in target ? ["none"] : ["none", "sent"], !("group" in target) && ctx.
|
|
1093
|
+
const wait = oneOf(params, "wait", "group" in target ? ["none"] : ["none", "sent"], !("group" in target) && oneShotWaits(ctx, target.link.id) ? "sent" : "none");
|
|
1019
1094
|
const seconds = num(params, "timeout", 300, {
|
|
1020
1095
|
min: 1,
|
|
1021
1096
|
max: 86400
|
|
@@ -1028,11 +1103,14 @@ var FILE_METHODS = {
|
|
|
1028
1103
|
const mime = mimeOf(path, str(params, "mime"));
|
|
1029
1104
|
const replyTo = str(params, "reply");
|
|
1030
1105
|
if (replyTo) {
|
|
1031
|
-
if (!await findMessage(ctx, link.id, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw
|
|
1106
|
+
if (!await findMessage(ctx, link.id, (m) => m.id === replyTo || replyRef(m) === replyTo)) throw noMessage(replyTo, {
|
|
1107
|
+
group: false,
|
|
1108
|
+
ref: str(params, "chat", true)
|
|
1109
|
+
}, { tail: ", or it cannot be replied to" });
|
|
1032
1110
|
}
|
|
1033
1111
|
const { voice, warning } = await voiceOf(params, path, mime, info.size);
|
|
1034
|
-
const source = await sendable(path, mime, voice);
|
|
1035
|
-
const image = voice ? void 0 : await readImageMeta(source, mime);
|
|
1112
|
+
const source = await whileUnchanged(path, () => sendable(path, mime, voice));
|
|
1113
|
+
const image = voice ? void 0 : await whileUnchanged(path, () => readImageMeta(source, mime));
|
|
1036
1114
|
const wireId = toBase64Url(randomBytes$1(12));
|
|
1037
1115
|
const file = {
|
|
1038
1116
|
id: `${link.id}-out-${wireId}`,
|
|
@@ -1044,7 +1122,7 @@ var FILE_METHODS = {
|
|
|
1044
1122
|
};
|
|
1045
1123
|
const timestamp = sentAt();
|
|
1046
1124
|
const bytes = await fileBytes();
|
|
1047
|
-
const digest = await bytes.stage(file.id, source);
|
|
1125
|
+
const digest = await whileUnchanged(path, () => bytes.stage(file.id, source));
|
|
1048
1126
|
await fileStore.put({
|
|
1049
1127
|
id: file.id,
|
|
1050
1128
|
linkId: link.id,
|
|
@@ -1079,14 +1157,23 @@ var FILE_METHODS = {
|
|
|
1079
1157
|
await removeStored(file.id).catch(() => {});
|
|
1080
1158
|
throw new CliError("refused", error instanceof Error ? error.message : String(error));
|
|
1081
1159
|
}
|
|
1082
|
-
|
|
1160
|
+
const messageId = `me_${timestamp}`;
|
|
1161
|
+
if (wait === "sent") await waitForFile(ctx, {
|
|
1083
1162
|
chat: link.id,
|
|
1084
1163
|
file: file.id,
|
|
1085
1164
|
timeout: seconds
|
|
1165
|
+
}, ctx.stopping).catch((error) => {
|
|
1166
|
+
if (!(error instanceof CliError) || error.code !== "timeout") throw error;
|
|
1167
|
+
throw new CliError("timeout", `${error.message}. It is kept here and ${goesOn(ctx, link.id)}`, {
|
|
1168
|
+
...error.details,
|
|
1169
|
+
chat: link.id,
|
|
1170
|
+
messageId,
|
|
1171
|
+
file: file.id
|
|
1172
|
+
});
|
|
1086
1173
|
});
|
|
1087
1174
|
return {
|
|
1088
1175
|
chat: link.id,
|
|
1089
|
-
messageId
|
|
1176
|
+
messageId,
|
|
1090
1177
|
file: {
|
|
1091
1178
|
id: file.id,
|
|
1092
1179
|
name: file.name,
|
|
@@ -1095,7 +1182,8 @@ var FILE_METHODS = {
|
|
|
1095
1182
|
...voice ? { voice: true } : {},
|
|
1096
1183
|
...image ? { image } : {}
|
|
1097
1184
|
},
|
|
1098
|
-
...warning ? { warning } : {}
|
|
1185
|
+
...warning ? { warning } : {},
|
|
1186
|
+
...keptForJoin(ctx, link.id, "the file")
|
|
1099
1187
|
};
|
|
1100
1188
|
},
|
|
1101
1189
|
async "file.list"(ctx, params) {
|
|
@@ -1105,20 +1193,23 @@ var FILE_METHODS = {
|
|
|
1105
1193
|
const kept = f.transfer?.state === "done" ? {
|
|
1106
1194
|
...f.transfer,
|
|
1107
1195
|
direction: f.direction
|
|
1196
|
+
} : !("group" in target) && f.transfer?.state === "transferring" && f.direction === "out" ? {
|
|
1197
|
+
...f.transfer,
|
|
1198
|
+
direction: f.direction,
|
|
1199
|
+
stage: "waiting",
|
|
1200
|
+
waitingFor: "contact"
|
|
1108
1201
|
} : waitingGroupFile(f);
|
|
1109
1202
|
return kept ? [[f.id, kept]] : [];
|
|
1110
1203
|
}));
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1118
|
-
const kept = await keptOf(target.link.id);
|
|
1119
|
-
return {
|
|
1204
|
+
const linkId = "group" in target ? `group:${target.group.id}` : target.link.id;
|
|
1205
|
+
const kept = await keptOf(linkId);
|
|
1206
|
+
const files = filesOf(await node(ctx).fileMessages(linkId), (id) => withWaitingFor(views[id] ?? kept.get(id)));
|
|
1207
|
+
return "group" in target ? {
|
|
1208
|
+
group: target.group.id,
|
|
1209
|
+
files
|
|
1210
|
+
} : {
|
|
1120
1211
|
chat: target.link.id,
|
|
1121
|
-
files
|
|
1212
|
+
files
|
|
1122
1213
|
};
|
|
1123
1214
|
},
|
|
1124
1215
|
/**
|
|
@@ -1182,52 +1273,8 @@ var FILE_METHODS = {
|
|
|
1182
1273
|
transfer: state(ctx).transfers[fileId] ?? null
|
|
1183
1274
|
};
|
|
1184
1275
|
},
|
|
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
1276
|
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
|
-
};
|
|
1277
|
+
return waitForFile(ctx, params);
|
|
1231
1278
|
},
|
|
1232
1279
|
/**
|
|
1233
1280
|
* Writes a received (or sent) file to disk: into `dir` under its own name (`saveName`), a voice message under the one
|
|
@@ -1242,13 +1289,15 @@ var FILE_METHODS = {
|
|
|
1242
1289
|
timeout: params.timeout
|
|
1243
1290
|
});
|
|
1244
1291
|
const stored = await fileStore.get(fileId);
|
|
1245
|
-
if (!stored?.metadata) throw
|
|
1292
|
+
if (!stored?.metadata) throw noFile(fileId);
|
|
1246
1293
|
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
1294
|
const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? stored.transfer;
|
|
1248
1295
|
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1249
1296
|
if (transfer && transfer.state !== "done") throw new CliError("unavailable", `The file is not all here yet (${transfer.transferred} of ${transfer.size} bytes)`);
|
|
1250
1297
|
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
1298
|
const force = bool(params, "force");
|
|
1299
|
+
const path = str(params, "path");
|
|
1300
|
+
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
1301
|
const free = !force && !str(params, "path") && !!stored.metadata.voice;
|
|
1253
1302
|
const ext = extname(named), stem = named.slice(0, named.length - ext.length);
|
|
1254
1303
|
const taken = async (target, code) => {
|
|
@@ -1540,7 +1589,7 @@ async function sendCard(ctx, params, kind) {
|
|
|
1540
1589
|
"none",
|
|
1541
1590
|
"sent",
|
|
1542
1591
|
"delivered"
|
|
1543
|
-
], ctx.
|
|
1592
|
+
], oneShotWaits(ctx, target.linkId) ? "sent" : "none");
|
|
1544
1593
|
const ms = num(params, "timeout", 30, {
|
|
1545
1594
|
min: 1,
|
|
1546
1595
|
max: 3600
|
|
@@ -1571,7 +1620,23 @@ async function sendCard(ctx, params, kind) {
|
|
|
1571
1620
|
if (wait !== "none") message = await waitForMessage(ctx, target.linkId, result.messageId, wait, ms);
|
|
1572
1621
|
return answer(target, kind, id, result.messageId, {
|
|
1573
1622
|
card,
|
|
1574
|
-
delivery: message?.delivery ?? null
|
|
1623
|
+
delivery: message?.delivery ?? null,
|
|
1624
|
+
...keptForJoin(ctx, target.linkId, "the card")
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* 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
|
|
1629
|
+
* went back since they were set. Said as that, not as a time the person gave in the future; fields the update gives
|
|
1630
|
+
* are checked as given.
|
|
1631
|
+
*/
|
|
1632
|
+
function clockWentBack(base, patch, kind) {
|
|
1633
|
+
const latest = Date.now() + MESSAGE_CLOCK_SKEW_MS;
|
|
1634
|
+
const ahead = (value) => typeof value === "number" && value > latest;
|
|
1635
|
+
const at = (run) => isObject(run) && ahead(run.at);
|
|
1636
|
+
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;
|
|
1637
|
+
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`, {
|
|
1638
|
+
field,
|
|
1639
|
+
now: Date.now()
|
|
1575
1640
|
});
|
|
1576
1641
|
}
|
|
1577
1642
|
/** Edits the card's message with its merged card, now. */
|
|
@@ -1600,18 +1665,22 @@ async function updateCard(ctx, params, kind) {
|
|
|
1600
1665
|
edits: message.edit.seq
|
|
1601
1666
|
});
|
|
1602
1667
|
const pace = paceOf(ctx, `${target.linkId}\n${message.id}`);
|
|
1603
|
-
const
|
|
1668
|
+
const base = pace.next ?? message.card;
|
|
1669
|
+
clockWentBack(base, patch, kind);
|
|
1670
|
+
const startedAt = typeof base.startedAt === "number" && patch.startedAt === void 0 ? base.startedAt : 0;
|
|
1671
|
+
const card = checked(withRun(mergeCard(base, {
|
|
1604
1672
|
...patch,
|
|
1605
|
-
...kind === "task" && { updatedAt: Date.now() }
|
|
1673
|
+
...kind === "task" && { updatedAt: Math.max(Date.now(), startedAt) }
|
|
1606
1674
|
}), params));
|
|
1607
1675
|
if (isObject(patch) && patch.parent !== void 0) await parentThere(ctx, target, card);
|
|
1608
1676
|
const text = str(params, "text") ?? "";
|
|
1609
|
-
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], ctx.
|
|
1677
|
+
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], oneShotWaits(ctx, target.linkId) ? "confirmed" : "none");
|
|
1610
1678
|
const ms = num(params, "timeout", 30, {
|
|
1611
1679
|
min: 1,
|
|
1612
1680
|
max: 3600
|
|
1613
1681
|
}) * 1e3;
|
|
1614
|
-
const
|
|
1682
|
+
const last = Math.max(pace.last, message.edit?.at ?? message.timestamp);
|
|
1683
|
+
const due = Math.min(last + CARD_UPDATE_GAP_MS - Date.now(), CARD_UPDATE_GAP_MS);
|
|
1615
1684
|
let queued = false;
|
|
1616
1685
|
if (due > 0 && ctx.mode === "daemon") {
|
|
1617
1686
|
pace.next = card;
|
|
@@ -1642,7 +1711,10 @@ async function updateCard(ctx, params, kind) {
|
|
|
1642
1711
|
card,
|
|
1643
1712
|
queued,
|
|
1644
1713
|
edits: edited?.edit?.seq ?? 0,
|
|
1645
|
-
...target.group ? { ...edges !== void 0 && { edges } } : {
|
|
1714
|
+
...target.group ? { ...edges !== void 0 && { edges } } : {
|
|
1715
|
+
confirmed: (!queued || wait !== "none") && !!edited && !edited.edit?.pending,
|
|
1716
|
+
...keptForJoin(ctx, target.linkId, "the update")
|
|
1717
|
+
}
|
|
1646
1718
|
});
|
|
1647
1719
|
}
|
|
1648
1720
|
/**
|
|
@@ -1685,7 +1757,7 @@ async function reportUsage(ctx, ref, fields, params) {
|
|
|
1685
1757
|
};
|
|
1686
1758
|
checked(report);
|
|
1687
1759
|
const sent = await cardMessage(ctx, target, "usage", id).catch(() => void 0);
|
|
1688
|
-
const wait = oneOf(params, "wait", ["none", "sent"], !target.group && ctx.
|
|
1760
|
+
const wait = oneOf(params, "wait", ["none", "sent"], !target.group && oneShotWaits(ctx, target.linkId) ? "sent" : "none");
|
|
1689
1761
|
if (!sent || (sent.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) return {
|
|
1690
1762
|
...await sendCard(ctx, {
|
|
1691
1763
|
...params,
|
|
@@ -1771,6 +1843,7 @@ var STATUS_CARD_METHODS = {
|
|
|
1771
1843
|
* chosen before (that one is not a hold).
|
|
1772
1844
|
*/
|
|
1773
1845
|
var HOLD_MAX_MINUTES = 10080;
|
|
1846
|
+
/** Per chat held: what stops its wait (the timer, or the wait for the chat to open: `expire`). */
|
|
1774
1847
|
var timers = /* @__PURE__ */ new WeakMap();
|
|
1775
1848
|
function holdsFile(ctx) {
|
|
1776
1849
|
return join(ctx.runtime.paths.dir, "holds.json");
|
|
@@ -1792,19 +1865,47 @@ function timersOf(ctx) {
|
|
|
1792
1865
|
if (!map) timers.set(ctx, map = /* @__PURE__ */ new Map());
|
|
1793
1866
|
return map;
|
|
1794
1867
|
}
|
|
1868
|
+
function stopWait(ctx, linkId) {
|
|
1869
|
+
timersOf(ctx).get(linkId)?.();
|
|
1870
|
+
timersOf(ctx).delete(linkId);
|
|
1871
|
+
}
|
|
1795
1872
|
function schedule(ctx, linkId, until) {
|
|
1796
|
-
|
|
1797
|
-
clearTimeout(map.get(linkId));
|
|
1873
|
+
stopWait(ctx, linkId);
|
|
1798
1874
|
const timer = setTimeout(() => {
|
|
1799
|
-
|
|
1800
|
-
|
|
1875
|
+
timersOf(ctx).delete(linkId);
|
|
1876
|
+
expire(ctx, linkId);
|
|
1801
1877
|
}, Math.max(0, until - Date.now()));
|
|
1802
1878
|
timer.unref?.();
|
|
1803
|
-
|
|
1879
|
+
timersOf(ctx).set(linkId, () => clearTimeout(timer));
|
|
1804
1880
|
}
|
|
1805
|
-
/**
|
|
1881
|
+
/**
|
|
1882
|
+
* Whether the chat leaves DHT only in this run: the engine switches only a chat it opened (`runnableTransports` is
|
|
1883
|
+
* there once it did). A one-shot that only reads opens none, and one about another chat not this one.
|
|
1884
|
+
*/
|
|
1885
|
+
var switchable = (link) => !link || link.deliveryMode !== "dht" || !!link.runnableTransports;
|
|
1886
|
+
/**
|
|
1887
|
+
* 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
|
|
1888
|
+
* that opens it; it is no longer reported meanwhile (`holdOf`). Each read said on stderr that it "could not end:
|
|
1889
|
+
* Delivery method unavailable." and kept its past `heldUntil`.
|
|
1890
|
+
*/
|
|
1891
|
+
function expire(ctx, linkId) {
|
|
1892
|
+
const opened = (links) => switchable(links.find((l) => l.id === linkId));
|
|
1893
|
+
if (!opened(state(ctx).links)) {
|
|
1894
|
+
const off = ctx.hub.onState((s) => {
|
|
1895
|
+
if (opened(s.links)) {
|
|
1896
|
+
stopWait(ctx, linkId);
|
|
1897
|
+
expire(ctx, linkId);
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
timersOf(ctx).set(linkId, off);
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
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`));
|
|
1904
|
+
}
|
|
1905
|
+
/** When the chat's hold ends, or null (its time is up, also while it waits for the chat to open: `expire`). */
|
|
1806
1906
|
function holdOf(ctx, linkId) {
|
|
1807
|
-
|
|
1907
|
+
const until = readHolds(ctx)[linkId]?.until;
|
|
1908
|
+
return until !== void 0 && until > Date.now() ? until : null;
|
|
1808
1909
|
}
|
|
1809
1910
|
/** Keeps the chat off its direct link for `minutes` (again: from now). */
|
|
1810
1911
|
async function holdChat(ctx, link, minutes) {
|
|
@@ -1840,8 +1941,7 @@ async function holdChat(ctx, link, minutes) {
|
|
|
1840
1941
|
async function releaseHold(ctx, linkId, reason, chosen = false) {
|
|
1841
1942
|
const holds = readHolds(ctx);
|
|
1842
1943
|
if (!holds[linkId]) return false;
|
|
1843
|
-
|
|
1844
|
-
timersOf(ctx).delete(linkId);
|
|
1944
|
+
stopWait(ctx, linkId);
|
|
1845
1945
|
const link = state(ctx).links.find((l) => l.id === linkId);
|
|
1846
1946
|
if (!chosen && link?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
|
|
1847
1947
|
linkId,
|
|
@@ -1871,6 +1971,22 @@ function isLive(link) {
|
|
|
1871
1971
|
if (link.textDelivery !== "stream" || link.dataLink !== "open") return false;
|
|
1872
1972
|
return !link.profile || link.pairing?.status === "ready" && !!link.pairing.transport;
|
|
1873
1973
|
}
|
|
1974
|
+
/**
|
|
1975
|
+
* The app's connection failure (ChatConnection's `connectionFailure`), with the relays' words made plain: the engine's
|
|
1976
|
+
* "Publish failed on every relay: Error: http://… responded 503" reads as the CLI failing, a class name per relay.
|
|
1977
|
+
*/
|
|
1978
|
+
function connectionError(link) {
|
|
1979
|
+
const pair = link.pairing;
|
|
1980
|
+
const dht = link.deliveryMode === "dht" || link.textDelivery === "dht";
|
|
1981
|
+
const detail = pair?.transitionError || (pair?.status === "error" ? pair.error : "") || (dht ? link.dhtDelivery?.error : "");
|
|
1982
|
+
if (!detail) return null;
|
|
1983
|
+
const at = detail.indexOf("Publish failed on every relay:");
|
|
1984
|
+
if (at < 0) return detail;
|
|
1985
|
+
const tail = detail.slice(at);
|
|
1986
|
+
const hosts = [...new Set([...tail.matchAll(/\bhttps?:\/\/[^\s;,]+/g)].map(([url]) => URL.canParse(url) ? new URL(url).host : url))];
|
|
1987
|
+
const said = / responded \d{3}\b/.test(tail) ? `${at ? "n" : "N"}o relay took it` : `${at ? "n" : "N"}o relay answered`;
|
|
1988
|
+
return `${detail.slice(0, at)}${said}${hosts.length ? ` (${hosts.join(", ")})` : ""}`;
|
|
1989
|
+
}
|
|
1874
1990
|
function chatJson(link, showSecret) {
|
|
1875
1991
|
const label = link.label?.trim() || null;
|
|
1876
1992
|
const peerName = link.peerNick?.trim() || null;
|
|
@@ -1882,11 +1998,12 @@ function chatJson(link, showSecret) {
|
|
|
1882
1998
|
peerName,
|
|
1883
1999
|
peer: link.peerPubKeyZ32,
|
|
1884
2000
|
createdAt: link.createdAt,
|
|
1885
|
-
lastMessageAt: link.lastMessageAt,
|
|
2001
|
+
lastMessageAt: link.lastMessageAt || null,
|
|
1886
2002
|
live,
|
|
1887
2003
|
transport: live ? link.pairing?.transport ?? link.pairingProgress?.transport ?? null : null,
|
|
1888
2004
|
text: link.textDelivery ?? (link.profile ? "unavailable" : "dht"),
|
|
1889
2005
|
pairing: link.pairing?.status ?? null,
|
|
2006
|
+
connectionError: connectionError(link),
|
|
1890
2007
|
stage: link.pairingProgress?.stage ?? null,
|
|
1891
2008
|
verified: !!link.peerVerified,
|
|
1892
2009
|
invite: link.pairing?.status === "ready" || !link.inviteCode ? null : showSecret === true ? link.inviteCode : "<hidden>",
|
|
@@ -2059,7 +2176,7 @@ function groupJson(group, showSecret = false) {
|
|
|
2059
2176
|
me: group.myKey ?? null,
|
|
2060
2177
|
canSend: group.canSend,
|
|
2061
2178
|
link: group.entryLink ? showSecret ? group.entryLink : "<hidden>" : null,
|
|
2062
|
-
lastMessageAt: group.lastMessageAt,
|
|
2179
|
+
lastMessageAt: group.lastMessageAt || null,
|
|
2063
2180
|
members: group.members.map((m) => ({
|
|
2064
2181
|
key: m.key,
|
|
2065
2182
|
name: m.nick ?? null,
|
|
@@ -2136,7 +2253,9 @@ async function pictureFrom(path) {
|
|
|
2136
2253
|
}
|
|
2137
2254
|
const url = `data:image/jpeg;base64,${(parts ? Buffer.concat(parts) : bytes).toString("base64")}`;
|
|
2138
2255
|
const checked = sanitizeAvatar(url);
|
|
2139
|
-
|
|
2256
|
+
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)`;
|
|
2257
|
+
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}`);
|
|
2258
|
+
if (!checked) throw new CliError("bad_request", `A picture is ${bounds}: resize it first`);
|
|
2140
2259
|
return checked;
|
|
2141
2260
|
}
|
|
2142
2261
|
async function picture(params) {
|
|
@@ -2189,9 +2308,7 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2189
2308
|
},
|
|
2190
2309
|
async "group.rename"(ctx, params) {
|
|
2191
2310
|
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`);
|
|
2311
|
+
const name = groupNameOf(params);
|
|
2195
2312
|
guardText(name, bool(params, "force"), "group's name", "rename it");
|
|
2196
2313
|
await node(ctx).renameGroup({
|
|
2197
2314
|
groupId: group.id,
|
|
@@ -2706,6 +2823,11 @@ function sameSecret(a, b) {
|
|
|
2706
2823
|
*/
|
|
2707
2824
|
var OPENED_SERVICE_CSP = "default-src 'self' https: data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; form-action 'self'";
|
|
2708
2825
|
/**
|
|
2826
|
+
* The policy while Hide my IP from contacts is on (`relayOnly`): no `https:`, so the page loads nothing but its own
|
|
2827
|
+
* origin. A picture or script from a server the contact names would show that server this machine's address.
|
|
2828
|
+
*/
|
|
2829
|
+
var OPENED_SERVICE_CSP_RELAY_ONLY = "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; form-action 'self'";
|
|
2830
|
+
/**
|
|
2709
2831
|
* The contact's headers that are not passed on: each makes the browser send something to a place it names, outside
|
|
2710
2832
|
* `connect-src` (violation and network-error reports, and the endpoints they go to; `Link` preloads, prefetches and
|
|
2711
2833
|
* early connections). Only the contact's server is reached.
|
|
@@ -2723,6 +2845,8 @@ var OPENED_SERVICE_DROPPED_DIRECTIVES = ["report-uri", "report-to"];
|
|
|
2723
2845
|
function withoutReports(value) {
|
|
2724
2846
|
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
2847
|
}
|
|
2848
|
+
/** `service open` while Hide my IP from contacts is on (as the browser extension refuses to open one). */
|
|
2849
|
+
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
2850
|
function plain(response, status, text, headers = {}) {
|
|
2727
2851
|
response.writeHead(status, {
|
|
2728
2852
|
"content-type": "text/plain; charset=utf-8",
|
|
@@ -2736,8 +2860,10 @@ function plain(response, status, text, headers = {}) {
|
|
|
2736
2860
|
* cookies and storage are its own, apart from any other app on 127.0.0.1 or localhost, and a name that merely
|
|
2737
2861
|
* resolves here (DNS rebinding) is not it. Only a browser given the link (which sets `OPEN_COOKIE`) is served; anyone
|
|
2738
2862
|
* else on this machine who finds the port gets 404. The body streams through, bounded by `MAX_RESPONSE_BYTES`.
|
|
2863
|
+
* `relayOnly`: Hide my IP from contacts was on when it opened (`OPENED_SERVICE_CSP_RELAY_ONLY`).
|
|
2739
2864
|
*/
|
|
2740
|
-
async function openServiceServer(send, port = 0) {
|
|
2865
|
+
async function openServiceServer(send, port = 0, { relayOnly = false } = {}) {
|
|
2866
|
+
const policy = relayOnly ? OPENED_SERVICE_CSP_RELAY_ONLY : OPENED_SERVICE_CSP;
|
|
2741
2867
|
const name = `${randomBytes(16).toString("hex")}.localhost`;
|
|
2742
2868
|
const token = randomBytes(32).toString("hex");
|
|
2743
2869
|
const cookies = /* @__PURE__ */ new Set();
|
|
@@ -2768,7 +2894,7 @@ async function openServiceServer(send, port = 0) {
|
|
|
2768
2894
|
chunks.push(chunk);
|
|
2769
2895
|
});
|
|
2770
2896
|
request.on("end", () => {
|
|
2771
|
-
if (!refused) proxy(request, response, chunks, send, cookies);
|
|
2897
|
+
if (!refused) proxy(request, response, chunks, send, cookies, policy);
|
|
2772
2898
|
});
|
|
2773
2899
|
});
|
|
2774
2900
|
await new Promise((resolve, reject) => {
|
|
@@ -2785,7 +2911,7 @@ async function openServiceServer(send, port = 0) {
|
|
|
2785
2911
|
url: `http://${host}${OPEN_PATH}${token}`
|
|
2786
2912
|
};
|
|
2787
2913
|
}
|
|
2788
|
-
async function proxy(request, response, chunks, send, cookies) {
|
|
2914
|
+
async function proxy(request, response, chunks, send, cookies, policy) {
|
|
2789
2915
|
const stop = new AbortController();
|
|
2790
2916
|
response.on("close", () => {
|
|
2791
2917
|
if (!response.writableFinished) stop.abort();
|
|
@@ -2818,7 +2944,7 @@ async function proxy(request, response, chunks, send, cookies) {
|
|
|
2818
2944
|
if (policy) out[lower] = [...out[lower] ?? [], policy];
|
|
2819
2945
|
} else out[lower] = value;
|
|
2820
2946
|
}
|
|
2821
|
-
out["content-security-policy"] = [...out["content-security-policy"] ?? [],
|
|
2947
|
+
out["content-security-policy"] = [...out["content-security-policy"] ?? [], policy];
|
|
2822
2948
|
response.writeHead(answer.status, out);
|
|
2823
2949
|
await pipeline(Readable.from(answer.body, { objectMode: false }), response);
|
|
2824
2950
|
} catch (error) {
|
|
@@ -2933,6 +3059,7 @@ var SERVICE_METHODS = {
|
|
|
2933
3059
|
/** A contact's shared app on a loopback port of this machine, as the Desktop opens it in a window. */
|
|
2934
3060
|
async "service.open"(ctx, params) {
|
|
2935
3061
|
if (ctx.mode !== "daemon") throw new CliError("unavailable", "An opened service lives in the daemon: start `ghostly daemon --detach` first");
|
|
3062
|
+
if (state(ctx).settings?.relayOnly === true) throw new CliError("unavailable", SERVICE_OPEN_OFF_RELAY_ONLY);
|
|
2936
3063
|
const link = chatOf(ctx, params);
|
|
2937
3064
|
const service = str(params, "service", true);
|
|
2938
3065
|
const key = `${link.peerPubKeyZ32}/${service}`;
|
|
@@ -3360,7 +3487,7 @@ function walletJson(instance, s) {
|
|
|
3360
3487
|
break;
|
|
3361
3488
|
case "lightning": {
|
|
3362
3489
|
const card = view?.lightnings?.find((c) => c.card === instance.card);
|
|
3363
|
-
balance = card?.balance ?? null;
|
|
3490
|
+
balance = (card?.providerId === "cashu-mint" ? view?.balance : card?.balance) ?? null;
|
|
3364
3491
|
status = card?.status ?? null;
|
|
3365
3492
|
error = card?.error ?? null;
|
|
3366
3493
|
break;
|
|
@@ -3451,10 +3578,13 @@ function badMintUrl(error) {
|
|
|
3451
3578
|
const code = error instanceof Error ? error.engineCode : void 0;
|
|
3452
3579
|
return code === "invalidMintUrl" || code === "mintNotHttps";
|
|
3453
3580
|
}
|
|
3581
|
+
/** What the engine's faucet says with no test mint to ask. */
|
|
3582
|
+
var NO_TEST_MINT = /^The faucet did not pay: This wallet has no test mint\b/;
|
|
3454
3583
|
/**
|
|
3455
3584
|
* The engine's wallet refusals about what the person asked, by the words it writes (they carry no `engineCode`): a
|
|
3456
3585
|
* 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.
|
|
3586
|
+
* it with. Before, each was `engine` (exit 1), which a bot reads as the engine failing and may retry. With no wallet of
|
|
3587
|
+
* the type at all, `wallet faucet`, `wallet receive` and `wallet address` say which to make first (`noWalletOf`).
|
|
3458
3588
|
*/
|
|
3459
3589
|
var WALLET_REFUSALS = [
|
|
3460
3590
|
[/^There is no .+ to remove$/, "not_found"],
|
|
@@ -3463,23 +3593,38 @@ var WALLET_REFUSALS = [
|
|
|
3463
3593
|
[/^You already have a .+ wallet$/, "refused"],
|
|
3464
3594
|
[/^No mint could create an invoice: No mint configured$/, "unavailable"],
|
|
3465
3595
|
[/^No Bitcoin source is set up$/, "unavailable"],
|
|
3466
|
-
[
|
|
3467
|
-
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"]
|
|
3596
|
+
[NO_TEST_MINT, "unavailable"],
|
|
3597
|
+
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"],
|
|
3598
|
+
[/^Nothing to (reclaim|take back)$/, "refused"],
|
|
3599
|
+
[/^This request is no longer open$/, "refused"],
|
|
3600
|
+
[/^This invoice is already paid$/, "refused"]
|
|
3468
3601
|
];
|
|
3602
|
+
var WALLET_NAMES = {
|
|
3603
|
+
cashu: "Cashu",
|
|
3604
|
+
lightning: "Lightning",
|
|
3605
|
+
arkade: "Arkade",
|
|
3606
|
+
bark: "Bark",
|
|
3607
|
+
spark: "Spark",
|
|
3608
|
+
bitcoin: "Bitcoin",
|
|
3609
|
+
fedimint: "Fedimint",
|
|
3610
|
+
usdt: "USDT"
|
|
3611
|
+
};
|
|
3469
3612
|
/**
|
|
3470
|
-
*
|
|
3471
|
-
*
|
|
3472
|
-
*
|
|
3613
|
+
* A request refused for want of a wallet of that type and network at all: `chat pay`, `chat request`, `wallet receive`
|
|
3614
|
+
* and the Cashu faucet with no Cashu wallet, an address with no wallet of its type. The engine says the wallet is short
|
|
3615
|
+
* of sats, that it has no mint or source, and names nothing to do. `refused` with the command that makes one, as a
|
|
3616
|
+
* contact with no wallet is told; `details.reason` `no_wallet`. With a wallet, the engine's own words.
|
|
3473
3617
|
*/
|
|
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"}
|
|
3618
|
+
function noWalletOf(ctx, n, error, type = "cashu") {
|
|
3619
|
+
if ((state(ctx).wallet.wallets ?? []).some((w) => w.type === type && w.network === n)) return error;
|
|
3620
|
+
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
3621
|
}
|
|
3478
3622
|
var engineCode = (error) => error instanceof Error ? error.engineCode : void 0;
|
|
3479
3623
|
/** 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
3624
|
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
3625
|
function walletRefusal(error) {
|
|
3482
3626
|
if (!(error instanceof Error) || error instanceof CliError) return error;
|
|
3627
|
+
if (error.name === "SwapUnsettledError") return new CliError("unavailable", error.message);
|
|
3483
3628
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
3484
3629
|
return code ? new CliError(code, error.message) : error;
|
|
3485
3630
|
}
|
|
@@ -3566,6 +3711,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3566
3711
|
type,
|
|
3567
3712
|
network: "testnet",
|
|
3568
3713
|
...card ? { card } : {}
|
|
3714
|
+
}).catch((error) => {
|
|
3715
|
+
throw error instanceof Error && NO_TEST_MINT.test(error.message) ? noWalletOf(ctx, "testnet", error) : error;
|
|
3569
3716
|
});
|
|
3570
3717
|
},
|
|
3571
3718
|
async "wallet.history"(ctx, params) {
|
|
@@ -3591,6 +3738,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3591
3738
|
amount,
|
|
3592
3739
|
network: n,
|
|
3593
3740
|
...card ? { card } : {}
|
|
3741
|
+
}).catch((error) => {
|
|
3742
|
+
throw error instanceof Error && NO_MINT.test(error.message) ? noWalletOf(ctx, n, error) : error;
|
|
3594
3743
|
});
|
|
3595
3744
|
return {
|
|
3596
3745
|
network: n,
|
|
@@ -3607,11 +3756,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3607
3756
|
if (type === "bitcoin") return {
|
|
3608
3757
|
type,
|
|
3609
3758
|
network: n,
|
|
3610
|
-
address: await node(ctx).bitcoinReceiveAddress({ network: n })
|
|
3759
|
+
address: await node(ctx).bitcoinReceiveAddress({ network: n }).catch((error) => {
|
|
3760
|
+
throw error instanceof Error && /^No Bitcoin source is set up$/.test(error.message) ? noWalletOf(ctx, n, error, "bitcoin") : error;
|
|
3761
|
+
})
|
|
3611
3762
|
};
|
|
3612
3763
|
const view = netView(state(ctx), n);
|
|
3613
3764
|
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}`);
|
|
3765
|
+
if (!address) throw noWalletOf(ctx, n, new CliError("unavailable", `No ${type} wallet with an address on ${n}`), type);
|
|
3615
3766
|
return {
|
|
3616
3767
|
type,
|
|
3617
3768
|
network: n,
|
|
@@ -3821,7 +3972,9 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3821
3972
|
},
|
|
3822
3973
|
async "payment.check"(ctx, params) {
|
|
3823
3974
|
const link = chatOf(ctx, params);
|
|
3824
|
-
|
|
3975
|
+
const p = state(ctx).payments[str(params, "payment", true)];
|
|
3976
|
+
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})`);
|
|
3977
|
+
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
3978
|
await node(ctx).checkPayment({
|
|
3826
3979
|
linkId: link.id,
|
|
3827
3980
|
paymentId: str(params, "payment", true)
|
|
@@ -3889,7 +4042,7 @@ function redactSettings(settings, showSecret = false) {
|
|
|
3889
4042
|
};
|
|
3890
4043
|
}
|
|
3891
4044
|
/** Settings a command may change; the rest are the app's to manage. */
|
|
3892
|
-
var
|
|
4045
|
+
var SETTABLE_KINDS = {
|
|
3893
4046
|
relays: "strings",
|
|
3894
4047
|
irohRelays: "strings",
|
|
3895
4048
|
hyperdhtRelay: "string",
|
|
@@ -3902,6 +4055,30 @@ var SETTABLE = {
|
|
|
3902
4055
|
autoDownloads: "boolean",
|
|
3903
4056
|
serveFiles: "boolean"
|
|
3904
4057
|
};
|
|
4058
|
+
var SETTABLE = SETTABLE_KINDS;
|
|
4059
|
+
/**
|
|
4060
|
+
* What a setting of the table reads as while the engine keeps none (types.ts `Settings`): a switch that is on and the
|
|
4061
|
+
* default relays are kept as absent (node.ts `updateSettings` deletes `sendTyping: true`, an empty `irohRelays`...).
|
|
4062
|
+
* Every key of the table the engine may leave out needs one here, or tsc fails.
|
|
4063
|
+
*/
|
|
4064
|
+
var SETTING_DEFAULTS = {
|
|
4065
|
+
irohRelays: () => [...DEFAULT_IROH_RELAYS],
|
|
4066
|
+
hyperdhtRelay: () => "",
|
|
4067
|
+
publicProfiles: () => true,
|
|
4068
|
+
shareProfile: () => true,
|
|
4069
|
+
sendTyping: () => true,
|
|
4070
|
+
autoDownloads: () => true,
|
|
4071
|
+
serveFiles: () => true
|
|
4072
|
+
};
|
|
4073
|
+
/**
|
|
4074
|
+
* The settings as `settings get` and `settings set` answer them: each key `settings set` takes, with its value in
|
|
4075
|
+
* effect. Before, a switch that is on (absent as kept) was never shown, and a fresh profile showed 4 of the 11 keys.
|
|
4076
|
+
*/
|
|
4077
|
+
function settingsInEffect(settings) {
|
|
4078
|
+
const filled = { ...settings };
|
|
4079
|
+
for (const key of Object.keys(SETTABLE_KINDS)) if (filled[key] === void 0 && Object.hasOwn(SETTING_DEFAULTS, key)) filled[key] = SETTING_DEFAULTS[key]();
|
|
4080
|
+
return filled;
|
|
4081
|
+
}
|
|
3905
4082
|
/**
|
|
3906
4083
|
* A relay address the engine refuses (node.ts `updateSettings`, irohWeb.ts, hyperdhtRelay.ts): the person's value, so
|
|
3907
4084
|
* `bad_request` named by its key, in a terminal's words ("give", not the app's "Enter"). Before, `engine` (exit 1). A
|
|
@@ -3919,7 +4096,7 @@ function relayRefused(error, patch) {
|
|
|
3919
4096
|
/** The engine keeps a chat's name to 48 characters (code points: `renameLink`). */
|
|
3920
4097
|
var CHAT_NAME_LENGTH = 48;
|
|
3921
4098
|
/**
|
|
3922
|
-
* A chat's name on this side (`chat rename`, an invite's `--label`), as the engine stores it (`
|
|
4099
|
+
* A chat's name on this side (`chat rename`, an invite's `--label`), as the engine stores it (`shownName`): a tab or a
|
|
3923
4100
|
* line break is a space, invisible characters go, and what is left is counted. Longer than the engine keeps whole is
|
|
3924
4101
|
* refused, not cut. An empty name (or spaces) is the documented one of `chat rename` (the contact's own name) and no
|
|
3925
4102
|
* 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 +4105,7 @@ var CHAT_NAME_LENGTH = 48;
|
|
|
3928
4105
|
function chatName(params, name) {
|
|
3929
4106
|
const value = str(params, name);
|
|
3930
4107
|
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)`);
|
|
4108
|
+
const clean = shownName(value, CHAT_NAME_LENGTH, "A chat's name", " (an empty name gives back the contact's own)");
|
|
3934
4109
|
if (groupPrefixed(clean) !== null) throw new CliError("bad_request", `A chat's name can't start with "group:": that names a group`);
|
|
3935
4110
|
return clean;
|
|
3936
4111
|
}
|
|
@@ -4065,6 +4240,32 @@ var METHODS = {
|
|
|
4065
4240
|
...ctx.listen && { listen: true }
|
|
4066
4241
|
};
|
|
4067
4242
|
},
|
|
4243
|
+
/**
|
|
4244
|
+
* This profile's status (WISP 401 § Presence and status), said to every paired contact whose app offers `status/1`:
|
|
4245
|
+
* at once on a live session, else on each chat's next one. A new one replaces the one before, whole.
|
|
4246
|
+
*/
|
|
4247
|
+
async "status.get"(ctx) {
|
|
4248
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4249
|
+
},
|
|
4250
|
+
async "status.set"(ctx, params) {
|
|
4251
|
+
const until = params.until === void 0 ? void 0 : num(params, "until", 0, {
|
|
4252
|
+
min: 1,
|
|
4253
|
+
whole: true
|
|
4254
|
+
});
|
|
4255
|
+
const status = checkOwnStatus({
|
|
4256
|
+
text: str(params, "text"),
|
|
4257
|
+
emoji: str(params, "emoji"),
|
|
4258
|
+
availability: str(params, "availability"),
|
|
4259
|
+
until
|
|
4260
|
+
}, (field) => field, "bad_request");
|
|
4261
|
+
guardText(status.text, bool(params, "force"), "status", "set it");
|
|
4262
|
+
await node(ctx).setOwnStatus({ status });
|
|
4263
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4264
|
+
},
|
|
4265
|
+
async "status.clear"(ctx) {
|
|
4266
|
+
await node(ctx).clearOwnStatus();
|
|
4267
|
+
return statusJson(node(ctx).getOwnStatus().status);
|
|
4268
|
+
},
|
|
4068
4269
|
async "profile.get"(ctx) {
|
|
4069
4270
|
const { settings } = state(ctx);
|
|
4070
4271
|
return {
|
|
@@ -4084,7 +4285,7 @@ var METHODS = {
|
|
|
4084
4285
|
return METHODS["profile.get"](ctx, {});
|
|
4085
4286
|
},
|
|
4086
4287
|
async "settings.get"(ctx, params) {
|
|
4087
|
-
return redactSettings(state(ctx).settings, bool(params, "showSecret"));
|
|
4288
|
+
return redactSettings(settingsInEffect(state(ctx).settings), bool(params, "showSecret"));
|
|
4088
4289
|
},
|
|
4089
4290
|
async "settings.set"(ctx, params) {
|
|
4090
4291
|
const patch = {};
|
|
@@ -4121,7 +4322,7 @@ var METHODS = {
|
|
|
4121
4322
|
throw relayRefused(error, patch);
|
|
4122
4323
|
});
|
|
4123
4324
|
return {
|
|
4124
|
-
...redactSettings(state(ctx).settings),
|
|
4325
|
+
...redactSettings(settingsInEffect(state(ctx).settings)),
|
|
4125
4326
|
...warning ? { warning } : {}
|
|
4126
4327
|
};
|
|
4127
4328
|
},
|
|
@@ -4178,7 +4379,7 @@ var METHODS = {
|
|
|
4178
4379
|
},
|
|
4179
4380
|
async "chat.list"(ctx, params) {
|
|
4180
4381
|
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) };
|
|
4382
|
+
return { chats: state(ctx).links.map((link) => chatJson(link, showSecret)).sort((a, b) => (b.lastMessageAt ?? 0) - (a.lastMessageAt ?? 0) || b.createdAt - a.createdAt) };
|
|
4182
4383
|
},
|
|
4183
4384
|
async "chat.get"(ctx, params) {
|
|
4184
4385
|
const link = chatNotGroup(ctx, params, "group show");
|
|
@@ -4199,11 +4400,12 @@ var METHODS = {
|
|
|
4199
4400
|
const secret = findSecret(text);
|
|
4200
4401
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; send it with --force if you mean to`, { kind: secret.kind });
|
|
4201
4402
|
}
|
|
4403
|
+
const unjoined = nobodyJoined(link);
|
|
4202
4404
|
const wait = oneOf(params, "wait", [
|
|
4203
4405
|
"none",
|
|
4204
4406
|
"sent",
|
|
4205
4407
|
"delivered"
|
|
4206
|
-
], "none");
|
|
4408
|
+
], ctx.mode === "one-shot" && !unjoined ? "sent" : "none");
|
|
4207
4409
|
const ms = num(params, "timeout", 30, {
|
|
4208
4410
|
min: 1,
|
|
4209
4411
|
max: 3600
|
|
@@ -4217,7 +4419,10 @@ var METHODS = {
|
|
|
4217
4419
|
...replyTo ? { replyTo } : {},
|
|
4218
4420
|
...card ? { card } : {}
|
|
4219
4421
|
});
|
|
4220
|
-
if (result.error) throw
|
|
4422
|
+
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
4423
|
+
group: false,
|
|
4424
|
+
ref: str(params, "chat", true)
|
|
4425
|
+
}) || (/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
4426
|
if (!result.messageId) throw new CliError("bad_request", "Nothing to send");
|
|
4222
4427
|
let message = await node(ctx).getMessage(link.id, result.messageId);
|
|
4223
4428
|
if (wait !== "none") message = await waitForMessage(ctx, link.id, result.messageId, wait, ms);
|
|
@@ -4229,7 +4434,8 @@ var METHODS = {
|
|
|
4229
4434
|
buttons: card.id,
|
|
4230
4435
|
card,
|
|
4231
4436
|
pressable: pressable(link)
|
|
4232
|
-
} : {}
|
|
4437
|
+
} : {},
|
|
4438
|
+
...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
4439
|
};
|
|
4234
4440
|
},
|
|
4235
4441
|
/**
|
|
@@ -4244,25 +4450,26 @@ var METHODS = {
|
|
|
4244
4450
|
const secret = findSecret(text);
|
|
4245
4451
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; edit with --force if you mean to`, { kind: secret.kind });
|
|
4246
4452
|
}
|
|
4247
|
-
const wait =
|
|
4248
|
-
const ms = num(params, "timeout", 30, {
|
|
4249
|
-
min: 1,
|
|
4250
|
-
max: 3600
|
|
4251
|
-
}) * 1e3;
|
|
4453
|
+
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
4252
4454
|
const result = await node(ctx).editMessage({
|
|
4253
4455
|
linkId: link.id,
|
|
4254
4456
|
messageId,
|
|
4255
4457
|
text
|
|
4256
4458
|
});
|
|
4257
|
-
if (result.error) throw editRefused(await messageOf(ctx, link.id, messageId), messageId,
|
|
4459
|
+
if (result.error) throw editRefused(await messageOf(ctx, link.id, messageId), messageId, {
|
|
4460
|
+
group: false,
|
|
4461
|
+
ref: str(params, "chat", true)
|
|
4462
|
+
}, result.error, result.refused);
|
|
4258
4463
|
const id = result.messageId ?? messageId;
|
|
4259
4464
|
let message = await node(ctx).getMessage(link.id, id);
|
|
4260
4465
|
if (wait === "confirmed" && message?.edit?.pending) message = await waitForEdit(ctx, link.id, id, ms);
|
|
4466
|
+
const confirmed = !!message && !message.edit?.pending;
|
|
4261
4467
|
return {
|
|
4262
4468
|
chat: link.id,
|
|
4263
4469
|
messageId: id,
|
|
4264
4470
|
edits: message?.edit?.seq ?? 0,
|
|
4265
|
-
confirmed
|
|
4471
|
+
confirmed,
|
|
4472
|
+
...!confirmed && keptForJoin(ctx, link.id, "the edit")
|
|
4266
4473
|
};
|
|
4267
4474
|
},
|
|
4268
4475
|
/**
|
|
@@ -4311,46 +4518,77 @@ var METHODS = {
|
|
|
4311
4518
|
*/
|
|
4312
4519
|
async "chat.react"(ctx, params) {
|
|
4313
4520
|
const link = chatNotGroup(ctx, params, "group react", "<message> <emoji>");
|
|
4314
|
-
const { wait, ms } = confirmWait(ctx, params);
|
|
4521
|
+
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
4315
4522
|
const before = Math.max(...node(ctx).chatUnconfirmed({ linkId: link.id }).reactions);
|
|
4316
|
-
const result = await react(ctx, link.id, params
|
|
4523
|
+
const result = await react(ctx, link.id, params, {
|
|
4524
|
+
group: false,
|
|
4525
|
+
ref: str(params, "chat", true)
|
|
4526
|
+
});
|
|
4317
4527
|
const pending = (left) => left.reactions.some((n) => n > before);
|
|
4318
4528
|
if (wait === "confirmed") await waitForConfirmed(ctx, link.id, "reaction", pending, ms);
|
|
4529
|
+
const confirmed = !pending(node(ctx).chatUnconfirmed({ linkId: link.id }));
|
|
4319
4530
|
return {
|
|
4320
4531
|
chat: link.id,
|
|
4321
4532
|
...result,
|
|
4322
|
-
confirmed
|
|
4533
|
+
confirmed,
|
|
4534
|
+
...!confirmed && keptForJoin(ctx, link.id, "the reaction")
|
|
4323
4535
|
};
|
|
4324
4536
|
},
|
|
4325
4537
|
/**
|
|
4326
4538
|
* WISP 400 § Pinned message: one per chat or group, a new pin replaces it; `remove` unpins. In a community only the
|
|
4327
4539
|
* 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.
|
|
4540
|
+
* confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has. A
|
|
4541
|
+
* group has no receipts: `wait: sent` (a one-shot's default) stays until an edge took it, and `edges` and `sent` say
|
|
4542
|
+
* how many did, as for `group react`.
|
|
4329
4543
|
*/
|
|
4330
4544
|
async "chat.pin"(ctx, params) {
|
|
4331
4545
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4332
4546
|
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
|
-
|
|
4547
|
+
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)");
|
|
4548
|
+
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");
|
|
4549
|
+
const { wait, ms } = target.group ? {
|
|
4550
|
+
wait: oneOf(params, "wait", ["none", "sent"], ctx.mode === "one-shot" ? "sent" : "none"),
|
|
4551
|
+
ms: num(params, "timeout", 30, {
|
|
4552
|
+
min: 1,
|
|
4553
|
+
max: 3600
|
|
4554
|
+
}) * 1e3
|
|
4555
|
+
} : confirmWait(ctx, params, target.linkId);
|
|
4335
4556
|
const result = await node(ctx).pinMessage({
|
|
4336
4557
|
linkId: target.linkId,
|
|
4337
4558
|
...messageId && { messageId },
|
|
4338
4559
|
remove
|
|
4339
4560
|
});
|
|
4561
|
+
const gone = result.error && messageId ? notHere(result.error, messageId, {
|
|
4562
|
+
group: target.group,
|
|
4563
|
+
ref: str(params, "chat", true)
|
|
4564
|
+
}) : void 0;
|
|
4565
|
+
if (gone) throw gone;
|
|
4340
4566
|
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
|
-
|
|
4567
|
+
if (target.group) {
|
|
4568
|
+
const n = result.n, pinned = remove ? null : messageId;
|
|
4569
|
+
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, target.id, messageId ?? "", { pin: n }, ms) : node(ctx).groupTaken({
|
|
4570
|
+
groupId: target.id,
|
|
4571
|
+
messageId: messageId ?? "",
|
|
4572
|
+
pin: n
|
|
4573
|
+
});
|
|
4574
|
+
return {
|
|
4575
|
+
group: target.id,
|
|
4576
|
+
messageId: pinned,
|
|
4577
|
+
removed: remove,
|
|
4578
|
+
sent: edges > 0,
|
|
4579
|
+
edges
|
|
4580
|
+
};
|
|
4581
|
+
}
|
|
4346
4582
|
const mine = node(ctx).chatUnconfirmed({ linkId: target.linkId }).pin;
|
|
4347
4583
|
const pending = (left) => mine !== null && left.pin === mine;
|
|
4348
4584
|
if (wait === "confirmed") await waitForConfirmed(ctx, target.linkId, "pin", pending, ms);
|
|
4585
|
+
const confirmed = !pending(node(ctx).chatUnconfirmed({ linkId: target.linkId }));
|
|
4349
4586
|
return {
|
|
4350
4587
|
chat: target.id,
|
|
4351
4588
|
messageId: remove ? null : messageId,
|
|
4352
4589
|
removed: remove,
|
|
4353
|
-
confirmed
|
|
4590
|
+
confirmed,
|
|
4591
|
+
...!confirmed && keptForJoin(ctx, target.linkId, remove ? "the unpin" : "the pin")
|
|
4354
4592
|
};
|
|
4355
4593
|
},
|
|
4356
4594
|
/** 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 +4634,10 @@ var METHODS = {
|
|
|
4396
4634
|
const chosen = [];
|
|
4397
4635
|
for (const id of messageIds) {
|
|
4398
4636
|
const message = await node(ctx).getMessage(from.linkId, id);
|
|
4399
|
-
if (!message) throw
|
|
4637
|
+
if (!message) throw noMessage(id, {
|
|
4638
|
+
group: from.group,
|
|
4639
|
+
ref: str(params, "chat", true)
|
|
4640
|
+
});
|
|
4400
4641
|
chosen.push(message);
|
|
4401
4642
|
}
|
|
4402
4643
|
if (!bool(params, "force")) for (const message of chosen) {
|
|
@@ -4407,6 +4648,7 @@ var METHODS = {
|
|
|
4407
4648
|
});
|
|
4408
4649
|
}
|
|
4409
4650
|
const wait = oneOf(params, "wait", ["none", "sent"], "none");
|
|
4651
|
+
const groupWait = params.wait === void 0 && ctx.mode === "one-shot" ? "sent" : wait;
|
|
4410
4652
|
const ms = num(params, "timeout", 30, {
|
|
4411
4653
|
min: 1,
|
|
4412
4654
|
max: 3600
|
|
@@ -4428,11 +4670,19 @@ var METHODS = {
|
|
|
4428
4670
|
sent: result.sent,
|
|
4429
4671
|
error: result.error
|
|
4430
4672
|
}));
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4673
|
+
for (const [i, result] of out.entries()) if (to[i].group) {
|
|
4674
|
+
let edges;
|
|
4675
|
+
for (const messageId of result.messageIds) {
|
|
4676
|
+
const took = groupWait === "sent" ? await waitForGroupFrame(ctx, to[i].id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
4677
|
+
groupId: to[i].id,
|
|
4678
|
+
messageId
|
|
4679
|
+
});
|
|
4680
|
+
edges = Math.min(edges ?? took, took);
|
|
4435
4681
|
}
|
|
4682
|
+
result.edges = edges ?? 0;
|
|
4683
|
+
}
|
|
4684
|
+
if (wait === "sent") for (const [i, result] of out.entries()) for (const messageId of result.messageIds) {
|
|
4685
|
+
if (to[i].group) continue;
|
|
4436
4686
|
const sent = await node(ctx).getMessage(to[i].id, messageId);
|
|
4437
4687
|
if (sent?.file) await FILE_METHODS["file.wait"](ctx, {
|
|
4438
4688
|
chat: to[i].id,
|
|
@@ -4455,8 +4705,15 @@ var METHODS = {
|
|
|
4455
4705
|
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
4706
|
const messageId = str(params, "message", true);
|
|
4457
4707
|
const message = await node(ctx).getMessage(link.id, messageId);
|
|
4458
|
-
|
|
4459
|
-
|
|
4708
|
+
const place = {
|
|
4709
|
+
group: false,
|
|
4710
|
+
ref: str(params, "chat", true)
|
|
4711
|
+
};
|
|
4712
|
+
if (!message) throw noMessage(messageId, place);
|
|
4713
|
+
if (message.sender !== "me") throw noMessage(messageId, place, {
|
|
4714
|
+
whose: "of yours",
|
|
4715
|
+
tail: ": only your own messages are sent again"
|
|
4716
|
+
});
|
|
4460
4717
|
if (message.delivery === "delivered") throw new CliError("refused", "Nothing to send again: it was delivered");
|
|
4461
4718
|
await node(ctx).retryMessage({
|
|
4462
4719
|
linkId: link.id,
|
|
@@ -4483,7 +4740,13 @@ var METHODS = {
|
|
|
4483
4740
|
}) * 1e3;
|
|
4484
4741
|
const ref = str(params, "message", true);
|
|
4485
4742
|
const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
|
|
4486
|
-
if (!message) throw
|
|
4743
|
+
if (!message) throw noMessage(ref, {
|
|
4744
|
+
group: target.group,
|
|
4745
|
+
ref: str(params, "chat", true)
|
|
4746
|
+
}, {
|
|
4747
|
+
whose: "of yours",
|
|
4748
|
+
tail: ": only your own messages are deleted for everyone"
|
|
4749
|
+
});
|
|
4487
4750
|
const result = await node(ctx).removeMessage({
|
|
4488
4751
|
linkId: target.linkId,
|
|
4489
4752
|
messageId: message.id
|
|
@@ -4520,8 +4783,11 @@ var METHODS = {
|
|
|
4520
4783
|
const ref = str(params, "message") ?? "<message>";
|
|
4521
4784
|
const link = chatNotGroup(ctx, params, "message delete", `${/^[\w.:<>-]+$/.test(ref) ? ref : JSON.stringify(ref)} --everyone`);
|
|
4522
4785
|
const messageId = str(params, "message", true);
|
|
4523
|
-
if (!await node(ctx).getMessage(link.id, messageId)) throw
|
|
4524
|
-
|
|
4786
|
+
if (!await node(ctx).getMessage(link.id, messageId)) throw noMessage(messageId, {
|
|
4787
|
+
group: false,
|
|
4788
|
+
ref: str(params, "chat", true)
|
|
4789
|
+
});
|
|
4790
|
+
const { everyone } = node(ctx).deleteMessage({
|
|
4525
4791
|
linkId: link.id,
|
|
4526
4792
|
messageId
|
|
4527
4793
|
});
|
|
@@ -4529,17 +4795,21 @@ var METHODS = {
|
|
|
4529
4795
|
chat: link.id,
|
|
4530
4796
|
messageId,
|
|
4531
4797
|
deleted: messageId,
|
|
4532
|
-
everyone
|
|
4798
|
+
everyone
|
|
4533
4799
|
};
|
|
4534
4800
|
},
|
|
4535
4801
|
/** 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
4802
|
async "chat.details"(ctx, params) {
|
|
4537
4803
|
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
4804
|
+
const messageId = str(params, "message", true);
|
|
4538
4805
|
const details = await node(ctx).messageDetails({
|
|
4539
4806
|
linkId: target.linkId,
|
|
4540
|
-
messageId
|
|
4807
|
+
messageId
|
|
4808
|
+
});
|
|
4809
|
+
if (!details) throw noMessage(messageId, {
|
|
4810
|
+
group: target.group,
|
|
4811
|
+
ref: str(params, "chat", true)
|
|
4541
4812
|
});
|
|
4542
|
-
if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this ${target.group ? "group" : "chat"}`);
|
|
4543
4813
|
return details;
|
|
4544
4814
|
},
|
|
4545
4815
|
async "chat.rename"(ctx, params) {
|
|
@@ -4556,6 +4826,7 @@ var METHODS = {
|
|
|
4556
4826
|
noCallOn(ctx, link.id, "remove the chat");
|
|
4557
4827
|
await node(ctx).removeLink({ linkId: link.id });
|
|
4558
4828
|
ctx.calls.forgetChat(link.id);
|
|
4829
|
+
ctx.groupAuto.forgetChat(link.id);
|
|
4559
4830
|
return { removed: link.id };
|
|
4560
4831
|
},
|
|
4561
4832
|
async "chat.transport"(ctx, params) {
|
|
@@ -4590,14 +4861,15 @@ var METHODS = {
|
|
|
4590
4861
|
*/
|
|
4591
4862
|
async "chat.disconnect"(ctx, params) {
|
|
4592
4863
|
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, {
|
|
4864
|
+
const minutes = params.hold === void 0 ? void 0 : num(params, "hold", 0, {
|
|
4598
4865
|
min: 0,
|
|
4599
4866
|
max: HOLD_MAX_MINUTES
|
|
4600
4867
|
});
|
|
4868
|
+
if (minutes !== 0) somebodyJoined(link);
|
|
4869
|
+
if (minutes === void 0) {
|
|
4870
|
+
node(ctx).disconnect({ linkId: link.id });
|
|
4871
|
+
return chatJson(findChat(state(ctx).links, link.id));
|
|
4872
|
+
}
|
|
4601
4873
|
if (minutes > 0) noCallOn(ctx, link.id, "hold the chat");
|
|
4602
4874
|
if (minutes === 0) await releaseHold(ctx, link.id, "lifted");
|
|
4603
4875
|
else await holdChat(ctx, link, minutes);
|
|
@@ -4636,9 +4908,7 @@ var METHODS = {
|
|
|
4636
4908
|
}, ms, `chat ${link.id} ${chatState(until).to}`));
|
|
4637
4909
|
},
|
|
4638
4910
|
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`);
|
|
4911
|
+
const name = groupNameOf(params);
|
|
4642
4912
|
guardText(name, bool(params, "force"), "group's name", "create it");
|
|
4643
4913
|
const profile = oneOf(params, "profile", ["community", "mesh"], "community");
|
|
4644
4914
|
const { groupId } = await node(ctx).createGroup({
|
|
@@ -4664,7 +4934,18 @@ var METHODS = {
|
|
|
4664
4934
|
},
|
|
4665
4935
|
async "group.list"(ctx, params) {
|
|
4666
4936
|
const showSecret = bool(params, "showSecret");
|
|
4667
|
-
return {
|
|
4937
|
+
return {
|
|
4938
|
+
groups: state(ctx).groups.map((g) => groupJson(g, showSecret)).sort((a, b) => (b.lastMessageAt ?? 0) - (a.lastMessageAt ?? 0)),
|
|
4939
|
+
autoJoin: ctx.groupAuto.get()
|
|
4940
|
+
};
|
|
4941
|
+
},
|
|
4942
|
+
/** Invitations over the chats named accepted by the daemon itself (`group auto on --from`); no argument: the setting. */
|
|
4943
|
+
async "group.auto"(ctx, params) {
|
|
4944
|
+
if (params.on === void 0) return { autoJoin: ctx.groupAuto.get() };
|
|
4945
|
+
return { autoJoin: ctx.groupAuto.set({
|
|
4946
|
+
on: bool(params, "on"),
|
|
4947
|
+
from: list(params, "from")
|
|
4948
|
+
}) };
|
|
4668
4949
|
},
|
|
4669
4950
|
async "group.get"(ctx, params) {
|
|
4670
4951
|
return groupJson(groupOf(ctx, params, "chat show <chat>"), bool(params, "showSecret"));
|
|
@@ -4697,7 +4978,10 @@ var METHODS = {
|
|
|
4697
4978
|
...replyTo ? { replyTo } : {},
|
|
4698
4979
|
...card ? { card } : {}
|
|
4699
4980
|
});
|
|
4700
|
-
if (result.error) throw
|
|
4981
|
+
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
4982
|
+
group: true,
|
|
4983
|
+
ref: str(params, "group", true)
|
|
4984
|
+
}) || (result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
4701
4985
|
const messageId = result.messageId ?? null;
|
|
4702
4986
|
const edges = messageId ? wait === "sent" ? await waitForGroupFrame(ctx, group.id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
4703
4987
|
groupId: group.id,
|
|
@@ -4741,7 +5025,10 @@ var METHODS = {
|
|
|
4741
5025
|
text,
|
|
4742
5026
|
...mentions.length ? { mentions } : {}
|
|
4743
5027
|
});
|
|
4744
|
-
if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId,
|
|
5028
|
+
if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId, {
|
|
5029
|
+
group: true,
|
|
5030
|
+
ref: str(params, "group", true)
|
|
5031
|
+
}, result.error, result.refused);
|
|
4745
5032
|
const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
|
|
4746
5033
|
if (edits === before) return {
|
|
4747
5034
|
group: group.id,
|
|
@@ -4764,11 +5051,31 @@ var METHODS = {
|
|
|
4764
5051
|
edges
|
|
4765
5052
|
};
|
|
4766
5053
|
},
|
|
5054
|
+
/**
|
|
5055
|
+
* WISP 400 § Reactions in a group, which has no receipts: `edges` says how many took it, `sent` whether one did.
|
|
5056
|
+
* `wait: sent` (a one-shot's default: what is not said yet leaves with the process) stays until an edge took it.
|
|
5057
|
+
*/
|
|
4767
5058
|
async "group.react"(ctx, params) {
|
|
4768
5059
|
const group = groupOf(ctx, params, "react <chat> <message> <emoji>");
|
|
5060
|
+
const wait = oneOf(params, "wait", ["none", "sent"], ctx.mode === "one-shot" ? "sent" : "none");
|
|
5061
|
+
const ms = num(params, "timeout", 30, {
|
|
5062
|
+
min: 1,
|
|
5063
|
+
max: 3600
|
|
5064
|
+
}) * 1e3;
|
|
5065
|
+
const { n, ...said } = await react(ctx, `group:${group.id}`, params, {
|
|
5066
|
+
group: true,
|
|
5067
|
+
ref: str(params, "group", true)
|
|
5068
|
+
});
|
|
5069
|
+
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, group.id, said.messageId, { reaction: n }, ms) : node(ctx).groupTaken({
|
|
5070
|
+
groupId: group.id,
|
|
5071
|
+
messageId: said.messageId,
|
|
5072
|
+
reaction: n
|
|
5073
|
+
});
|
|
4769
5074
|
return {
|
|
4770
5075
|
group: group.id,
|
|
4771
|
-
...
|
|
5076
|
+
...said,
|
|
5077
|
+
sent: edges > 0,
|
|
5078
|
+
edges
|
|
4772
5079
|
};
|
|
4773
5080
|
},
|
|
4774
5081
|
/**
|
|
@@ -4838,7 +5145,7 @@ var METHODS = {
|
|
|
4838
5145
|
},
|
|
4839
5146
|
async "events.replay"(ctx, params) {
|
|
4840
5147
|
return {
|
|
4841
|
-
events: ctx.hub.replay(
|
|
5148
|
+
events: ctx.hub.replay(sinceSeq(params, 0)),
|
|
4842
5149
|
lastSeq: ctx.hub.lastSeq
|
|
4843
5150
|
};
|
|
4844
5151
|
},
|
|
@@ -4881,7 +5188,10 @@ var METHODS = {
|
|
|
4881
5188
|
if (typeof target !== "function") throw new CliError("not_found", `The engine has no call ${method}`);
|
|
4882
5189
|
try {
|
|
4883
5190
|
const result = await target.call(node(ctx), args) ?? null;
|
|
4884
|
-
if (method === "removeLink")
|
|
5191
|
+
if (method === "removeLink") {
|
|
5192
|
+
ctx.calls.forgetChat(str(args ?? {}, "linkId", true));
|
|
5193
|
+
ctx.groupAuto.forgetChat(str(args ?? {}, "linkId", true));
|
|
5194
|
+
}
|
|
4885
5195
|
return result;
|
|
4886
5196
|
} catch (error) {
|
|
4887
5197
|
if (error instanceof TypeError && BAD_VALUE.test(error.message)) throw wrong("a parameter of the wrong kind", error.message);
|
|
@@ -4957,20 +5267,24 @@ async function guardEngineSend(ctx, method, args) {
|
|
|
4957
5267
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; call ${method} with --force if you mean to`, { kind: secret.kind });
|
|
4958
5268
|
}
|
|
4959
5269
|
/**
|
|
4960
|
-
* How long `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed
|
|
4961
|
-
*
|
|
5270
|
+
* How long `edit`, `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed, since what is
|
|
5271
|
+
* not said yet leaves with the process; a daemon goes on saying it, so it answers at once unless asked to wait, as a
|
|
5272
|
+
* one-shot does on a chat nobody joined yet (`oneShotWaits`).
|
|
4962
5273
|
*/
|
|
4963
|
-
function confirmWait(ctx, params) {
|
|
5274
|
+
function confirmWait(ctx, params, chat) {
|
|
4964
5275
|
return {
|
|
4965
|
-
wait: oneOf(params, "wait", ["none", "confirmed"], ctx
|
|
5276
|
+
wait: oneOf(params, "wait", ["none", "confirmed"], oneShotWaits(ctx, chat) ? "confirmed" : "none"),
|
|
4966
5277
|
ms: num(params, "timeout", 30, {
|
|
4967
5278
|
min: 1,
|
|
4968
5279
|
max: 3600
|
|
4969
5280
|
}) * 1e3
|
|
4970
5281
|
};
|
|
4971
5282
|
}
|
|
4972
|
-
/**
|
|
4973
|
-
|
|
5283
|
+
/**
|
|
5284
|
+
* Reacts to a message of a chat or a group (`group:<id>`): `emoji`, or `remove` for "" (WISP 400 § Reactions). In a
|
|
5285
|
+
* group, `n` is the reaction's number, for `groupTaken`.
|
|
5286
|
+
*/
|
|
5287
|
+
async function react(ctx, linkId, params, place) {
|
|
4974
5288
|
const messageId = str(params, "message", true);
|
|
4975
5289
|
const removed = bool(params, "remove");
|
|
4976
5290
|
const emoji = removed ? "" : str(params, "emoji");
|
|
@@ -4980,11 +5294,14 @@ async function react(ctx, linkId, params) {
|
|
|
4980
5294
|
messageId,
|
|
4981
5295
|
emoji: emoji ?? ""
|
|
4982
5296
|
});
|
|
5297
|
+
const gone = result.error ? notHere(result.error, messageId, place) : void 0;
|
|
5298
|
+
if (gone) throw gone;
|
|
4983
5299
|
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
5300
|
return {
|
|
4985
5301
|
messageId,
|
|
4986
5302
|
emoji: emoji || null,
|
|
4987
|
-
removed
|
|
5303
|
+
removed,
|
|
5304
|
+
...result.n ? { n: result.n } : {}
|
|
4988
5305
|
};
|
|
4989
5306
|
}
|
|
4990
5307
|
/**
|
|
@@ -5044,14 +5361,23 @@ function chatNotGroup(ctx, params, command, rest = "") {
|
|
|
5044
5361
|
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
|
|
5045
5362
|
}
|
|
5046
5363
|
/**
|
|
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
|
-
*
|
|
5364
|
+
* 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
|
|
5365
|
+
* message id is (`noMessage`); before, a mistyped or lost id read "Only your own text messages can be edited"
|
|
5366
|
+
* (`refused`, exit 1), as if the message were someone else's.
|
|
5050
5367
|
*/
|
|
5051
|
-
function editRefused(message, ref,
|
|
5052
|
-
if (refused && !message) return
|
|
5368
|
+
function editRefused(message, ref, place, error, refused) {
|
|
5369
|
+
if (refused && !message) return noMessage(ref, place);
|
|
5053
5370
|
return new CliError(refused ? "refused" : "unavailable", error);
|
|
5054
5371
|
}
|
|
5372
|
+
/**
|
|
5373
|
+
* The engine's "That message is not in this chat" (", or takes no reaction", ", or cannot be pinned", ", or cannot be
|
|
5374
|
+
* replied to") for the message `id`, said as `noMessage` says it, with that reason kept; undefined for any other error.
|
|
5375
|
+
* The engine says "chat" in a group for a reply and a save: `place` says which it is.
|
|
5376
|
+
*/
|
|
5377
|
+
function notHere(error, id, place) {
|
|
5378
|
+
const said = /^That message is not in this (?:chat|group)(?:, or (.+))?$/.exec(error);
|
|
5379
|
+
return said ? noMessage(id, place, said[1] ? { tail: `, or it ${said[1]}` } : {}) : void 0;
|
|
5380
|
+
}
|
|
5055
5381
|
/** The chat link's own wait for a contact (`GhostLink.connect`): `chat connect --timeout` waits at most that long. */
|
|
5056
5382
|
var CONNECT_MAX_SECONDS = 90;
|
|
5057
5383
|
/**
|
|
@@ -5083,7 +5409,10 @@ async function saveMark(ctx, params, remove) {
|
|
|
5083
5409
|
remove
|
|
5084
5410
|
});
|
|
5085
5411
|
const where = target.group ? "group" : "chat";
|
|
5086
|
-
if (result.error && /not in this chat/.test(result.error)) throw new CliError("not_found",
|
|
5412
|
+
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, {
|
|
5413
|
+
group: target.group,
|
|
5414
|
+
ref: str(params, "chat", true)
|
|
5415
|
+
});
|
|
5087
5416
|
if (result.error) throw new CliError("bad_request", result.error);
|
|
5088
5417
|
return {
|
|
5089
5418
|
[target.group ? "group" : "chat"]: target.id,
|
|
@@ -5113,7 +5442,13 @@ async function historyOf(ctx, chat, params, json = messageJson) {
|
|
|
5113
5442
|
before,
|
|
5114
5443
|
...after !== void 0 && { after }
|
|
5115
5444
|
}).catch((error) => {
|
|
5116
|
-
|
|
5445
|
+
const missing = [before, after].find((id) => error instanceof Error && error.message === `No message ${id}`);
|
|
5446
|
+
if (missing === void 0) throw error;
|
|
5447
|
+
const group = chat.startsWith("group:");
|
|
5448
|
+
throw noMessage(String(missing), {
|
|
5449
|
+
group,
|
|
5450
|
+
ref: str(params, group ? "group" : "chat", true)
|
|
5451
|
+
});
|
|
5117
5452
|
});
|
|
5118
5453
|
const originals = await originalsNow(ctx, chat, page.messages);
|
|
5119
5454
|
return {
|
|
@@ -5174,6 +5509,6 @@ async function callApi(ctx, method, params = {}) {
|
|
|
5174
5509
|
return run(ctx, await withStoredIds(ctx, params));
|
|
5175
5510
|
}
|
|
5176
5511
|
//#endregion
|
|
5177
|
-
export {
|
|
5512
|
+
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
5513
|
|
|
5179
|
-
//# sourceMappingURL=api-
|
|
5514
|
+
//# sourceMappingURL=api-CTqIcdu7.js.map
|