@ghostlytools/cli 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -13
- package/dist/assets/{api-CHD8_kcJ.js → api-ButrHieZ.js} +2 -2
- package/dist/assets/{api-CMohP9Pw.js → api-DDmune9b.js} +352 -120
- package/dist/assets/api-DDmune9b.js.map +1 -0
- package/dist/assets/{apiKit-CfwVtBcw.js → apiKit-DfFlJhXO.js} +4 -4
- package/dist/assets/apiKit-DfFlJhXO.js.map +1 -0
- package/dist/assets/{apps-733nXRBy.js → apps-BVnNpB2f.js} +1 -1
- package/dist/assets/{apps-LG-QOIxs.js → apps-CpQVuYqT.js} +17 -16
- package/dist/assets/apps-CpQVuYqT.js.map +1 -0
- package/dist/assets/{arkade-C8x3Efyj.js → arkade-C9Ne-zJb.js} +12 -5
- package/dist/assets/arkade-C9Ne-zJb.js.map +1 -0
- package/dist/assets/{backup-nCbNWJ7-.js → backup-DavZrUf6.js} +1 -1
- package/dist/assets/{backup-CfJenOQo.js → backup-MN2sZQeW.js} +11 -8
- package/dist/assets/backup-MN2sZQeW.js.map +1 -0
- 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-1wUBd8ZD.js → blobFiles-B6nf0gCG.js} +3 -3
- package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B6nf0gCG.js.map} +1 -1
- package/dist/assets/buttons-DC20Q2no.js +2 -0
- package/dist/assets/{buttons-BC0stvPg.js → buttons-DIWDW2n5.js} +23 -6
- package/dist/assets/buttons-DIWDW2n5.js.map +1 -0
- package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-ui8jtIw0.js} +19 -37
- package/dist/assets/daemonProof-ui8jtIw0.js.map +1 -0
- package/dist/assets/{endpoint-Cl3cgAYl.js → endpoint-BdaeBw2L.js} +3 -3
- package/dist/assets/endpoint-BdaeBw2L.js.map +1 -0
- package/dist/assets/{envelope-BbvUBjc5.js → envelope-ByeUit1N.js} +2 -2
- package/dist/assets/{envelope-BbvUBjc5.js.map → envelope-ByeUit1N.js.map} +1 -1
- package/dist/assets/{errors-BLSPp0tK.js → errors-CzXgR8Cc.js} +39 -4
- package/dist/assets/errors-CzXgR8Cc.js.map +1 -0
- package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-BMEBas7S.js} +3 -3
- package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-BMEBas7S.js.map} +1 -1
- package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-CFNrRfcl.js} +2 -2
- package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-CFNrRfcl.js.map} +1 -1
- package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-CtwagJ8h.js} +1 -1
- package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-BXAN7i-N.js} +7 -7
- package/dist/assets/fileBytesIdb-BXAN7i-N.js.map +1 -0
- package/dist/assets/fileBytesIdb-C20oXDdr.js +2 -0
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-Do1Vpkis.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-Do1Vpkis.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js → ghostly_iroh_web-BXCsSxxo.js} +29 -29
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js.map → ghostly_iroh_web-BXCsSxxo.js.map} +1 -1
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-Bmo-SkVQ.js → groupFiles-DVxX0O1g.js} +61 -17
- package/dist/assets/groupFiles-DVxX0O1g.js.map +1 -0
- package/dist/assets/{host-DxDRCRKD.js → host-AB2Cr46b.js} +127 -48
- package/dist/assets/host-AB2Cr46b.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js → hyperdhtRelay-BcrwJRtb.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js.map → hyperdhtRelay-BcrwJRtb.js.map} +1 -1
- package/dist/assets/{idb-BJARz3Qi.js → idb-BlH8-O3R.js} +35 -5
- package/dist/assets/idb-BlH8-O3R.js.map +1 -0
- package/dist/assets/{irohWeb-BUvaADop.js → irohWeb-B5j2rgWj.js} +3 -3
- package/dist/assets/{irohWeb-BUvaADop.js.map → irohWeb-B5j2rgWj.js.map} +1 -1
- package/dist/assets/{main-BIXIs84L.js → main-AHz1dbsm.js} +227 -62
- package/dist/assets/main-AHz1dbsm.js.map +1 -0
- package/dist/assets/{mainline-HQVJ5ukA.js → mainline-afyQ77bv.js} +46 -16
- package/dist/assets/mainline-afyQ77bv.js.map +1 -0
- package/dist/assets/{networkReason-CKBiFTwt.js → networkReason-DWzsMN8E.js} +3 -3
- package/dist/assets/{networkReason-CKBiFTwt.js.map → networkReason-DWzsMN8E.js.map} +1 -1
- package/dist/assets/{nwc-Dm4RSvvF.js → nwc-DYXTp8UX.js} +3 -3
- package/dist/assets/{nwc-Dm4RSvvF.js.map → nwc-DYXTp8UX.js.map} +1 -1
- package/dist/assets/{nwcProvider-yQdL-DfC.js → nwcProvider-B4k6mYJl.js} +2 -2
- package/dist/assets/{nwcProvider-yQdL-DfC.js.map → nwcProvider-B4k6mYJl.js.map} +1 -1
- package/dist/assets/{profiles-BehWURA9.js → profiles-CEnZfN78.js} +74 -13
- package/dist/assets/profiles-CEnZfN78.js.map +1 -0
- package/dist/assets/{registry-CHVZ0Jzl.js → registry-Ccru6KBP.js} +1 -1
- package/dist/assets/{registry-C9f2Ogff.js → registry-wSZHgbsv.js} +3 -3
- package/dist/assets/{registry-C9f2Ogff.js.map → registry-wSZHgbsv.js.map} +1 -1
- package/dist/assets/{resolve-Cqj1jjK2.js → resolve-BPJnMtLC.js} +2 -2
- package/dist/assets/{resolve-Cqj1jjK2.js.map → resolve-BPJnMtLC.js.map} +1 -1
- package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-Fv-MuY45.js} +2 -2
- package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-Fv-MuY45.js.map} +1 -1
- package/dist/assets/{server-CcAs54Yb.js → server-DPzt5V2x.js} +993 -283
- package/dist/assets/server-DPzt5V2x.js.map +1 -0
- package/dist/assets/{src-BLHey3Q1.js → src-CFeRBeHz.js} +518 -134
- package/dist/assets/src-CFeRBeHz.js.map +1 -0
- package/dist/assets/{usdt-DMKpMhdM.js → usdt-CBh78JVF.js} +3 -3
- package/dist/assets/{usdt-DMKpMhdM.js.map → usdt-CBh78JVF.js.map} +1 -1
- package/dist/assets/{words-DUlvkoUT.js → words-DC8BQvPO.js} +4 -4
- package/dist/assets/words-DC8BQvPO.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/payment-bot.mjs +5 -2
- package/package.json +1 -1
- package/dist/assets/api-CMohP9Pw.js.map +0 -1
- package/dist/assets/apiKit-CfwVtBcw.js.map +0 -1
- package/dist/assets/apps-LG-QOIxs.js.map +0 -1
- package/dist/assets/arkade-C8x3Efyj.js.map +0 -1
- package/dist/assets/backup-CfJenOQo.js.map +0 -1
- package/dist/assets/buttons-BC0stvPg.js.map +0 -1
- package/dist/assets/buttons-BDKeKyKw.js +0 -2
- package/dist/assets/daemonProof-CWTVNUmr.js.map +0 -1
- package/dist/assets/endpoint-Cl3cgAYl.js.map +0 -1
- package/dist/assets/errors-BLSPp0tK.js.map +0 -1
- package/dist/assets/fileBytesIdb-BIFKtgln.js.map +0 -1
- package/dist/assets/fileBytesIdb-BVVr_rWX.js +0 -2
- package/dist/assets/groupFiles-Bmo-SkVQ.js.map +0 -1
- package/dist/assets/host-DxDRCRKD.js.map +0 -1
- package/dist/assets/idb-BJARz3Qi.js.map +0 -1
- package/dist/assets/main-BIXIs84L.js.map +0 -1
- package/dist/assets/mainline-HQVJ5ukA.js.map +0 -1
- package/dist/assets/profiles-BehWURA9.js.map +0 -1
- package/dist/assets/server-CcAs54Yb.js.map +0 -1
- package/dist/assets/src-BLHey3Q1.js.map +0 -1
- package/dist/assets/words-DUlvkoUT.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $
|
|
2
|
+
import { $c as createContactLink, $i as automaticTransport, $l as PacketTooLargeError, $o as HANDOFF_OFFER, $r as vapidKeysMatch, $s as readEnrollHello, A as knockRecords, Aa as GROUP_REACTION_FRAME, Al as firstDeviceSetSecret, An as findEndpoint, Ao as webLocalFetch, As as readHandoffPake, B as GROUP_READ_NOTE, Ba as pairedReplyAuthor, Bi as IdentityExchange, Bl as DEFAULT_RELAYS, Bn as EngineError, Bo as contactRtcConfig, Br as mayPin, Bs as verifySetUpdate, C as decodeCommunityLink, Ca as REMOVED_TEXT, Cc as APP_BUNDLE_LIMITS, Cr as rankHubs, Cs as handoffVersions, D as encodeGroupEntryLink, Da as forwardedAgain, Dc as appDigest, Dl as turnPutSummary, Dn as ENDPOINT, Do as GhostlyHttpError, Dr as shouldBeHub, Ds as readHandoffDone, E as decodeGroupEntryLink, Ea as parseLinkPreview, El as classifyTurnRead, En as decodeBolt11, Eo as presenceSeenAt, Er as readLobby, Es as readHandoffCancel, F as groupWakeFrame, Fa as reactionEmoji, Fc as sha256Paced, Fi as dialDescriptors, Fl as turnInstance, Fn as INVITE_TAKEN, Fo as RTC_CONFIG, Fr as TypingSender, G as GROUP_EDIT_TEXT_BYTES, Gi as newIdentityBinding, Go as HTTP_SERVICE_PROTO, Gr as WAKE_CALL_INTERVAL_MS, Gs as enrollCancelFrame, Gt as encodeDidDhtPacket, H as frameBytes, Ha as replySnippet, Hc as isAppKey, Hi as emptyIdentityLedger, Hn as engineText, Ho as parseCallSignal, Hr as pinIsNewer, Ht as didDhtDocument, I as groupWakes, Ia as reactionIsNewer, Il as turnKeys, In as LIVENESS_PING_MS, Is as readSetUpdate, J as mentionsMember, Jc as parseImageMeta, Ji as lastSharedWithMe, Jo as HANDOFF_ACK, Jr as newWakeToken, Js as enrollDoneFrame, Jt as ETHEREUM_USDT, K as carryMentions, Ki as receivedIdentityStatus, Kl as currentRelays, Ko as LEGACY_SERVICES, Kr as WakeLimiter, Ks as enrollCancelReason, L as parseGroupWakeFrame, La as readReaction, Lc as APP_STATEMENT_LIMITS, Ll as turnName, Ln as PAIRED_FRAME_TOO_LARGE, Lr as typingActivity, Ls as setAckFrame, M as readKnocks, Ma as ReactionWindow, Mc as pacer, Mi as CapsExchange, Ml as readTurnPacket, Mn as parseCashuRequestPayload, Mo as decodeControl, Mr as transferStalled, Ms as readHandoffVerified, Na as nextReactionNumber, Ni as DHT_TEXT_CAPABILITY, Nl as signTurnPacket, Nn as parseFedimintRequestPayload, No as encodeControl, Ns as sealHandoffPiece, O as entryParams, Oa as readForwarded, Oc as appViewOf, Ol as TURN_LAST_SEQUENCE, On as cashuRequestPayload, Oo as formatLocalTarget, Or as ChatFiles, Os as readHandoffHave, P as GroupWakeLimiter, Pa as queueReaction, Pc as readAppBundleAsync, Pi as capsDescriptors, Pl as signTurnRelease, Pn as GhostLink, Qc as readCanonicalJson, Qi as TRANSPORTS, Ql as withRequestOptions, Qo as HANDOFF_HELLO, Qr as checkPushEndpoint, Qs as readEnrollGrant, Qt as SEPOLIA_TEST_USDT, R as GROUP_LIMITS, Ra as validReactionNumber, Rc as appFingerprint, Ri as IDENTITY_REVOCATION_LABEL, Rl as turnStatedVerifier, Rn as pairedMessageFits, Rs as setUpdateFrame, S as communityHasFrame, Sa as MAX_REMOVAL_NUMBER, Sc as seenEntry, Sl as webCryptoSigner, So as DHT_POLL_INTERVALS, Sr as pickHubs, Ss as handoffStreamKey, Ta as dhtEditId, Tc as APP_ICON_PATH, Tl as TURN_SETTLE_MS, To as WATCH_PEER_MS, Tr as readBeaconHead, Ts as readHandoffAck, Ua as BUTTON_ID, Uc as isAppRef, Ui as identityRevocationValue, Ul as RelayTransport, Un as parseEngineError, Ur as pinNumberHolds, Ut as didDhtFromPublicKey, V as GroupSession, Va as readReply, Vc as isAppHash, Vn as engineError, Vr as nextPinNumber, Wc as readAppRevocation, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Wo as emptyLinkRecords, Wr as readPin, Wt as encodeDidDhtDeactivated, Xa as STATUS_CARD_LIMITS, Xc as canonicalJson, Xi as emptyProofLedger, Xl as budgetRetryMs, Xo as HANDOFF_DONE, Xr as relayRequest, Xs as enrollHelloFrame, Xt as ONCHAIN_PROVIDER, Y as groupName, Yi as PeerProofs, Yl as traceLink, Yn as groupFileFallback, Yo as HANDOFF_CANCEL, Yr as parseWakeFrame, Ys as enrollGrantFrame, Yt as EVM_TEST_CHAINS, Zi as validExternalKey, Zl as isDiscoveryBudgetError, Zn as readGroupFileMeta, Zo as HANDOFF_HAVE, Zr as wakeRequest, Zs as enrollProofFrame, Zt as PaymentPreflightError, _ as openGroupTyping, _c as mergeContactKnocks, _i as readManifest, _l as deviceKeyZ32, _o as rosterHas, _r as lobbyKeys, _s as handoffManifestFrames, _u as toBase64Url, a as appStoreDecision, aa as DHT_FILE_CAPABILITY, ac as planKnocks, ai as APPS_CAPABILITY, al as OwnInviteError, an as assertWholeSats, ao as arrivalKey, as as filePartName, au as createIdentity, b as CommunitySession, ba as EDIT_BUFFER_MS, bc as readLinkRecord, bl as newDeviceSetSecret, bo as DirectPathWatch, br as mergeLobby, bs as handoffReleaseFrame, bu as utf8Encode, c as planAppUpdate, ca as sanitizeFileName, cc as turnOff, ci as STATUS_CARD_CAPABILITY, cl as encodeInviteCode, cn as walletNetworkOf, co as receivedTimestamp, cr as MESH_HUBS, cs as handoffAttemptSucceeded, cu as publicKeyFromZ32, dc as contactDay, di as HOLD_DATED_BACK_MS, dn as sparkAddressKind, do as GROUP_MEMBER_CAP, dr as pickMeshHubs, ds as handoffContext, du as sanitizeAvatar, ec as verifyEnrollProof, ei as APP_RANGE_LIMITS, el as encodeContactLink, en as TEST_USDT_FAUCET_AMOUNT, es as HANDOFF_PAKE, f as readAppStoreSteps, fc as knockSlotIdentity, fi as HOLD_LIMITS, fl as DEVICES_CAPABILITY, fn as sparkInvoiceDetails, fr as COMMUNITY_TOPOLOGY, fs as handoffContextProof, fu as sanitizeDisplayText, g as groupTypingEpoch, ga as parseVoiceMeta, gc as makeStampPaced, gi as newMailbox, gl as deviceEchoNonce, go as rosterAdmin, gr as freshHubs, gs as handoffHelloFrame, gt as normalizeAtprotoHandle, gu as randomBytes, h as GroupTypingBoard, ha as fileMessageText, hc as linkRecords, hi as isHoldUrl, hl as deviceEchoFrame, hn as isPubkyKey, ho as parseGroupCommit, hr as doorHubs, hs as handoffEphemeral, ht as isAtprotoDid, i as appRevocationFor, ia as peekDhtMailbox, ic as newInbox, ii as isAppVersion, il as readDeviceInvite, in as assertTokenUnits, io as statusCardText, is as HANDOFF_VERIFIED, j as mergeKnocks, ja as REACTION_LIMITS, jc as isAppUrl, jl as nextTurnPosition, jn as isFederationId, jo as LIMITS, jr as transferEnded, js as readHandoffTurnFrame, k as knockIdentity, ka as COMMUNITY_REACTION_FRAME, kl as TURN_MAX, kn as fedimintRequestPayload, ko as parseLocalTarget, kr as FILE_LIMITS, ks as readHandoffHello, l as APP_STORE_LIMITS, la as sanitizeMime, lc as ContactRequestError, li as UPGRADE_CAPABILITY, ll as inviteLink, ln as SPARK_NETWORKS, lo as shownTime, lr as mayBeHub, ls as handoffBusyFrame, lu as verify, mc as knockSlotRecords, mi as HoldRefusedError, ml as HANDOFF_CAPABILITY, mo as commitHash, mr as beaconRecords, ms as handoffDigest, mu as fromBase64Url, n as readX401SdJwtVc, nc as endedRequests, nl as createDeviceInvite, nn as WALLET_NETWORKS, no as checkStatusCard, ns as HANDOFF_REQUEST, o as appUpdateDecision, oa as dhtFileId, oc as settleRequest, oi as BUTTONS_CAPABILITY, ol as createChatInvite, on as formatPaymentAmount, oo as claimedTime, or as groupSignalFrame, os as handoffAttemptAllowed, ou as identityFromSeed, pc as knockSlotOf, pi as HoldKeys, pl as ENROLL_CAPABILITY, pn as isBitcoinAddress, po as MEMBER_KEY, pr as beaconKeys, ps as handoffDataFrame, pu as bytesEqual, q as parseCommunityEdit, qi as revokesIdentity, ql as normalizeRelayUrl, qo as serviceIdFromName, qr as deviceWakeRequest, qs as enrollDigits, qt as signDidDhtPacket, r as sameX401HolderJwk, ra as DHT_MESSAGE_TTL, rc as inboxRecord, ri as chatAppId, rl as deviceInviteJoinerParams, rn as arkAddressPrefix, ro as sameButtonText, rs as HANDOFF_TIMINGS, s as checkAppBeforeRun, sa as formatFileSize, sc as takeRequest, si as EDIT_CAPABILITY, sl as decodeInviteCode, sn as validatePaymentTarget, so as heardTime, sr as readGroupSignal, ss as handoffAttemptFailed, su as identityFromSeedB64, t as newX401HolderKey, tc as clearMissed, ti as isServeId, tl as readContactLink, tn as USDT_PUBLIC_RPC, tr as CarriedTransport, ts as HANDOFF_PIECE_BYTES, tu as createRelayPayload, uc as REQUEST_LIFETIME_MS, ui as HOLD_CAPABILITY, ul as inviteOwnership, un as SPARK_PROVIDER, uo as GROUP_ADMIN_OFF_ERROR, ur as meshHubs, us as handoffCancelFrame, v as sealGroupTyping, vc as openRequest, vl as deviceLinkPairing, vo as verifyCommitSignature, vr as lobbyRecords, vs as handoffOfferFrame, vu as toZ32, w as encodeCommunityLink, wa as RateWindow, wc as APP_BUNDLE_MAGIC, wl as TURN_RAISE_READ_TIMEOUT_MS, wo as RELAY_POLL_INTERVALS, wr as readBeacon, ws as newHandoffId, x as GROUP_READ_NOTE_COMMUNITY, xa as EDIT_RATE_WINDOW_MS, xc as requestRecords, xl as seedSigner, xr as newerHead, xs as handoffRetryAfter, y as COMMUNITY_LIMITS, ya as parseVideoMeta, yc as readKnockSlot, yl as devicePingFrame, yo as edgeParams, yr as mergeBeacon, ys as handoffPakeFrame, yu as utf8Decode, za as wireReaction, zc as appRef, zl as turnVerifierMark, zn as pairedMessageFrame, zr as PIN_LIMITS, zs as signTombstone } from "./src-CFeRBeHz.js";
|
|
3
3
|
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
6
|
-
import { a as clearProfileStores, c as
|
|
7
|
-
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-
|
|
8
|
-
import { $ as setAwayWallets, A as LightningCards, B as breezDatabaseInUse, C as FileAppender, D as streamStored, E as storedSize, F as ProviderSources, G as relayOnlyProblem, H as dropBreezDatabase, I as sourceKey, J as WrongNetworkError, K as ModeChanged, L as CASHU_MINT_SOURCE, M as isRecoveryPhrase, N as normalizePhrase, P as lightningPaying, Q as requireTurn, R as cashuMint, S as WALLET_TYPES, T as removeStored, U as iceServerProblem, V as breezDatabasesFor, W as iceServerSetting, X as awayFrom, Y as networkLabel, Z as refuseAway, _ as crossNetwork, a as storedGroupFiles, b as walletInstances, c as receivedPairedReply, d as paymentAlias, et as setSingleWriterGate, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, j as cardsKey, k as CASHU_CARD, l as replyRef, m as assertConfirmedReal, n as groupFileId, o as groupReply, p as WALLET_NAMES, q as ModeGate, r as groupFileText, s as pairedWireReply, t as GroupFileDesk, u as replyTo, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as breezDatabase } from "./groupFiles-
|
|
9
|
-
import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-
|
|
5
|
+
import { t as nwc } from "./nwcProvider-B4k6mYJl.js";
|
|
6
|
+
import { a as clearProfileStores, c as deleteDatabase, d as newestWalletTx, f as openDb, g as wrap, h as transact, i as STORES$1, l as errorLine, m as store, n as APP_STORAGE_SCOPE_INDEX, o as committed, p as profileOpenFailure, r as CARD_INDEX, s as databaseName, t as APP_STORAGE_CHAT_INDEX, u as fileStore } from "./idb-BlH8-O3R.js";
|
|
7
|
+
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-DWzsMN8E.js";
|
|
8
|
+
import { $ as setAwayWallets, A as LightningCards, B as breezDatabaseInUse, C as FileAppender, D as streamStored, E as storedSize, F as ProviderSources, G as relayOnlyProblem, H as dropBreezDatabase, I as sourceKey, J as WrongNetworkError, K as ModeChanged, L as CASHU_MINT_SOURCE, M as isRecoveryPhrase, N as normalizePhrase, P as lightningPaying, Q as requireTurn, R as cashuMint, S as WALLET_TYPES, T as removeStored, U as iceServerProblem, V as breezDatabasesFor, W as iceServerSetting, X as awayFrom, Y as networkLabel, Z as refuseAway, _ as crossNetwork, a as storedGroupFiles, b as walletInstances, c as receivedPairedReply, d as paymentAlias, et as setSingleWriterGate, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, j as cardsKey, k as CASHU_CARD, l as replyRef, m as assertConfirmedReal, n as groupFileId, o as groupReply, p as WALLET_NAMES, q as ModeGate, r as groupFileText, s as pairedWireReply, t as GroupFileDesk, u as replyTo, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as breezDatabase } from "./groupFiles-DVxX0O1g.js";
|
|
9
|
+
import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-B5j2rgWj.js";
|
|
10
10
|
import { c as isTestMint, d as paysItsOwnInvoices, l as isWorthlessMint, n as DEFAULT_MINTS, o as fakesLightning, r as TEST_MINT, t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-BrlY773j.js";
|
|
11
|
-
import { _ as reserveAdapterIds, b as testBuild, f as setOwnDidSource, g as registeredOnchainProviders, h as registeredLightningProviders, l as chosenResolver, n as resolveAtprotoDid, p as onAdaptersChanged, t as assertPublicServer, v as boundedIdentityFetch, y as verifyIdentity } from "./resolve-
|
|
12
|
-
import { i as fromBase64Url$1, n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-
|
|
13
|
-
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-
|
|
11
|
+
import { _ as reserveAdapterIds, b as testBuild, f as setOwnDidSource, g as registeredOnchainProviders, h as registeredLightningProviders, l as chosenResolver, n as resolveAtprotoDid, p as onAdaptersChanged, t as assertPublicServer, v as boundedIdentityFetch, y as verifyIdentity } from "./resolve-BPJnMtLC.js";
|
|
12
|
+
import { i as fromBase64Url$1, n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-ByeUit1N.js";
|
|
13
|
+
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-BMEBas7S.js";
|
|
14
14
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-BT_wRxab.js";
|
|
15
15
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
16
16
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
@@ -198,7 +198,7 @@ function viewNews(before, after) {
|
|
|
198
198
|
//#endregion
|
|
199
199
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
200
200
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
201
|
-
var loadUsdt = () => import("./usdt-
|
|
201
|
+
var loadUsdt = () => import("./usdt-CBh78JVF.js");
|
|
202
202
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
203
203
|
var DEFAULT_USDT = {
|
|
204
204
|
network: "ethereum",
|
|
@@ -647,7 +647,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
647
647
|
//#endregion
|
|
648
648
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
649
649
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
650
|
-
var loadArkade = () => import("./arkade-
|
|
650
|
+
var loadArkade = () => import("./arkade-C9Ne-zJb.js");
|
|
651
651
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
652
652
|
var RETIRE_READ_MS = 1e4;
|
|
653
653
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -994,8 +994,10 @@ var ArkWallet = class {
|
|
|
994
994
|
};
|
|
995
995
|
this.changed();
|
|
996
996
|
}
|
|
997
|
-
const balance = await read("balance", () => adapter.
|
|
998
|
-
|
|
997
|
+
const { balance, incoming } = await read("balance", () => adapter.balances(), {
|
|
998
|
+
balance: this.view.balance,
|
|
999
|
+
incoming: this.view.incoming
|
|
1000
|
+
});
|
|
999
1001
|
const { recoverable, sweeping, small } = await read("recoverable", () => adapter.expired(), {
|
|
1000
1002
|
recoverable: this.view.recoverable,
|
|
1001
1003
|
sweeping: this.view.sweeping,
|
|
@@ -1006,7 +1008,7 @@ var ArkWallet = class {
|
|
|
1006
1008
|
return this.view.expiresAt;
|
|
1007
1009
|
});
|
|
1008
1010
|
if (this.adapter !== adapter) return;
|
|
1009
|
-
const balancesRead = this.view.read || !failed.some((what) => what === "balance" || what === "
|
|
1011
|
+
const balancesRead = this.view.read || !failed.some((what) => what === "balance" || what === "recoverable");
|
|
1010
1012
|
const before = this.view;
|
|
1011
1013
|
this.view = {
|
|
1012
1014
|
configured: true,
|
|
@@ -4362,7 +4364,11 @@ var BdkOnchain = class BdkOnchain {
|
|
|
4362
4364
|
this.changeset = stored ? bdk.ChangeSet.from_json(stored.changeset) : void 0;
|
|
4363
4365
|
this.reserved = (stored?.reserved ?? []).filter((r) => Date.now() - r.at < RESERVATION_MS);
|
|
4364
4366
|
this.scanned = stored?.scanned ?? false;
|
|
4367
|
+
this.shown = new Map(Object.entries(stored?.shown ?? {}).map(([index, at]) => [Number(index), at]));
|
|
4368
|
+
this.openedAt = Date.now();
|
|
4365
4369
|
}
|
|
4370
|
+
shown;
|
|
4371
|
+
openedAt;
|
|
4366
4372
|
scanned;
|
|
4367
4373
|
/**
|
|
4368
4374
|
* Checks the settings, finds an Esplora server on the wallet's chain, and loads the wallet. What fails
|
|
@@ -4445,10 +4451,26 @@ var BdkOnchain = class BdkOnchain {
|
|
|
4445
4451
|
this.syncing = void 0;
|
|
4446
4452
|
});
|
|
4447
4453
|
}
|
|
4454
|
+
/**
|
|
4455
|
+
* Where to be paid: a new address, unless STOP_GAP - 1 handed out already wait unpaid. Then the unpaid one shown
|
|
4456
|
+
* longest ago, once that is ADDRESS_HOLD_MS: a restore's full scan stops after STOP_GAP unused addresses in a row, so
|
|
4457
|
+
* a payment past more unpaid requests than that was never found from the phrase (agents#1634), and every address
|
|
4458
|
+
* revealed is read at every sync. Only where each of those is still held for someone is a new one revealed anyway.
|
|
4459
|
+
*/
|
|
4448
4460
|
async receiveAddress() {
|
|
4449
|
-
|
|
4461
|
+
let unused = this.wallet.list_unused_addresses("external");
|
|
4462
|
+
if (unused.length >= 19) try {
|
|
4463
|
+
await this.sync();
|
|
4464
|
+
unused = this.wallet.list_unused_addresses("external");
|
|
4465
|
+
} catch {}
|
|
4466
|
+
const now = Date.now();
|
|
4467
|
+
const shownAt = (index) => this.shown.get(index) ?? this.openedAt;
|
|
4468
|
+
const info = (unused.length < 19 ? void 0 : unused.filter((info) => now - shownAt(info.index) >= 36e5).sort((a, b) => shownAt(a.index) - shownAt(b.index) || a.index - b.index)[0]) ?? this.wallet.reveal_next_address("external");
|
|
4469
|
+
this.shown.set(info.index, now);
|
|
4470
|
+
const open = new Set(unused.map((u) => u.index));
|
|
4471
|
+
for (const index of this.shown.keys()) if (index !== info.index && !open.has(index)) this.shown.delete(index);
|
|
4450
4472
|
this.persist();
|
|
4451
|
-
return address;
|
|
4473
|
+
return info.address.toString();
|
|
4452
4474
|
}
|
|
4453
4475
|
async balance() {
|
|
4454
4476
|
await this.sync();
|
|
@@ -4653,7 +4675,8 @@ var BdkOnchain = class BdkOnchain {
|
|
|
4653
4675
|
const value = {
|
|
4654
4676
|
changeset: this.changeset.to_json(),
|
|
4655
4677
|
reserved: this.reserved,
|
|
4656
|
-
scanned: this.scanned
|
|
4678
|
+
scanned: this.scanned,
|
|
4679
|
+
shown: Object.fromEntries(this.shown)
|
|
4657
4680
|
};
|
|
4658
4681
|
this.writes = this.writes.then(() => this.store.save(this.key, value)).catch(() => {});
|
|
4659
4682
|
}
|
|
@@ -6813,7 +6836,7 @@ var registry;
|
|
|
6813
6836
|
var loading$1;
|
|
6814
6837
|
var listeners = /* @__PURE__ */ new Set();
|
|
6815
6838
|
function loadIdentityProviders() {
|
|
6816
|
-
return loading$1 ??= import("./registry-
|
|
6839
|
+
return loading$1 ??= import("./registry-Ccru6KBP.js").then((m) => {
|
|
6817
6840
|
registry = m;
|
|
6818
6841
|
for (const listener of listeners) listener();
|
|
6819
6842
|
return m;
|
|
@@ -7630,7 +7653,7 @@ var ProfileDid = class {
|
|
|
7630
7653
|
return this.seed;
|
|
7631
7654
|
}
|
|
7632
7655
|
async save(next) {
|
|
7633
|
-
await
|
|
7656
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(next, KEY$1));
|
|
7634
7657
|
this.stored = next;
|
|
7635
7658
|
}
|
|
7636
7659
|
};
|
|
@@ -10871,7 +10894,11 @@ var SavedMessages = class {
|
|
|
10871
10894
|
if (row) return row;
|
|
10872
10895
|
}
|
|
10873
10896
|
}
|
|
10874
|
-
/**
|
|
10897
|
+
/**
|
|
10898
|
+
* Saves a message, or unsaves it with `remove`. Saving one already saved keeps its first time. `removed`: whether a
|
|
10899
|
+
* mark went. An id that names neither a mark nor a message of the chat (a typo) is "not in this chat", as `save` says
|
|
10900
|
+
* it; before, it answered done and the message meant stayed saved (agents#1580).
|
|
10901
|
+
*/
|
|
10875
10902
|
save({ linkId, messageId, remove }) {
|
|
10876
10903
|
return this.serial(async () => {
|
|
10877
10904
|
if (typeof linkId !== "string" || !linkId) return { error: "No chat named" };
|
|
@@ -10886,8 +10913,15 @@ var SavedMessages = class {
|
|
|
10886
10913
|
if (next.length !== marks.length) {
|
|
10887
10914
|
await this.write(next);
|
|
10888
10915
|
this.changed();
|
|
10916
|
+
return {
|
|
10917
|
+
error: null,
|
|
10918
|
+
removed: true
|
|
10919
|
+
};
|
|
10889
10920
|
}
|
|
10890
|
-
return
|
|
10921
|
+
return row ? {
|
|
10922
|
+
error: null,
|
|
10923
|
+
removed: false
|
|
10924
|
+
} : { error: "That message is not in this chat" };
|
|
10891
10925
|
}
|
|
10892
10926
|
const row = await this.row(linkId, messageId);
|
|
10893
10927
|
if (!row) return { error: "That message is not in this chat" };
|
|
@@ -11612,7 +11646,7 @@ var Apps = class {
|
|
|
11612
11646
|
}
|
|
11613
11647
|
async putApp(app) {
|
|
11614
11648
|
try {
|
|
11615
|
-
await
|
|
11649
|
+
await committed((await store(STORES$1.apps, "readwrite")).put(app));
|
|
11616
11650
|
} finally {
|
|
11617
11651
|
this.held.delete(app.ref);
|
|
11618
11652
|
}
|
|
@@ -11655,7 +11689,7 @@ var Apps = class {
|
|
|
11655
11689
|
async writeStores(write, apply) {
|
|
11656
11690
|
const before = this.records();
|
|
11657
11691
|
const written = before.then(async (held) => {
|
|
11658
|
-
await
|
|
11692
|
+
await committed(write(await store(STORES$1.appStores, "readwrite")));
|
|
11659
11693
|
apply(held);
|
|
11660
11694
|
this.views = null;
|
|
11661
11695
|
});
|
|
@@ -11669,9 +11703,6 @@ var Apps = class {
|
|
|
11669
11703
|
putStore(record) {
|
|
11670
11704
|
return this.writeStores((records) => records.put(record), (held) => held.set(record.key, record));
|
|
11671
11705
|
}
|
|
11672
|
-
deleteStore(key) {
|
|
11673
|
-
return this.writeStores((records) => records.delete(key), (held) => held.delete(key));
|
|
11674
|
-
}
|
|
11675
11706
|
/** The stores' views, made once and again after a store is written here: an app's every storage call and chat frame checks them. */
|
|
11676
11707
|
heldViews() {
|
|
11677
11708
|
return this.views ??= this.stores().then((s) => this.storeViews(s), (error) => {
|
|
@@ -11995,8 +12026,10 @@ var Apps = class {
|
|
|
11995
12026
|
}
|
|
11996
12027
|
/**
|
|
11997
12028
|
* Adds a store the person chose: read at its URL and pinned to its key (`key`, when given, is the key the person saw,
|
|
11998
|
-
* and another one is refused). A store already added under that key
|
|
11999
|
-
*
|
|
12029
|
+
* and another one is refused). A store already added under that key keeps the URL it is read from and takes only a newer
|
|
12030
|
+
* index: a copy of its signed index at another URL, the same one or an older one, never moves it there (it would be
|
|
12031
|
+
* read only there from then on, frozen). The index the preview just read at that URL, under that key, is taken as it
|
|
12032
|
+
* is (only its expiry again), not downloaded again.
|
|
12000
12033
|
*/
|
|
12001
12034
|
async addStore({ url, key }) {
|
|
12002
12035
|
if (key !== void 0 && !isAppKey(key)) fail("store-key", "Not a store key");
|
|
@@ -12014,10 +12047,16 @@ var Apps = class {
|
|
|
12014
12047
|
if (!read.ok) fail(read.reason, "This is not a store Ghostly can read");
|
|
12015
12048
|
const { index, digest } = read.store;
|
|
12016
12049
|
const held = await this.storeRecord(index.key);
|
|
12017
|
-
const
|
|
12018
|
-
|
|
12019
|
-
|
|
12020
|
-
}
|
|
12050
|
+
const seen = held?.removed && held.seen && appStoreDecision({
|
|
12051
|
+
key: held.key,
|
|
12052
|
+
...held.seen
|
|
12053
|
+
}, {
|
|
12054
|
+
key: index.key,
|
|
12055
|
+
sequence: index.sequence,
|
|
12056
|
+
digest
|
|
12057
|
+
});
|
|
12058
|
+
if (seen === "rollback" || seen === "equivocation") fail(seen, `This store's index is older than the one you had (sequence ${held.seen.sequence})`);
|
|
12059
|
+
const record = held && !held.removed ? held : {
|
|
12021
12060
|
key: index.key,
|
|
12022
12061
|
url: at,
|
|
12023
12062
|
addedAt: this.now(),
|
|
@@ -12076,14 +12115,18 @@ var Apps = class {
|
|
|
12076
12115
|
async removeStore({ key }) {
|
|
12077
12116
|
const held = await this.storeRecord(key);
|
|
12078
12117
|
if (!held) return;
|
|
12079
|
-
|
|
12118
|
+
const seen = held.index ? {
|
|
12119
|
+
sequence: held.index.sequence,
|
|
12120
|
+
digest: held.digest ?? ""
|
|
12121
|
+
} : held.seen;
|
|
12122
|
+
await this.putStore({
|
|
12080
12123
|
key: held.key,
|
|
12081
12124
|
url: held.url,
|
|
12082
12125
|
addedAt: held.addedAt,
|
|
12083
|
-
preloaded: true,
|
|
12084
|
-
removed: true
|
|
12126
|
+
...held.preloaded && { preloaded: true },
|
|
12127
|
+
removed: true,
|
|
12128
|
+
...seen && { seen }
|
|
12085
12129
|
});
|
|
12086
|
-
else await this.deleteStore(key);
|
|
12087
12130
|
for (const app of await this.installed()) {
|
|
12088
12131
|
if (app.store !== key) continue;
|
|
12089
12132
|
const { store: _s, ...unpinned } = app;
|
|
@@ -12854,7 +12897,7 @@ var Apps = class {
|
|
|
12854
12897
|
value: text,
|
|
12855
12898
|
size
|
|
12856
12899
|
});
|
|
12857
|
-
await
|
|
12900
|
+
await committed(writing.put(counterRow(app.ref, where, next)));
|
|
12858
12901
|
this.usage.set(`${app.ref}\0${where}`, next);
|
|
12859
12902
|
});
|
|
12860
12903
|
}
|
|
@@ -12876,7 +12919,7 @@ var Apps = class {
|
|
|
12876
12919
|
where,
|
|
12877
12920
|
name
|
|
12878
12921
|
]);
|
|
12879
|
-
await (next.rows ?
|
|
12922
|
+
await (next.rows ? committed(writing.put(counterRow(app.ref, where, next))) : committed(writing.delete([
|
|
12880
12923
|
app.ref,
|
|
12881
12924
|
where,
|
|
12882
12925
|
COUNT_KEY
|
|
@@ -20800,8 +20843,9 @@ var Outbox = class {
|
|
|
20800
20843
|
};
|
|
20801
20844
|
this.now = options.now ?? Date.now;
|
|
20802
20845
|
}
|
|
20803
|
-
|
|
20804
|
-
|
|
20846
|
+
/** `messages`: the chat's history as the caller just read it (a start has), so it is not read a second time. */
|
|
20847
|
+
async recover(messages) {
|
|
20848
|
+
for (const message of messages ?? await this.store.read()) {
|
|
20805
20849
|
if (message.via === "hold" || message.sender !== "me") continue;
|
|
20806
20850
|
if (message.delivery === "queued") {
|
|
20807
20851
|
await this.queue(message, message.deliveryError ?? "Not confirmed yet.");
|
|
@@ -20822,10 +20866,13 @@ var Outbox = class {
|
|
|
20822
20866
|
}
|
|
20823
20867
|
/**
|
|
20824
20868
|
* One at a time, in the order asked: `run` starts when the turns before it are over. A turn that takes longer than
|
|
20825
|
-
* `TURN_MS` no longer holds the next one back.
|
|
20869
|
+
* `TURN_MS` no longer holds the next one back. Its `TURN_MS` counts from when it begins, not from when it was
|
|
20870
|
+
* queued: counted from the queueing, every turn queued behind a slow one was past its time when its turn came, and
|
|
20871
|
+
* they all started at once (45 whole-chat reads together after a link drop, the heap past 1 GB: agents#1693).
|
|
20826
20872
|
*/
|
|
20827
20873
|
turn(run) {
|
|
20828
|
-
const
|
|
20874
|
+
const before = this.line;
|
|
20875
|
+
const result = before.then(async () => {
|
|
20829
20876
|
if (this.dropped) {
|
|
20830
20877
|
this.dropped = false;
|
|
20831
20878
|
await this.requeueUnconfirmed();
|
|
@@ -20833,13 +20880,13 @@ var Outbox = class {
|
|
|
20833
20880
|
this.began = this.closed;
|
|
20834
20881
|
return run();
|
|
20835
20882
|
});
|
|
20836
|
-
this.line = new Promise((next) => {
|
|
20883
|
+
this.line = before.then(() => new Promise((next) => {
|
|
20837
20884
|
const timer = setTimeout(next, TURN_MS);
|
|
20838
20885
|
result.then(() => {}, () => {}).then(() => {
|
|
20839
20886
|
clearTimeout(timer);
|
|
20840
20887
|
next();
|
|
20841
20888
|
});
|
|
20842
|
-
});
|
|
20889
|
+
}));
|
|
20843
20890
|
return result;
|
|
20844
20891
|
}
|
|
20845
20892
|
/** The link has not closed since this turn began: what the turn sends goes on the link the turn looked at. */
|
|
@@ -21625,8 +21672,7 @@ var QuoteSweeps = class {
|
|
|
21625
21672
|
let state = this.chats.get(chat);
|
|
21626
21673
|
if (!state) this.chats.set(chat, state = {
|
|
21627
21674
|
due: /* @__PURE__ */ new Map(),
|
|
21628
|
-
at: -Infinity
|
|
21629
|
-
busy: false
|
|
21675
|
+
at: -Infinity
|
|
21630
21676
|
});
|
|
21631
21677
|
state.due.set(id, ref);
|
|
21632
21678
|
this.next(chat);
|
|
@@ -21636,9 +21682,18 @@ var QuoteSweeps = class {
|
|
|
21636
21682
|
clearTimeout(this.chats.get(chat)?.timer);
|
|
21637
21683
|
this.chats.delete(chat);
|
|
21638
21684
|
}
|
|
21639
|
-
|
|
21640
|
-
|
|
21685
|
+
/**
|
|
21686
|
+
* The peer stops: what waits is swept now, after a sweep still running, not dropped. Nothing would look again at the
|
|
21687
|
+
* next start, so the replies would keep the removed messages' lines for good.
|
|
21688
|
+
*/
|
|
21689
|
+
async stop() {
|
|
21690
|
+
const chats = [...this.chats];
|
|
21641
21691
|
this.chats.clear();
|
|
21692
|
+
await Promise.allSettled(chats.map(async ([chat, state]) => {
|
|
21693
|
+
clearTimeout(state.timer);
|
|
21694
|
+
await state.busy;
|
|
21695
|
+
if (state.due.size) await this.sweep(chat, state.due);
|
|
21696
|
+
}));
|
|
21642
21697
|
}
|
|
21643
21698
|
next(chat) {
|
|
21644
21699
|
const state = this.chats.get(chat);
|
|
@@ -21653,10 +21708,9 @@ var QuoteSweeps = class {
|
|
|
21653
21708
|
}
|
|
21654
21709
|
const removed = state.due;
|
|
21655
21710
|
state.due = /* @__PURE__ */ new Map();
|
|
21656
|
-
state.busy = true;
|
|
21657
21711
|
state.at = this.now();
|
|
21658
|
-
this.sweep(chat, removed).catch(() => {}).finally(() => {
|
|
21659
|
-
state.busy =
|
|
21712
|
+
state.busy = this.sweep(chat, removed).catch(() => {}).finally(() => {
|
|
21713
|
+
state.busy = void 0;
|
|
21660
21714
|
if (this.chats.get(chat) === state) this.next(chat);
|
|
21661
21715
|
});
|
|
21662
21716
|
}
|
|
@@ -22217,8 +22271,8 @@ var db = {
|
|
|
22217
22271
|
});
|
|
22218
22272
|
},
|
|
22219
22273
|
async deleteLink(linkId) {
|
|
22220
|
-
await
|
|
22221
|
-
await
|
|
22274
|
+
await committed((await store(STORES$1.links, "readwrite")).delete(linkId));
|
|
22275
|
+
await committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([linkId], [linkId, []])));
|
|
22222
22276
|
await fileStore.deleteForLink(linkId);
|
|
22223
22277
|
await removeFileBytes(`${linkId}-in-`);
|
|
22224
22278
|
await removeFileBytes(`${linkId}-out-`);
|
|
@@ -22314,7 +22368,7 @@ var db = {
|
|
|
22314
22368
|
},
|
|
22315
22369
|
/** Writes a message whether or not it is there: lines of history that change as what they tell changes. */
|
|
22316
22370
|
async putMessage(message) {
|
|
22317
|
-
await
|
|
22371
|
+
await committed((await store(STORES$1.messages, "readwrite")).put(message));
|
|
22318
22372
|
},
|
|
22319
22373
|
async updateDelivery(linkId, id, delivery, deliveryError, extra) {
|
|
22320
22374
|
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite", delivery === "sent" || delivery === "delivered" ? RELAXED : void 0);
|
|
@@ -22391,34 +22445,34 @@ var db = {
|
|
|
22391
22445
|
return results.filter((row) => !!row);
|
|
22392
22446
|
},
|
|
22393
22447
|
async deleteMessage(linkId, messageId) {
|
|
22394
|
-
await
|
|
22448
|
+
await committed((await store(STORES$1.messages, "readwrite")).delete([linkId, messageId]));
|
|
22395
22449
|
},
|
|
22396
22450
|
async getGroups() {
|
|
22397
22451
|
return wrap((await store(STORES$1.groups, "readonly")).getAll());
|
|
22398
22452
|
},
|
|
22399
22453
|
async putGroup(group) {
|
|
22400
|
-
await
|
|
22454
|
+
await committed((await store(STORES$1.groups, "readwrite")).put(group));
|
|
22401
22455
|
},
|
|
22402
22456
|
/** The group and its history. */
|
|
22403
22457
|
async deleteGroup(groupId) {
|
|
22404
|
-
await
|
|
22458
|
+
await committed((await store(STORES$1.groups, "readwrite")).delete(groupId));
|
|
22405
22459
|
const link = `group:${groupId}`;
|
|
22406
|
-
await
|
|
22460
|
+
await committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([link], [link, []])));
|
|
22407
22461
|
},
|
|
22408
22462
|
async getServices() {
|
|
22409
22463
|
return wrap((await store(STORES$1.services, "readonly")).getAll());
|
|
22410
22464
|
},
|
|
22411
22465
|
async putService(service) {
|
|
22412
|
-
await
|
|
22466
|
+
await committed((await store(STORES$1.services, "readwrite")).put(service));
|
|
22413
22467
|
},
|
|
22414
22468
|
async deleteService(serviceId) {
|
|
22415
|
-
await
|
|
22469
|
+
await committed((await store(STORES$1.services, "readwrite")).delete(serviceId));
|
|
22416
22470
|
},
|
|
22417
22471
|
async getSettings() {
|
|
22418
22472
|
return await wrap((await store(STORES$1.settings, "readonly")).get("settings")) ?? {};
|
|
22419
22473
|
},
|
|
22420
22474
|
async putSettings(settings) {
|
|
22421
|
-
await
|
|
22475
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(settings, "settings"));
|
|
22422
22476
|
}
|
|
22423
22477
|
};
|
|
22424
22478
|
//#endregion
|
|
@@ -22684,10 +22738,11 @@ var Reactions = class {
|
|
|
22684
22738
|
}
|
|
22685
22739
|
/**
|
|
22686
22740
|
* The row a received reaction names. Most often the row of that id (a group's), or of `peer_` or `me_` and that id (a
|
|
22687
|
-
* chat's)
|
|
22688
|
-
* in a group there is no other, since a row that takes a reaction goes
|
|
22689
|
-
* for so at most once a `REACTION_LOOKUP_MS` per chat, since the
|
|
22690
|
-
* meanwhile waits, and the next read finds what waited
|
|
22741
|
+
* chat's), else a row the host knows that id names (a file of mine, a payment): those are read alone. Any other (one
|
|
22742
|
+
* not here yet) is looked for in the whole chat; in a group there is no other, since a row that takes a reaction goes
|
|
22743
|
+
* by its own id there. A `received` one is looked for so at most once a `REACTION_LOOKUP_MS` per chat, since the
|
|
22744
|
+
* contact can name ids that never were: one that comes meanwhile waits, and the next read finds what waited
|
|
22745
|
+
* (`lookUpWaiting`).
|
|
22691
22746
|
*/
|
|
22692
22747
|
async find(chat, id, received = false) {
|
|
22693
22748
|
const group = isGroup$1(chat);
|
|
@@ -22697,6 +22752,10 @@ var Reactions = class {
|
|
|
22697
22752
|
if (row && replyRef(row, group) === id) return row;
|
|
22698
22753
|
}
|
|
22699
22754
|
if (group) return void 0;
|
|
22755
|
+
for (const rowId of await this.host.rows?.(chat, id) ?? []) {
|
|
22756
|
+
const row = await this.host.message(chat, rowId);
|
|
22757
|
+
if (row && replyRef(row, false) === id) return row;
|
|
22758
|
+
}
|
|
22700
22759
|
if (received && !this.lookupDue(chat)) return void 0;
|
|
22701
22760
|
}
|
|
22702
22761
|
return reactionTarget(await this.host.messages(chat), id, group);
|
|
@@ -22801,12 +22860,19 @@ function pinOfFormerMember(pin, inRoster) {
|
|
|
22801
22860
|
function mayPinIn(group) {
|
|
22802
22861
|
return !!group?.myKey && group.status === "active" && mayPin(group.profile, group.myKey, group.members.find((m) => m.role === "admin")?.key);
|
|
22803
22862
|
}
|
|
22804
|
-
/**
|
|
22863
|
+
/**
|
|
22864
|
+
* The row a pin names, when it is here: the row of that id (a group's), or of `peer_`/`me_` and that id, or one the host
|
|
22865
|
+
* knows that id names (a file of mine, a payment), each read alone; else any other of a chat's.
|
|
22866
|
+
*/
|
|
22805
22867
|
async function pinnedRow(host, chat, id) {
|
|
22806
22868
|
if (!id) return void 0;
|
|
22807
22869
|
const group = isGroup(chat);
|
|
22808
22870
|
if (host.message) {
|
|
22809
|
-
for (const rowId of group ? [id] : [
|
|
22871
|
+
for (const rowId of group ? [id] : [
|
|
22872
|
+
`peer_${id}`,
|
|
22873
|
+
`me_${id}`,
|
|
22874
|
+
...await host.rows?.(chat, id) ?? []
|
|
22875
|
+
]) {
|
|
22810
22876
|
const row = await host.message(chat, rowId);
|
|
22811
22877
|
if (row && replyRef(row, group) === id) return row;
|
|
22812
22878
|
}
|
|
@@ -22828,7 +22894,7 @@ async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
|
22828
22894
|
} : { error: "Nothing is pinned in this chat" };
|
|
22829
22895
|
if (typeof messageId !== "string" || !messageId) return { error: "No message to pin" };
|
|
22830
22896
|
const group = isGroup(chat);
|
|
22831
|
-
const target = await host.message
|
|
22897
|
+
const target = host.message ? await host.message(chat, messageId) ?? await pinnedRow(host, chat, messageId) : (await host.messages(chat)).find((m) => m.id === messageId) ?? await pinnedRow(host, chat, messageId);
|
|
22832
22898
|
const id = target && replyRef(target, group);
|
|
22833
22899
|
if (!target || !id) return { error: "That message is not in this chat, or cannot be pinned" };
|
|
22834
22900
|
return {
|
|
@@ -23351,6 +23417,13 @@ var Communities = class {
|
|
|
23351
23417
|
/** The latest message from another member, per group: what makes it unread in the list. */
|
|
23352
23418
|
lastPeerMessageAt = /* @__PURE__ */ new Map();
|
|
23353
23419
|
lastMentionAt = /* @__PURE__ */ new Map();
|
|
23420
|
+
/** The maps above, and what moved them last (`markCame`, `unmark`). */
|
|
23421
|
+
marks = {
|
|
23422
|
+
lastMessageAt: this.lastMessageAt,
|
|
23423
|
+
lastPeerMessageAt: this.lastPeerMessageAt,
|
|
23424
|
+
lastMentionAt: this.lastMentionAt,
|
|
23425
|
+
by: /* @__PURE__ */ new Map()
|
|
23426
|
+
};
|
|
23354
23427
|
refused = /* @__PURE__ */ new Map();
|
|
23355
23428
|
lastKnock = /* @__PURE__ */ new Map();
|
|
23356
23429
|
/** Joiners: groups whose knock is out (published), and the knock record it is in. */
|
|
@@ -23358,6 +23431,9 @@ var Communities = class {
|
|
|
23358
23431
|
knockAt = /* @__PURE__ */ new Map();
|
|
23359
23432
|
/** Joiners: how many others had a knock still being refreshed in the record I last read (they wait with me). */
|
|
23360
23433
|
knockingWith = /* @__PURE__ */ new Map();
|
|
23434
|
+
/** Since when this run knocks with nobody answering (`JOIN_GIVE_UP_MS`), and the joins it gave up (`Groups.giveUpJoin`). */
|
|
23435
|
+
knockingSince = /* @__PURE__ */ new Map();
|
|
23436
|
+
gaveUp = /* @__PURE__ */ new Set();
|
|
23361
23437
|
/** Joiners: the knock record a knock read whose write the relays refused, and when it was read (`knock`). */
|
|
23362
23438
|
knockRead = /* @__PURE__ */ new Map();
|
|
23363
23439
|
/** My frames an edge took, and which of them carry an edit (`frame id → editKey`). */
|
|
@@ -23431,14 +23507,9 @@ var Communities = class {
|
|
|
23431
23507
|
for (const group of groups) {
|
|
23432
23508
|
this.stored.set(group.id, group);
|
|
23433
23509
|
if (group.community) this.attach(group.community);
|
|
23434
|
-
const history = await this.store.getMessages(MESSAGE_LINK$1(group.id))
|
|
23435
|
-
|
|
23436
|
-
|
|
23437
|
-
const peerAt = cameOrWritten(lastPeer?.timestamp, lastPeer ? group.came?.peer : void 0);
|
|
23438
|
-
if (peerAt) this.lastPeerMessageAt.set(group.id, peerAt);
|
|
23439
|
-
const mention = [...history].reverse().find((m) => m.mentioned);
|
|
23440
|
-
const mentionAt = cameOrWritten(mention?.timestamp, mention ? group.came?.mention : void 0);
|
|
23441
|
-
if (mentionAt) this.lastMentionAt.set(group.id, mentionAt);
|
|
23510
|
+
const history = await this.store.getMessages(MESSAGE_LINK$1(group.id));
|
|
23511
|
+
loadMarks(this.marks, group, history);
|
|
23512
|
+
this.host.loaded?.(group.id, history);
|
|
23442
23513
|
for (const [, linkId] of this.host.entries(group.id)) if (group.joining?.linkId !== linkId) await this.host.closeEdge(linkId);
|
|
23443
23514
|
const live = this.live.get(group.id);
|
|
23444
23515
|
if (live) for (const key of this.host.edges(group.id).keys()) live.restored.set(key, 0);
|
|
@@ -23448,6 +23519,15 @@ var Communities = class {
|
|
|
23448
23519
|
record(groupId) {
|
|
23449
23520
|
return this.stored.get(groupId);
|
|
23450
23521
|
}
|
|
23522
|
+
/** What moved this group's marks last (`markCame`). */
|
|
23523
|
+
markedBy(groupId) {
|
|
23524
|
+
return this.marks.by.get(groupId);
|
|
23525
|
+
}
|
|
23526
|
+
/** A message deleted for everyone left this device: the marks it set go back (`unmark` in groups.ts). */
|
|
23527
|
+
async unmark(groupId, removed) {
|
|
23528
|
+
const group = this.stored.get(groupId);
|
|
23529
|
+
if (await unmark(this.marks, group, groupId, () => this.store.getMessages(MESSAGE_LINK$1(groupId)), removed) && group) await this.store.putGroup(group);
|
|
23530
|
+
}
|
|
23451
23531
|
views() {
|
|
23452
23532
|
return [...this.stored.values()].flatMap((group) => this.viewOf(group));
|
|
23453
23533
|
}
|
|
@@ -23477,7 +23557,8 @@ var Communities = class {
|
|
|
23477
23557
|
viaLink: true,
|
|
23478
23558
|
stage: this.joinStage(group),
|
|
23479
23559
|
since: group.joining.since,
|
|
23480
|
-
...this.knockingWith.get(group.id) ? { waiting: this.knockingWith.get(group.id) } : {}
|
|
23560
|
+
...this.knockingWith.get(group.id) ? { waiting: this.knockingWith.get(group.id) } : {},
|
|
23561
|
+
...this.gaveUp.has(group.id) && { unanswered: true }
|
|
23481
23562
|
} : void 0;
|
|
23482
23563
|
if (invitation && !this.keptWhileKnocking(live)) return [{
|
|
23483
23564
|
...base,
|
|
@@ -23494,7 +23575,8 @@ var Communities = class {
|
|
|
23494
23575
|
return !!id && this.host.linkReady(id, 2);
|
|
23495
23576
|
};
|
|
23496
23577
|
const hubs = freshHubs(this.hubs(live), this.now()).map((h) => h.key);
|
|
23497
|
-
const
|
|
23578
|
+
const roster = s.roster, inRoster = new Set(roster.map(([key]) => key));
|
|
23579
|
+
const former = Object.entries(s.state.nicks).filter(([key]) => !inRoster.has(key));
|
|
23498
23580
|
return [{
|
|
23499
23581
|
...base,
|
|
23500
23582
|
name: s.name,
|
|
@@ -23516,7 +23598,7 @@ var Communities = class {
|
|
|
23516
23598
|
hubs: hubs.length,
|
|
23517
23599
|
connected: [...edges.keys()].filter(ready).length
|
|
23518
23600
|
},
|
|
23519
|
-
members:
|
|
23601
|
+
members: roster.map(([key, role]) => ({
|
|
23520
23602
|
key,
|
|
23521
23603
|
role,
|
|
23522
23604
|
me: key === s.myKey,
|
|
@@ -23556,7 +23638,10 @@ var Communities = class {
|
|
|
23556
23638
|
if (!link) throw new Error("This is not a link to a group");
|
|
23557
23639
|
const existing = this.stored.get(link.g);
|
|
23558
23640
|
const live = this.live.get(link.g);
|
|
23559
|
-
if (existing?.joining && existing.joining.host === link.host)
|
|
23641
|
+
if (existing?.joining && existing.joining.host === link.host) {
|
|
23642
|
+
await this.knockAgain(link.g);
|
|
23643
|
+
return link.g;
|
|
23644
|
+
}
|
|
23560
23645
|
if (live) {
|
|
23561
23646
|
const s = live.session;
|
|
23562
23647
|
const door = s.entryKey === link.host;
|
|
@@ -23595,6 +23680,8 @@ var Communities = class {
|
|
|
23595
23680
|
this.knockAt.delete(link.g);
|
|
23596
23681
|
this.knockingWith.delete(link.g);
|
|
23597
23682
|
this.knockRead.delete(link.g);
|
|
23683
|
+
this.knockingSince.delete(link.g);
|
|
23684
|
+
this.gaveUp.delete(link.g);
|
|
23598
23685
|
const before = this.stored.get(link.g)?.joining;
|
|
23599
23686
|
const linkId = await this.host.openEntry(link, "guest", seedB64, link.host);
|
|
23600
23687
|
if (before && before.linkId !== linkId) await this.host.closeEdge(before.linkId);
|
|
@@ -23619,6 +23706,26 @@ var Communities = class {
|
|
|
23619
23706
|
traceJoin(link.g, "join.start");
|
|
23620
23707
|
this.knock(group, since).catch(() => {});
|
|
23621
23708
|
}
|
|
23709
|
+
/** A link join nobody answered (`JOIN_GIVE_UP_MS`) knocks again, as when the link was opened: Try again. */
|
|
23710
|
+
async knockAgain(groupId, now = this.now()) {
|
|
23711
|
+
const group = this.stored.get(groupId);
|
|
23712
|
+
if (!group?.joining || !this.gaveUp.delete(groupId)) return;
|
|
23713
|
+
this.knockingSince.set(groupId, now);
|
|
23714
|
+
this.lastKnock.delete(groupId);
|
|
23715
|
+
this.knocked.delete(groupId);
|
|
23716
|
+
this.knockRead.delete(groupId);
|
|
23717
|
+
await this.reopenEntry(group.joining);
|
|
23718
|
+
this.host.emit();
|
|
23719
|
+
this.knock(group, now).catch(() => {});
|
|
23720
|
+
}
|
|
23721
|
+
/** The joiner's side of the link's entry session, opened again where it is gone (the same key, so the same session). */
|
|
23722
|
+
async reopenEntry(joining) {
|
|
23723
|
+
if ([...this.host.entries(joining.g).values()].includes(joining.linkId)) return;
|
|
23724
|
+
await this.host.openEntry({
|
|
23725
|
+
g: joining.g,
|
|
23726
|
+
host: joining.host
|
|
23727
|
+
}, "guest", joining.seedB64, joining.host);
|
|
23728
|
+
}
|
|
23622
23729
|
/** The check is over (answered, or nobody was at the door): the group stays as it is here. */
|
|
23623
23730
|
async endCheck(group) {
|
|
23624
23731
|
const joining = group.joining;
|
|
@@ -23707,7 +23814,8 @@ var Communities = class {
|
|
|
23707
23814
|
await this.forget(groupId);
|
|
23708
23815
|
return;
|
|
23709
23816
|
}
|
|
23710
|
-
const
|
|
23817
|
+
const others = new Set(s.others);
|
|
23818
|
+
const edges = [...this.host.edges(groupId).entries()].filter(([key, id]) => others.has(key) && this.host.linkReady(id, 2));
|
|
23711
23819
|
if (!edges.length) throw new Error("Nobody in the group is connected right now to take your leave. Try again in a moment.");
|
|
23712
23820
|
let next;
|
|
23713
23821
|
if (s.isAdmin) {
|
|
@@ -23799,11 +23907,11 @@ var Communities = class {
|
|
|
23799
23907
|
if (live?.hub) await this.publishBeacon(groupId, live, this.now(), false).catch(() => {});
|
|
23800
23908
|
this.live.delete(groupId);
|
|
23801
23909
|
this.stored.delete(groupId);
|
|
23802
|
-
this.
|
|
23803
|
-
this.lastPeerMessageAt.delete(groupId);
|
|
23804
|
-
this.lastMentionAt.delete(groupId);
|
|
23910
|
+
dropMarks(this.marks, groupId);
|
|
23805
23911
|
this.knockingWith.delete(groupId);
|
|
23806
23912
|
this.knockRead.delete(groupId);
|
|
23913
|
+
this.knockingSince.delete(groupId);
|
|
23914
|
+
this.gaveUp.delete(groupId);
|
|
23807
23915
|
this.lineOrder.forget(MESSAGE_LINK$1(groupId));
|
|
23808
23916
|
for (const linkId of [...this.host.edges(groupId).values(), ...this.host.entries(groupId).values()]) await this.host.closeEdge(linkId);
|
|
23809
23917
|
await this.store.deleteGroup(groupId);
|
|
@@ -23827,10 +23935,23 @@ var Communities = class {
|
|
|
23827
23935
|
};
|
|
23828
23936
|
for (const group of [...this.stored.values()]) {
|
|
23829
23937
|
const live = this.live.get(group.id);
|
|
23830
|
-
if (group.joining && (this.knocking(group, live) || group.joining.check)) {
|
|
23831
|
-
const
|
|
23832
|
-
|
|
23833
|
-
|
|
23938
|
+
if (group.joining && (this.knocking(group, live) || group.joining.check) && !this.gaveUp.has(group.id)) {
|
|
23939
|
+
const knocking = this.knocking(group, live), waited = now - group.joining.since;
|
|
23940
|
+
const answered = this.host.linkReady(group.joining.linkId, 2) || !!this.host.linkSeen?.(group.joining.linkId);
|
|
23941
|
+
const since = this.knockingSince.get(group.id);
|
|
23942
|
+
if (since === void 0 || answered) this.knockingSince.set(group.id, now);
|
|
23943
|
+
if (since === void 0) await this.reopenEntry(group.joining).catch(() => {});
|
|
23944
|
+
else if (knocking && !answered && now - since > 36e5) {
|
|
23945
|
+
this.gaveUp.add(group.id);
|
|
23946
|
+
countWaitingJoin(this.host, group.id, now, false);
|
|
23947
|
+
traceJoin(group.id, "join.unanswered");
|
|
23948
|
+
await this.host.closeEdge(group.joining.linkId).catch(() => {});
|
|
23949
|
+
this.host.emit();
|
|
23950
|
+
continue;
|
|
23951
|
+
}
|
|
23952
|
+
const every = joinKnockWait(waited, this.timings, countWaitingJoin(this.host, group.id, now, knocking && !answered && waited > this.timings.patienceMs));
|
|
23953
|
+
if (!knocking && waited > CHECK_MS) await this.endCheck(group);
|
|
23954
|
+
else if (!answered && now - (this.lastKnock.get(group.id) ?? 0) >= (this.knocked.has(group.id) ? every : Math.min(every, 3e3))) await this.knock(group, now).catch(() => {});
|
|
23834
23955
|
if (!live) continue;
|
|
23835
23956
|
}
|
|
23836
23957
|
if (!live) continue;
|
|
@@ -23954,7 +24075,7 @@ var Communities = class {
|
|
|
23954
24075
|
if (s.state.pendingLeaves.some((r) => r.s !== me && this.recentHub(live, r.s))) live.lobbyBusyUntil = Math.max(live.lobbyBusyUntil, now + this.timings.lobbyBusyMs);
|
|
23955
24076
|
if (this.hubDropped(groupId, live, others, now)) live.lobbyBusyUntil = Math.max(live.lobbyBusyUntil, now + this.timings.lobbyBusyMs);
|
|
23956
24077
|
const lobbyEvery = (now < live.lobbyBusyUntil || now < (live.memberBackUntil ?? 0)) && !busy ? this.timings.lobbyPollMs : this.timings.lobbyIdlePollMs;
|
|
23957
|
-
if (now - live.lastLobbyPoll >= lobbyEvery) {
|
|
24078
|
+
if (now - live.lastLobbyPoll >= lobbyEvery || !busy && now >= (live.lobbyHeldUntil ?? Infinity)) {
|
|
23958
24079
|
live.lastLobbyPoll = now;
|
|
23959
24080
|
await this.pollLobby(groupId, live, now);
|
|
23960
24081
|
}
|
|
@@ -24018,7 +24139,9 @@ var Communities = class {
|
|
|
24018
24139
|
const check = live.lobbyChecks?.get(hub);
|
|
24019
24140
|
if (check && now >= check.at) {
|
|
24020
24141
|
live.lobbyChecks.delete(hub);
|
|
24021
|
-
|
|
24142
|
+
const lost = await this.lobbyLost(groupId, live, hub, check.ts);
|
|
24143
|
+
if (lost === "room") live.lobbyWrites.delete(hub);
|
|
24144
|
+
else if (lost === "full") live.lobbyWrites.set(hub, now - this.timings.lobbyWriteMs + this.timings.lobbyPollMs + Math.floor(this.random() * LOBBY_CHECK_JITTER_MS));
|
|
24022
24145
|
}
|
|
24023
24146
|
if (now - (live.lobbyWrites.get(hub) ?? 0) >= this.timings.lobbyWriteMs) {
|
|
24024
24147
|
live.lobbyWrites.set(hub, now);
|
|
@@ -24351,23 +24474,28 @@ var Communities = class {
|
|
|
24351
24474
|
traceJoin(groupId, "lobby.written");
|
|
24352
24475
|
}
|
|
24353
24476
|
/**
|
|
24354
|
-
* My request is not in the hub's lobby any more
|
|
24355
|
-
* reading from before mine, dropped it (
|
|
24356
|
-
*
|
|
24477
|
+
* My request is not in the hub's lobby any more (`LOBBY_CHECK_MS`). With room for it ("room"): another member's write,
|
|
24478
|
+
* made from a reading from before mine, dropped it. Full ("full"): the newer requests pushed it out, and asking again
|
|
24479
|
+
* at once would push out one of them before the hub read it, so it waits for the hub's next reading. Many members a
|
|
24480
|
+
* closed hub carried ask the hub left in the same second; with 6 places, the rest waited for the 20 s refresh while the
|
|
24481
|
+
* lobby held requests the hub had already taken, and were cut off for up to 115 s (CLI daemons, 2026-10-19). A read
|
|
24482
|
+
* that fails says nothing, and the usual refresh asks again.
|
|
24357
24483
|
*/
|
|
24358
24484
|
async lobbyLost(groupId, live, hub, ts) {
|
|
24359
24485
|
const keys = lobbyKeys(live.session.state.rv, groupId, hub);
|
|
24360
24486
|
const records = await this.host.resolve(keys.identity.pubKeyZ32, true, true).catch(() => void 0);
|
|
24361
24487
|
if (records === void 0) return false;
|
|
24362
24488
|
const entries = readLobby(keys, records ?? []);
|
|
24363
|
-
|
|
24364
|
-
|
|
24365
|
-
return
|
|
24489
|
+
if (entries.some((e) => e.key === live.session.myKey && e.ts >= ts)) return false;
|
|
24490
|
+
traceJoin(groupId, "lobby.lost");
|
|
24491
|
+
return entries.length < COMMUNITY_TOPOLOGY.lobbyEntries ? "room" : "full";
|
|
24366
24492
|
}
|
|
24367
24493
|
async pollLobby(groupId, live, now) {
|
|
24368
24494
|
const keys = lobbyKeys(live.session.state.rv, groupId, live.session.myKey);
|
|
24369
24495
|
const back = this.wayBack(groupId, live);
|
|
24370
24496
|
const entries = readLobby(keys, await this.host.resolve(keys.identity.pubKeyZ32, !back, !back && this.doorBusy(groupId, live, now), back).catch(() => null) ?? []);
|
|
24497
|
+
const held = this.host.readHeldBackFor?.(keys.identity.pubKeyZ32);
|
|
24498
|
+
live.lobbyHeldUntil = held !== void 0 && held > 0 ? now + held : void 0;
|
|
24371
24499
|
for (const { key, ts } of entries) {
|
|
24372
24500
|
if (now - ts > COMMUNITY_TOPOLOGY.lobbyFreshMs || key === live.session.myKey) continue;
|
|
24373
24501
|
if (live.session.wasRemoved(key)) {
|
|
@@ -24817,6 +24945,7 @@ var Communities = class {
|
|
|
24817
24945
|
this.knocked.delete(g);
|
|
24818
24946
|
this.knockAt.delete(g);
|
|
24819
24947
|
this.knockingWith.delete(g);
|
|
24948
|
+
this.knockingSince.delete(g);
|
|
24820
24949
|
this.knockRead.delete(g);
|
|
24821
24950
|
await this.host.closeEdge(linkId);
|
|
24822
24951
|
await this.reconcile(g, live, now);
|
|
@@ -24930,7 +25059,7 @@ var Communities = class {
|
|
|
24930
25059
|
message: async (m) => {
|
|
24931
25060
|
const timestamp = m.timestamp;
|
|
24932
25061
|
const mentioned = m.sender !== session.myKey && mentionsMember(m.mentions, session.myKey);
|
|
24933
|
-
const file = m.file && this.files ? await this.files.announced(id, {
|
|
25062
|
+
const file = m.file && this.files && !this.stored.get(id)?.removedIds?.includes(m.id) ? await this.files.announced(id, {
|
|
24934
25063
|
id: m.id,
|
|
24935
25064
|
sender: m.sender,
|
|
24936
25065
|
ts: m.timestamp,
|
|
@@ -24956,10 +25085,9 @@ var Communities = class {
|
|
|
24956
25085
|
...file && { file }
|
|
24957
25086
|
});
|
|
24958
25087
|
placing(stored !== false);
|
|
25088
|
+
if (stored === false && this.stored.get(id)?.removedIds?.includes(m.id)) return;
|
|
24959
25089
|
const came = m.sender === session.myKey ? timestamp : cameAt(timestamp, stored, arrivalNow(this.now()));
|
|
24960
|
-
this.
|
|
24961
|
-
if (mentioned) this.lastMentionAt.set(id, Math.max(this.lastMentionAt.get(id) ?? 0, came));
|
|
24962
|
-
if (m.sender !== session.myKey) this.lastPeerMessageAt.set(id, Math.max(this.lastPeerMessageAt.get(id) ?? 0, came));
|
|
25090
|
+
markCame(this.marks, id, m.id, came, m.sender !== session.myKey, mentioned);
|
|
24963
25091
|
noteCame(this.stored.get(id), came, m.sender !== session.myKey, mentioned);
|
|
24964
25092
|
},
|
|
24965
25093
|
app: (m) => this.deliver(id, () => m.frame.t === "group-have" ? this.files?.communityApp(id, m.sender, m.frame) : this.host.communityApp?.(id, m.sender, m.frame)),
|
|
@@ -24980,6 +25108,7 @@ var Communities = class {
|
|
|
24980
25108
|
seqFloor: () => this.host.seqFloor?.() ?? 0,
|
|
24981
25109
|
adminWork: () => this.host.adminWork?.(id) ?? true,
|
|
24982
25110
|
adminTurn: () => this.host.adminTurn?.(id) ?? Promise.resolve(true),
|
|
25111
|
+
removed: (messageId) => !!this.stored.get(id)?.removedIds?.includes(messageId),
|
|
24983
25112
|
relay: (frame) => {
|
|
24984
25113
|
if (this.live.get(id)?.hub) for (const [, linkId] of this.hearers(id, frame)) this.sendTo(linkId, frame);
|
|
24985
25114
|
},
|
|
@@ -25118,6 +25247,19 @@ var GONE_LINGER_MS = 15e3;
|
|
|
25118
25247
|
*/
|
|
25119
25248
|
var HUB_CLOCK_READ_GAP_MS = 75e3;
|
|
25120
25249
|
/**
|
|
25250
|
+
* A member steps up as a hub only while the beacon lists fewer fresh hubs than `maxHubs` less this. At `maxHubs` less
|
|
25251
|
+
* one, one entry crossing its freshness (a hub whose write the budget held a while) brought a member back up, which
|
|
25252
|
+
* pushed another out, and so on: 14-20 hubs of 20 members for minutes (agents#1691).
|
|
25253
|
+
*/
|
|
25254
|
+
var STEP_UP_MARGIN = 2;
|
|
25255
|
+
/**
|
|
25256
|
+
* Too few hubs: a member steps up after a delay of its own, under this (the same for its key and epoch), and only on a
|
|
25257
|
+
* reading made after it. Every member read the same short beacon in the same minute and stepped up together.
|
|
25258
|
+
*/
|
|
25259
|
+
var STEP_UP_DELAY_MS = 6e4;
|
|
25260
|
+
/** The longest a write of my entry waits for the budget it was told of: within an entry's freshness (90 s). */
|
|
25261
|
+
var PUBLISH_WAIT_MAX_MS = 3e4;
|
|
25262
|
+
/**
|
|
25121
25263
|
* The hubs of the private groups this device is in (WISP 902 · Group Mesh § Hubs): whether a group runs on hubs, who
|
|
25122
25264
|
* they are (the community's sealed beacon and lobbies, under the epoch's rendezvous secret), whether I am one, which
|
|
25123
25265
|
* edges that asks for, and passing frames on as a hub. `Groups` owns the sessions and the edges; this decides.
|
|
@@ -25163,6 +25305,9 @@ var MeshHubs = class {
|
|
|
25163
25305
|
lastRead: 0,
|
|
25164
25306
|
lastWrite: 0,
|
|
25165
25307
|
lastTry: 0,
|
|
25308
|
+
publishAfter: 0,
|
|
25309
|
+
readAt: 0,
|
|
25310
|
+
stepUpAt: 0,
|
|
25166
25311
|
hub: false,
|
|
25167
25312
|
hubSince: 0,
|
|
25168
25313
|
members: /* @__PURE__ */ new Map(),
|
|
@@ -25361,6 +25506,9 @@ var MeshHubs = class {
|
|
|
25361
25506
|
live.lastTry = 0;
|
|
25362
25507
|
live.beacon = [];
|
|
25363
25508
|
live.epochRead = false;
|
|
25509
|
+
live.publishAfter = 0;
|
|
25510
|
+
live.stepUpAt = 0;
|
|
25511
|
+
live.readAt = 0;
|
|
25364
25512
|
live.clocks.restart();
|
|
25365
25513
|
}
|
|
25366
25514
|
const policy = session.hubPolicy, me = session.myKey, inRoster = (key) => rosterHas(session.roster, key);
|
|
@@ -25370,7 +25518,11 @@ var MeshHubs = class {
|
|
|
25370
25518
|
const others = this.listed(live, session, now);
|
|
25371
25519
|
const fits = this.fits(groupId, session);
|
|
25372
25520
|
if (live.hub) live.need = session.others.length;
|
|
25373
|
-
|
|
25521
|
+
const counted = this.counted(live, session, now), short = live.epochRead && counted < MESH_HUBS.maxHubs - STEP_UP_MARGIN;
|
|
25522
|
+
const needed = counted < MESH_HUBS.hubsPerMember;
|
|
25523
|
+
if (!short || live.hub) live.stepUpAt = 0;
|
|
25524
|
+
else if (!live.stepUpAt) live.stepUpAt = needed ? now : now + stepUpDelay(me, session.epoch);
|
|
25525
|
+
if (!live.hub && may && fits && (policy.pin.includes(me) || short && now >= live.stepUpAt && (needed || live.readAt >= live.stepUpAt))) {
|
|
25374
25526
|
live.hub = true;
|
|
25375
25527
|
live.hubSince = now;
|
|
25376
25528
|
live.myHubs = [];
|
|
@@ -25380,7 +25532,7 @@ var MeshHubs = class {
|
|
|
25380
25532
|
live.hub = false;
|
|
25381
25533
|
live.members.clear();
|
|
25382
25534
|
if (!may || !fits) await this.publish(groupId, session, live, now, false).catch(() => {});
|
|
25383
|
-
} else if (live.hub && now - live.lastTry >= 5e3 && (now - live.lastWrite >= this.timings.beaconEveryMs || !live.beacon.some((h) => h.key === me))) await this.publish(groupId, session, live, now, true).catch(() => {});
|
|
25535
|
+
} else if (live.hub && now - live.lastTry >= 5e3 && now >= live.publishAfter && (now - live.lastWrite >= this.timings.beaconEveryMs || !live.beacon.some((h) => h.key === me))) await this.publish(groupId, session, live, now, true).catch(() => {});
|
|
25384
25536
|
if (live.hub) {
|
|
25385
25537
|
await this.serve(groupId, session, live, now, rv);
|
|
25386
25538
|
const hubs = others.map((h) => h.key).sort();
|
|
@@ -25397,7 +25549,18 @@ var MeshHubs = class {
|
|
|
25397
25549
|
* pinned hub lists itself whatever the beacon holds.
|
|
25398
25550
|
*/
|
|
25399
25551
|
full(live, session, now) {
|
|
25400
|
-
return live.epochRead && !session.hubPolicy.pin.includes(session.myKey) && !live.beacon.some((h) => h.key === session.myKey) && this.
|
|
25552
|
+
return live.epochRead && !session.hubPolicy.pin.includes(session.myKey) && !live.beacon.some((h) => h.key === session.myKey) && this.counted(live, session, now) >= MESH_HUBS.maxHubs;
|
|
25553
|
+
}
|
|
25554
|
+
/**
|
|
25555
|
+
* The other hubs there are, as far as stepping up or down goes: the beacon's fresh ones and those a reading showed
|
|
25556
|
+
* fresh within `graceMs`. A hub whose republish the relays' budget held back past the entry's 90 s is still a hub:
|
|
25557
|
+
* counted on fresh entries alone, every such entry brought a member up, and none ever saw enough to step down
|
|
25558
|
+
* (agents#1691: 14-20 hubs of 20 members, beacon writes refused 290 times of 339).
|
|
25559
|
+
*/
|
|
25560
|
+
counted(live, session, now) {
|
|
25561
|
+
const keys = new Set(this.listed(live, session, now).map((h) => h.key));
|
|
25562
|
+
for (const [key, at] of live.seenHubs) if (now - at <= this.timings.graceMs && key !== session.myKey && rosterHas(session.roster, key) && !live.departed.has(key)) keys.add(key);
|
|
25563
|
+
return keys.size;
|
|
25401
25564
|
}
|
|
25402
25565
|
shape(live) {
|
|
25403
25566
|
return `${live.hub}|${live.myHubs.join(",")}|${[...live.members.keys()].sort().join(",")}|${live.beacon.map((h) => h.key).sort().join(",")}`;
|
|
@@ -25411,11 +25574,18 @@ var MeshHubs = class {
|
|
|
25411
25574
|
} catch {
|
|
25412
25575
|
return;
|
|
25413
25576
|
}
|
|
25577
|
+
if (this.held(keys.identity.pubKeyZ32)) return;
|
|
25414
25578
|
live.beacon = live.clocks.inMyTime(readBeacon(keys, records ?? []), now);
|
|
25415
25579
|
live.firstRead = true;
|
|
25416
25580
|
live.epochRead = true;
|
|
25581
|
+
live.readAt = now;
|
|
25417
25582
|
this.noteHubs(live, session, now);
|
|
25418
25583
|
}
|
|
25584
|
+
/** How long the relays' budget holds the read of this key back: the read that just ended answered no relay's packet. */
|
|
25585
|
+
held(pubKeyZ32) {
|
|
25586
|
+
const wait = this.host.readHeldBackFor?.(pubKeyZ32);
|
|
25587
|
+
return wait !== void 0 && wait > 0 ? wait : void 0;
|
|
25588
|
+
}
|
|
25419
25589
|
noteHubs(live, session, now) {
|
|
25420
25590
|
for (const h of this.listed(live, session, now)) live.seenHubs.set(h.key, now);
|
|
25421
25591
|
for (const [key, at] of live.seenHubs) if (now - at > this.timings.graceMs || !rosterHas(session.roster, key)) live.seenHubs.delete(key);
|
|
@@ -25432,10 +25602,17 @@ var MeshHubs = class {
|
|
|
25432
25602
|
let records;
|
|
25433
25603
|
try {
|
|
25434
25604
|
records = await this.host.resolve(keys.identity.pubKeyZ32, true);
|
|
25435
|
-
} catch {
|
|
25605
|
+
} catch (error) {
|
|
25606
|
+
this.holdPublish(live, now, error);
|
|
25607
|
+
return;
|
|
25608
|
+
}
|
|
25609
|
+
const wait = this.held(keys.identity.pubKeyZ32);
|
|
25610
|
+
if (wait !== void 0) {
|
|
25611
|
+
live.publishAfter = now + wait;
|
|
25436
25612
|
return;
|
|
25437
25613
|
}
|
|
25438
25614
|
existing = live.clocks.inMyTime(readBeacon(keys, records ?? []), now);
|
|
25615
|
+
live.readAt = now;
|
|
25439
25616
|
if (listed) {
|
|
25440
25617
|
live.beacon = existing;
|
|
25441
25618
|
live.lastRead = now;
|
|
@@ -25452,14 +25629,27 @@ var MeshHubs = class {
|
|
|
25452
25629
|
load: live.members.size,
|
|
25453
25630
|
since: live.hubSince || now
|
|
25454
25631
|
} : null, now, (key) => rosterHas(session.roster, key) && !policy.no.includes(key));
|
|
25455
|
-
|
|
25632
|
+
try {
|
|
25633
|
+
await this.host.publish(keys.identity, beaconRecords(keys, live.clocks.asWritten(hubs)), true);
|
|
25634
|
+
} catch (error) {
|
|
25635
|
+
this.holdPublish(live, now, error);
|
|
25636
|
+
throw error;
|
|
25637
|
+
}
|
|
25456
25638
|
live.beacon = hubs;
|
|
25457
25639
|
live.lastWrite = now;
|
|
25458
25640
|
live.lastRead = now;
|
|
25641
|
+
live.readAt = now;
|
|
25459
25642
|
live.firstRead = true;
|
|
25460
25643
|
live.epochRead = true;
|
|
25461
25644
|
this.noteHubs(live, session, now);
|
|
25462
25645
|
}
|
|
25646
|
+
/**
|
|
25647
|
+
* A write of my entry (or the read before it) the relays' budget held back: not tried again every 5 s (each try a
|
|
25648
|
+
* read, held 290 times of 339 on 20 apps: agents#1691), but once the budget says it frees a request.
|
|
25649
|
+
*/
|
|
25650
|
+
holdPublish(live, now, error) {
|
|
25651
|
+
if (isDiscoveryBudgetError(error)) live.publishAfter = now + Math.min(Math.max(error.retryInMs, 5e3), PUBLISH_WAIT_MAX_MS);
|
|
25652
|
+
}
|
|
25463
25653
|
/** As a hub: who asked in my lobby, and which of my members are still around. */
|
|
25464
25654
|
async serve(groupId, session, live, now, rv) {
|
|
25465
25655
|
const edges = this.host.edges(groupId);
|
|
@@ -25694,6 +25884,12 @@ function authorOf(frame) {
|
|
|
25694
25884
|
default: return;
|
|
25695
25885
|
}
|
|
25696
25886
|
}
|
|
25887
|
+
/** A member's own delay before it steps up (`STEP_UP_DELAY_MS`): from its key and the epoch, so members spread out. */
|
|
25888
|
+
function stepUpDelay(key, epoch) {
|
|
25889
|
+
let hash = epoch | 0;
|
|
25890
|
+
for (let i = 0; i < key.length; i++) hash = Math.imul(hash, 31) + key.charCodeAt(i) | 0;
|
|
25891
|
+
return (hash >>> 0) % STEP_UP_DELAY_MS;
|
|
25892
|
+
}
|
|
25697
25893
|
//#endregion
|
|
25698
25894
|
//#region ../browser/src/engine/groupTyping.ts
|
|
25699
25895
|
/**
|
|
@@ -26074,11 +26270,111 @@ function noteCame(group, came, peer, mentioned) {
|
|
|
26074
26270
|
}
|
|
26075
26271
|
/** What `load` starts the unread marks from: the history's own times, or when its latest came if that was later. */
|
|
26076
26272
|
var cameOrWritten = (written, came) => written === void 0 && came === void 0 ? void 0 : Math.max(written ?? 0, came ?? 0);
|
|
26273
|
+
/** Every key that was a member of the group at some epoch of its chain. */
|
|
26274
|
+
function everMembers(session) {
|
|
26275
|
+
const keys = /* @__PURE__ */ new Set();
|
|
26276
|
+
for (const commit of session.state.chain) if (commit) for (const [key] of commit.m) keys.add(key);
|
|
26277
|
+
return keys;
|
|
26278
|
+
}
|
|
26077
26279
|
/** The view's `lastPeerMessageAt`, when there is one. */
|
|
26078
26280
|
var peerMessageAt = (map, groupId) => {
|
|
26079
26281
|
const at = map.get(groupId);
|
|
26080
26282
|
return at ? { lastPeerMessageAt: at } : {};
|
|
26081
26283
|
};
|
|
26284
|
+
/**
|
|
26285
|
+
* A message came at `came`: the marks move to it (never back), and it is noted as the one that moved them (`unmark`
|
|
26286
|
+
* reads the history again only for one of those).
|
|
26287
|
+
*/
|
|
26288
|
+
function markCame(marks, groupId, id, came, peer, mentioned) {
|
|
26289
|
+
const by = { ...marks.by.get(groupId) };
|
|
26290
|
+
const move = (map) => {
|
|
26291
|
+
if (came < (map.get(groupId) ?? 0)) return false;
|
|
26292
|
+
map.set(groupId, came);
|
|
26293
|
+
return true;
|
|
26294
|
+
};
|
|
26295
|
+
if (move(marks.lastMessageAt)) by.last = id;
|
|
26296
|
+
if (mentioned && move(marks.lastMentionAt)) by.mention = id;
|
|
26297
|
+
if (peer && move(marks.lastPeerMessageAt)) by.peer = id;
|
|
26298
|
+
marks.by.set(groupId, by);
|
|
26299
|
+
}
|
|
26300
|
+
/** What `load` reads a group's marks from: the newest rows (`newestMarked`), and when its latest came if later (`came`). */
|
|
26301
|
+
function loadMarks(marks, group, history) {
|
|
26302
|
+
const { last, peer, mention } = newestMarked(history);
|
|
26303
|
+
if (last) marks.lastMessageAt.set(group.id, last.timestamp);
|
|
26304
|
+
const peerAt = cameOrWritten(peer?.timestamp, peer ? group.came?.peer : void 0);
|
|
26305
|
+
if (peerAt) marks.lastPeerMessageAt.set(group.id, peerAt);
|
|
26306
|
+
const mentionAt = cameOrWritten(mention?.timestamp, mention ? group.came?.mention : void 0);
|
|
26307
|
+
if (mentionAt) marks.lastMentionAt.set(group.id, mentionAt);
|
|
26308
|
+
marks.by.set(group.id, {
|
|
26309
|
+
last: last?.id,
|
|
26310
|
+
peer: peer?.id,
|
|
26311
|
+
mention: mention?.id
|
|
26312
|
+
});
|
|
26313
|
+
}
|
|
26314
|
+
/** A group gone from this engine: its marks too. */
|
|
26315
|
+
function dropMarks(marks, groupId) {
|
|
26316
|
+
marks.lastMessageAt.delete(groupId);
|
|
26317
|
+
marks.lastPeerMessageAt.delete(groupId);
|
|
26318
|
+
marks.lastMentionAt.delete(groupId);
|
|
26319
|
+
marks.by.delete(groupId);
|
|
26320
|
+
}
|
|
26321
|
+
/** The newest rows `load` reads the marks from: a group's last message, last of a member's, last mentioning me. */
|
|
26322
|
+
function newestMarked(history) {
|
|
26323
|
+
const said = history.filter((m) => !m.event && !m.groupPay);
|
|
26324
|
+
return {
|
|
26325
|
+
last: said[said.length - 1],
|
|
26326
|
+
peer: [...said].reverse().find((m) => m.sender !== "me"),
|
|
26327
|
+
mention: [...history].reverse().find((m) => m.mentioned)
|
|
26328
|
+
};
|
|
26329
|
+
}
|
|
26330
|
+
/**
|
|
26331
|
+
* A message deleted for everyone (WISP 400 § Delete for everyone: a tombstone does not count as unread or move the
|
|
26332
|
+
* chat): the marks it moved go back to the newest line still kept, as `load` reads them, and the record's `came` it
|
|
26333
|
+
* raised goes too. A mark a newer line moved stays, and the history is read only when the message moved one
|
|
26334
|
+
* (`markedBy`): removals go at the pace of edits. `history`: the group's rows, with it gone. True when `came` changed
|
|
26335
|
+
* (the record is to be saved).
|
|
26336
|
+
*/
|
|
26337
|
+
async function unmark(marks, group, groupId, history, removed) {
|
|
26338
|
+
const by = marks.by.get(groupId);
|
|
26339
|
+
if (!by || ![
|
|
26340
|
+
by.last,
|
|
26341
|
+
by.peer,
|
|
26342
|
+
by.mention
|
|
26343
|
+
].includes(removed.id)) return false;
|
|
26344
|
+
const newest = newestMarked((await history()).filter((m) => m.id !== removed.id));
|
|
26345
|
+
const back = (map, row) => {
|
|
26346
|
+
if (row) map.set(groupId, row.timestamp);
|
|
26347
|
+
else map.delete(groupId);
|
|
26348
|
+
};
|
|
26349
|
+
let came = false;
|
|
26350
|
+
if (by.last === removed.id) back(marks.lastMessageAt, newest.last);
|
|
26351
|
+
if (by.peer === removed.id) {
|
|
26352
|
+
back(marks.lastPeerMessageAt, newest.peer);
|
|
26353
|
+
if (group?.came?.peer !== void 0) {
|
|
26354
|
+
group.came = {
|
|
26355
|
+
...group.came,
|
|
26356
|
+
peer: void 0
|
|
26357
|
+
};
|
|
26358
|
+
came = true;
|
|
26359
|
+
}
|
|
26360
|
+
}
|
|
26361
|
+
if (by.mention === removed.id) {
|
|
26362
|
+
back(marks.lastMentionAt, newest.mention);
|
|
26363
|
+
if (group?.came?.mention !== void 0) {
|
|
26364
|
+
group.came = {
|
|
26365
|
+
...group.came,
|
|
26366
|
+
mention: void 0
|
|
26367
|
+
};
|
|
26368
|
+
came = true;
|
|
26369
|
+
}
|
|
26370
|
+
}
|
|
26371
|
+
marks.by.set(groupId, {
|
|
26372
|
+
last: by.last === removed.id ? newest.last?.id : by.last,
|
|
26373
|
+
peer: by.peer === removed.id ? newest.peer?.id : by.peer,
|
|
26374
|
+
mention: by.mention === removed.id ? newest.mention?.id : by.mention
|
|
26375
|
+
});
|
|
26376
|
+
return came;
|
|
26377
|
+
}
|
|
26082
26378
|
var ENTRY_TIMINGS = {
|
|
26083
26379
|
pollMs: 5e3,
|
|
26084
26380
|
warmPollMs: 2e3,
|
|
@@ -26087,6 +26383,32 @@ var ENTRY_TIMINGS = {
|
|
|
26087
26383
|
slowKnockMs: 2e4,
|
|
26088
26384
|
patienceMs: 12e4
|
|
26089
26385
|
};
|
|
26386
|
+
/**
|
|
26387
|
+
* A link join nobody answers (the link replaced or turned off, the group deleted, its admin's app gone) knocks less
|
|
26388
|
+
* often the longer it waits, once past `patienceMs`: a fifth of the wait between knocks, up to this, but no longer than
|
|
26389
|
+
* the joins waiting need (`JOIN_KNOCKS_PER_MINUTE`), and never sooner than `slowKnockMs`. Under `KNOCK_TTL_MS`, so an
|
|
26390
|
+
* admin's app that comes back still finds the knock fresh. Every `slowKnockMs` for good, four such links took 27 of the
|
|
26391
|
+
* app's 30 relay requests a minute, 20 minutes on (bug hunt 1019-0904, 2026-10-20).
|
|
26392
|
+
*/
|
|
26393
|
+
var JOIN_KNOCK_WAIT_MAX_MS = 15e4;
|
|
26394
|
+
/** A join counted as waiting (`countWaitingJoin`) and not counted again this long is gone (joined, given up, forgotten). */
|
|
26395
|
+
var WAITING_JOIN_SEEN_MS = 1e4;
|
|
26396
|
+
var waitingJoins = /* @__PURE__ */ new WeakMap();
|
|
26397
|
+
/** Counts the link join of `groupId` among the waiting ones of `host`'s app while `waiting`, or no longer: how many there are. */
|
|
26398
|
+
function countWaitingJoin(host, groupId, now, waiting) {
|
|
26399
|
+
let joins = waitingJoins.get(host);
|
|
26400
|
+
if (!joins) waitingJoins.set(host, joins = /* @__PURE__ */ new Map());
|
|
26401
|
+
if (waiting) joins.set(groupId, now);
|
|
26402
|
+
else joins.delete(groupId);
|
|
26403
|
+
for (const [id, at] of joins) if (now - at > WAITING_JOIN_SEEN_MS) joins.delete(id);
|
|
26404
|
+
return joins.size;
|
|
26405
|
+
}
|
|
26406
|
+
/** The wait between a joiner's knocks, `waited` after it opened the link, one of `joins` waiting (`JOIN_KNOCK_WAIT_MAX_MS`). */
|
|
26407
|
+
function joinKnockWait(waited, timings, joins) {
|
|
26408
|
+
if (waited <= timings.patienceMs) return timings.knockMs;
|
|
26409
|
+
const share = Math.round(joins * 6e4 / 2);
|
|
26410
|
+
return Math.max(timings.slowKnockMs, Math.min(JOIN_KNOCK_WAIT_MAX_MS, Math.round(waited / 5), share));
|
|
26411
|
+
}
|
|
26090
26412
|
var KNOCK_VERIFY_SPREAD_MS = 700;
|
|
26091
26413
|
/** Entry sessions the admin runs at once; a joiner who does not finish in time is not answered again for a while. */
|
|
26092
26414
|
var MAX_PENDING_ENTRIES = 4;
|
|
@@ -26141,17 +26463,6 @@ function invitationClaims(frame) {
|
|
|
26141
26463
|
var FAREWELL_ANSWERS = 3;
|
|
26142
26464
|
/** Commits sent to a removed member that was behind when it left, at most. */
|
|
26143
26465
|
var FAREWELL_COMMITS = 64;
|
|
26144
|
-
/**
|
|
26145
|
-
* A member whose messages were just asked of another (`Groups.askOf`) is told where I am only once that one's answer
|
|
26146
|
-
* has come: no message of it for this long, or `MESH_SYNC_HOLD_MAX_MS` after it was asked. Told at once, its own
|
|
26147
|
-
* answer raced the other's, which holds the same messages among everyone's in the order they were written, and a
|
|
26148
|
-
* member back in a group of five read each member's lines apart, the newest above older ones (WISP 902 § Catch-up).
|
|
26149
|
-
* A message of the answer is one written before the asking: what the member writes meanwhile is no reason to wait, so
|
|
26150
|
-
* the longest wait only has to cover a whole answer (the 256 messages a member keeps for the others and its own last
|
|
26151
|
-
* 32) at the pace of a phone with a long history, 600 ms a frame. At ten seconds, an answer of 200 messages at four a
|
|
26152
|
-
* second was cut at the 40th, and the others' newest lines landed above what was still coming.
|
|
26153
|
-
*/
|
|
26154
|
-
var MESH_SYNC_HOLD_MS = 1500;
|
|
26155
26466
|
/** Where a member's gossip turns start among the members it is connected to: a number of its own, from its key. */
|
|
26156
26467
|
var gossipStart = (key) => {
|
|
26157
26468
|
let n = 0;
|
|
@@ -26223,6 +26534,13 @@ var Groups = class {
|
|
|
26223
26534
|
lastPeerMessageAt = /* @__PURE__ */ new Map();
|
|
26224
26535
|
/** The latest message that names me, per group (the chat list's "@" while it is unread). */
|
|
26225
26536
|
lastMentionAt = /* @__PURE__ */ new Map();
|
|
26537
|
+
/** The maps above, and what moved them last (`markCame`, `unmark`). */
|
|
26538
|
+
marks = {
|
|
26539
|
+
lastMessageAt: this.lastMessageAt,
|
|
26540
|
+
lastPeerMessageAt: this.lastPeerMessageAt,
|
|
26541
|
+
lastMentionAt: this.lastMentionAt,
|
|
26542
|
+
by: /* @__PURE__ */ new Map()
|
|
26543
|
+
};
|
|
26226
26544
|
reconciling = Promise.resolve();
|
|
26227
26545
|
/** Admin side: joiners with an entry session open, per group: member key → since when. */
|
|
26228
26546
|
pendingEntries = /* @__PURE__ */ new Map();
|
|
@@ -26239,6 +26557,9 @@ var Groups = class {
|
|
|
26239
26557
|
/** Joiner side: when a knock just written is read back (`KNOCK_VERIFY_MS`); none once it was found there. */
|
|
26240
26558
|
knockCheckAt = /* @__PURE__ */ new Map();
|
|
26241
26559
|
/** Joiner side: knocks written in a row without one found in the record since (`KNOCK_VERIFIES`). */
|
|
26560
|
+
/** Joiner side: since when this run knocks with nobody answering (`JOIN_GIVE_UP_MS`), and the joins it gave up. */
|
|
26561
|
+
knockingSince = /* @__PURE__ */ new Map();
|
|
26562
|
+
gaveUp = /* @__PURE__ */ new Set();
|
|
26242
26563
|
knockRewrites = /* @__PURE__ */ new Map();
|
|
26243
26564
|
/** Per group, members met over their admission a moment ago: their edge is opened expecting them. */
|
|
26244
26565
|
justMet = /* @__PURE__ */ new Map();
|
|
@@ -26381,7 +26702,7 @@ var Groups = class {
|
|
|
26381
26702
|
await this.communities.load(all.filter((g) => g.community || g.joining));
|
|
26382
26703
|
for (const group of all.filter((g) => !g.community && !g.joining)) {
|
|
26383
26704
|
this.stored.set(group.id, group);
|
|
26384
|
-
const history = await this.store.getMessages(MESSAGE_LINK(group.id))
|
|
26705
|
+
const history = await this.store.getMessages(MESSAGE_LINK(group.id));
|
|
26385
26706
|
const framed = history.filter((m) => m.frame);
|
|
26386
26707
|
this.framesKept.set(group.id, framed.map((m) => ({
|
|
26387
26708
|
id: m.id,
|
|
@@ -26389,13 +26710,8 @@ var Groups = class {
|
|
|
26389
26710
|
})));
|
|
26390
26711
|
if (group.state) this.attach(group.state, framed.map((m) => m.frame));
|
|
26391
26712
|
if (group.invited) this.invited.set(group.id, new Set(Object.keys(group.invited)));
|
|
26392
|
-
|
|
26393
|
-
|
|
26394
|
-
const peerAt = cameOrWritten(lastPeer?.timestamp, lastPeer ? group.came?.peer : void 0);
|
|
26395
|
-
if (peerAt) this.lastPeerMessageAt.set(group.id, peerAt);
|
|
26396
|
-
const mention = [...history].reverse().find((m) => m.mentioned);
|
|
26397
|
-
const mentionAt = cameOrWritten(mention?.timestamp, mention ? group.came?.mention : void 0);
|
|
26398
|
-
if (mentionAt) this.lastMentionAt.set(group.id, mentionAt);
|
|
26713
|
+
loadMarks(this.marks, group, history);
|
|
26714
|
+
this.host.loaded?.(group.id, history);
|
|
26399
26715
|
}
|
|
26400
26716
|
for (const id of this.sessions.keys()) this.reconcileEdges(id);
|
|
26401
26717
|
await this.files?.load(all.map((g) => g.id));
|
|
@@ -26437,7 +26753,12 @@ var Groups = class {
|
|
|
26437
26753
|
return view && this.pinned(view);
|
|
26438
26754
|
}
|
|
26439
26755
|
pinned(view) {
|
|
26440
|
-
const
|
|
26756
|
+
const record = this.record(view.id), kept = record?.pin;
|
|
26757
|
+
const pin = pinView(!!kept?.id && !!record?.removedIds?.some((id) => id === kept.id || id === kept.messageId) ? {
|
|
26758
|
+
...kept,
|
|
26759
|
+
id: "",
|
|
26760
|
+
messageId: void 0
|
|
26761
|
+
} : kept);
|
|
26441
26762
|
return pin ? {
|
|
26442
26763
|
...view,
|
|
26443
26764
|
pin
|
|
@@ -26480,7 +26801,8 @@ var Groups = class {
|
|
|
26480
26801
|
...invitation.takenBack ? { takenBack: true } : {},
|
|
26481
26802
|
...invitation.entry ? {
|
|
26482
26803
|
viaLink: true,
|
|
26483
|
-
stage: this.joinStage(group)
|
|
26804
|
+
stage: this.joinStage(group),
|
|
26805
|
+
...this.gaveUp.has(group.id) && { unanswered: true }
|
|
26484
26806
|
} : {}
|
|
26485
26807
|
}
|
|
26486
26808
|
};
|
|
@@ -26658,8 +26980,10 @@ var Groups = class {
|
|
|
26658
26980
|
this.host.emit();
|
|
26659
26981
|
}
|
|
26660
26982
|
async accept(groupId) {
|
|
26983
|
+
if (this.isCommunity(groupId)) return this.communities.knockAgain(groupId);
|
|
26661
26984
|
const group = this.stored.get(groupId);
|
|
26662
26985
|
if (!group?.invitation) throw new Error("No invitation to accept");
|
|
26986
|
+
if (group.invitation.entry && !group.state) return this.knockAgain(group);
|
|
26663
26987
|
if (group.invitation.takenBack) throw new Error("This invitation was taken back");
|
|
26664
26988
|
if (!this.host.linkReady(group.invitation.linkId)) throw new Error("The contact who invited you is not connected. Try again when they are.");
|
|
26665
26989
|
const seedB64 = group.invitation.seedB64 ?? createIdentity().seedB64;
|
|
@@ -26913,9 +27237,7 @@ var Groups = class {
|
|
|
26913
27237
|
this.pendingEntries.delete(groupId);
|
|
26914
27238
|
this.welcomed.delete(groupId);
|
|
26915
27239
|
this.lingering.delete(groupId);
|
|
26916
|
-
this.
|
|
26917
|
-
this.lastPeerMessageAt.delete(groupId);
|
|
26918
|
-
this.lastMentionAt.delete(groupId);
|
|
27240
|
+
dropMarks(this.marks, groupId);
|
|
26919
27241
|
this.authorOrder.forget(groupId);
|
|
26920
27242
|
this.lineOrder.forget(MESSAGE_LINK(groupId));
|
|
26921
27243
|
await this.store.deleteGroup(groupId);
|
|
@@ -27054,8 +27376,23 @@ var Groups = class {
|
|
|
27054
27376
|
group.removedIds = [...group.removedIds ?? [], messageId].slice(-500);
|
|
27055
27377
|
await this.store.putGroup(group);
|
|
27056
27378
|
}
|
|
27379
|
+
this.communities.session(groupId)?.forget(messageId);
|
|
27057
27380
|
await this.files?.forget(groupId, messageId);
|
|
27058
27381
|
}
|
|
27382
|
+
/**
|
|
27383
|
+
* A message deleted for everyone left this device (`removed`, the row as it was): the group's unread, "@" and place
|
|
27384
|
+
* in the list go back to what they were without it (`unmark`), after a restart too.
|
|
27385
|
+
*/
|
|
27386
|
+
/** Whether this message moved one of the group's marks last (`unmark` has something to do for it). */
|
|
27387
|
+
movedMarks(groupId, messageId) {
|
|
27388
|
+
const by = (this.isCommunity(groupId) ? this.communities.markedBy(groupId) : this.marks.by.get(groupId)) ?? {};
|
|
27389
|
+
return by.last === messageId || by.peer === messageId || by.mention === messageId;
|
|
27390
|
+
}
|
|
27391
|
+
async unmark(groupId, removed) {
|
|
27392
|
+
if (this.isCommunity(groupId)) return this.communities.unmark(groupId, removed);
|
|
27393
|
+
const group = this.stored.get(groupId);
|
|
27394
|
+
if (await unmark(this.marks, group, groupId, () => this.store.getMessages(MESSAGE_LINK(groupId)), removed) && group) await this.store.putGroup(group);
|
|
27395
|
+
}
|
|
27059
27396
|
/** The connection of an edge opened. One kept to tell a removed member closes a while after, whatever its app says or does not say. */
|
|
27060
27397
|
edgeOpen(groupId, peerKey) {
|
|
27061
27398
|
const group = this.stored.get(groupId), farewell = group?.farewells?.[peerKey];
|
|
@@ -27160,6 +27497,8 @@ var Groups = class {
|
|
|
27160
27497
|
this.knocked.delete(groupId);
|
|
27161
27498
|
this.knockCheckAt.delete(groupId);
|
|
27162
27499
|
this.knockRewrites.delete(groupId);
|
|
27500
|
+
this.knockingSince.delete(groupId);
|
|
27501
|
+
this.gaveUp.delete(groupId);
|
|
27163
27502
|
this.justMet.delete(groupId);
|
|
27164
27503
|
this.welcomed.delete(groupId);
|
|
27165
27504
|
this.lingering.delete(groupId);
|
|
@@ -27247,7 +27586,11 @@ var Groups = class {
|
|
|
27247
27586
|
if (!link) throw new Error("This is not a link to a group");
|
|
27248
27587
|
if (this.isCommunity(link.g)) throw new Error("This group is joined with its current link");
|
|
27249
27588
|
const existing = this.stored.get(link.g);
|
|
27250
|
-
if (existing?.state?.status === "active"
|
|
27589
|
+
if (existing?.state?.status === "active") return link.g;
|
|
27590
|
+
if (existing?.invitation?.entry === link.host) {
|
|
27591
|
+
if (!existing.state) await this.knockAgain(existing);
|
|
27592
|
+
return link.g;
|
|
27593
|
+
}
|
|
27251
27594
|
if (existing?.invitation?.seedB64 && !existing.invitation.entry) throw new Error("You are already joining this group");
|
|
27252
27595
|
if (existing?.invitation && !existing.invitation.entry) throw new Error("You have an invitation to this group. Answer it first.");
|
|
27253
27596
|
if (existing?.state && !existing.left) throw new Error("You are out of this group and its history is still here. Delete it from this device to join with a link.");
|
|
@@ -27297,8 +27640,18 @@ var Groups = class {
|
|
|
27297
27640
|
continue;
|
|
27298
27641
|
}
|
|
27299
27642
|
if (group.invitation?.entry && !group.state) {
|
|
27300
|
-
|
|
27301
|
-
|
|
27643
|
+
if (this.gaveUp.has(group.id)) continue;
|
|
27644
|
+
const answered = this.host.linkReady(group.invitation.linkId) || !!this.host.linkSeen?.(group.invitation.linkId);
|
|
27645
|
+
const since = this.knockingSince.get(group.id);
|
|
27646
|
+
if (since === void 0 || answered) this.knockingSince.set(group.id, now);
|
|
27647
|
+
if (since === void 0) await this.reopenEntry(group).catch(() => {});
|
|
27648
|
+
else if (!answered && now - since > 36e5) {
|
|
27649
|
+
await this.giveUpJoin(group, now);
|
|
27650
|
+
continue;
|
|
27651
|
+
}
|
|
27652
|
+
const waited = now - group.createdAt, joins = countWaitingJoin(this.host, group.id, now, !answered && waited > this.timings.patienceMs);
|
|
27653
|
+
const every = joinKnockWait(waited, this.timings, joins);
|
|
27654
|
+
if (!answered && (now - (this.lastKnock.get(group.id) ?? 0) >= every || now >= (this.knockCheckAt.get(group.id) ?? Infinity))) await this.knock(group, now).catch(() => {});
|
|
27302
27655
|
continue;
|
|
27303
27656
|
}
|
|
27304
27657
|
if (group.invitation?.seedB64 && !group.state) {
|
|
@@ -27516,6 +27869,34 @@ var Groups = class {
|
|
|
27516
27869
|
await this.host.closeEdge(linkId);
|
|
27517
27870
|
}
|
|
27518
27871
|
}
|
|
27872
|
+
/** Nobody answered the link for `JOIN_GIVE_UP_MS`: the knocks stop, and the entry session with them, until Try again. */
|
|
27873
|
+
async giveUpJoin(group, now) {
|
|
27874
|
+
this.gaveUp.add(group.id);
|
|
27875
|
+
countWaitingJoin(this.host, group.id, now, false);
|
|
27876
|
+
traceJoin(group.id, "join.unanswered");
|
|
27877
|
+
await this.host.closeEdge(group.invitation.linkId).catch(() => {});
|
|
27878
|
+
this.host.emit();
|
|
27879
|
+
}
|
|
27880
|
+
/** A link join given up (`giveUpJoin`) knocks again, as when the link was opened: Try again. */
|
|
27881
|
+
async knockAgain(group, now = this.now()) {
|
|
27882
|
+
if (!this.gaveUp.delete(group.id)) return;
|
|
27883
|
+
this.knockingSince.set(group.id, now);
|
|
27884
|
+
this.lastKnock.delete(group.id);
|
|
27885
|
+
this.knocked.delete(group.id);
|
|
27886
|
+
this.knockRewrites.delete(group.id);
|
|
27887
|
+
await this.reopenEntry(group);
|
|
27888
|
+
this.host.emit();
|
|
27889
|
+
this.knock(group, now).catch(() => {});
|
|
27890
|
+
}
|
|
27891
|
+
/** The joiner's side of the link's entry session, opened again where it is gone (the same key, so the same session). */
|
|
27892
|
+
async reopenEntry(group) {
|
|
27893
|
+
const invitation = group.invitation;
|
|
27894
|
+
if ([...this.host.entries(group.id).values()].includes(invitation.linkId)) return;
|
|
27895
|
+
await this.host.openEntry({
|
|
27896
|
+
g: group.id,
|
|
27897
|
+
host: invitation.entry
|
|
27898
|
+
}, "guest", invitation.seedB64, invitation.entry);
|
|
27899
|
+
}
|
|
27519
27900
|
async knock(group, now = Date.now()) {
|
|
27520
27901
|
const invitation = group.invitation;
|
|
27521
27902
|
this.lastKnock.set(group.id, now);
|
|
@@ -27546,7 +27927,7 @@ var Groups = class {
|
|
|
27546
27927
|
}, now)));
|
|
27547
27928
|
const rewrites = (this.knockRewrites.get(group.id) ?? 0) + 1;
|
|
27548
27929
|
this.knockRewrites.set(group.id, rewrites);
|
|
27549
|
-
if (rewrites <= 2) this.knockCheckAt.set(group.id, now + 800 + gossipStart(key) % KNOCK_VERIFY_SPREAD_MS);
|
|
27930
|
+
if (rewrites <= 2 && now - group.createdAt <= this.timings.patienceMs) this.knockCheckAt.set(group.id, now + 800 + gossipStart(key) % KNOCK_VERIFY_SPREAD_MS);
|
|
27550
27931
|
traceJoin(group.id, "knock.published", { ms: Date.now() - started });
|
|
27551
27932
|
if (!this.knocked.has(group.id)) {
|
|
27552
27933
|
this.knocked.add(group.id);
|
|
@@ -27562,9 +27943,11 @@ var Groups = class {
|
|
|
27562
27943
|
knocks: knocks.length
|
|
27563
27944
|
});
|
|
27564
27945
|
let pending = this.pendingEntries.get(group.id);
|
|
27946
|
+
let ever;
|
|
27565
27947
|
for (const { key, ts } of knocks) {
|
|
27566
27948
|
const again = this.unwelcomed(group, session, key);
|
|
27567
27949
|
if (now - ts > 18e4 || rosterHas(session.roster, key) && !again || this.refused.has(key) || pending?.has(key) || key === entry.link.host) continue;
|
|
27950
|
+
if (!again && (ever ??= everMembers(session)).has(key)) continue;
|
|
27568
27951
|
if (again && this.rewelcomedLately(group.id, key)) continue;
|
|
27569
27952
|
const entryIds = new Set(this.host.entries(group.id).values());
|
|
27570
27953
|
const contactsInvited = [...this.invited.get(group.id) ?? []].filter((id) => !entryIds.has(id)).length;
|
|
@@ -27822,6 +28205,7 @@ var Groups = class {
|
|
|
27822
28205
|
if (viaLink) {
|
|
27823
28206
|
this.lastKnock.delete(g);
|
|
27824
28207
|
this.knocked.delete(g);
|
|
28208
|
+
this.knockingSince.delete(g);
|
|
27825
28209
|
if (this.host.linkReady(linkId, 5)) this.signals.keep(g, linkId);
|
|
27826
28210
|
}
|
|
27827
28211
|
this.reconcileEdges(g);
|
|
@@ -28178,12 +28562,16 @@ var Groups = class {
|
|
|
28178
28562
|
}
|
|
28179
28563
|
/**
|
|
28180
28564
|
* Whether the answer of the member asked for someone's messages may still be coming: its edge up, asked under
|
|
28181
|
-
* `MESH_SYNC_HOLD_MAX_MS` ago, and a message of its answer (or the asking) under `MESH_SYNC_HOLD_MS` ago
|
|
28565
|
+
* `MESH_SYNC_HOLD_MAX_MS` ago, and a message of its answer (or the asking) under `MESH_SYNC_HOLD_MS` ago; or, however
|
|
28566
|
+
* long ago, frames of its edge still waiting to be handled here. An app that handles a frame a second was still on the
|
|
28567
|
+
* others' syncs ahead of that answer 1.5 s after the ask, and on its 200 messages three minutes after: the next member
|
|
28568
|
+
* was asked for the same messages, and both handed them on.
|
|
28182
28569
|
*/
|
|
28183
28570
|
answering(groupId, { via, at }, now) {
|
|
28184
28571
|
const edge = this.host.edges(groupId).get(via);
|
|
28185
|
-
if (!edge || !this.host.linkReady(edge)
|
|
28186
|
-
|
|
28572
|
+
if (!edge || !this.host.linkReady(edge)) return false;
|
|
28573
|
+
if ((this.host.linkWaiting?.(edge) ?? 0) > 0) return true;
|
|
28574
|
+
return now - at < 18e4 && now - Math.max(at, this.lastHanded.get(groupId)?.get(via) ?? 0) < 1500;
|
|
28187
28575
|
}
|
|
28188
28576
|
/**
|
|
28189
28577
|
* Whether the sync to a member whose edge just opened waits (`heldSyncs` sends it): its messages were asked of
|
|
@@ -28508,6 +28896,7 @@ var Groups = class {
|
|
|
28508
28896
|
seqFloor: () => this.host.seqFloor?.() ?? 0,
|
|
28509
28897
|
adminWork: () => this.host.adminWork?.(state.id) ?? true,
|
|
28510
28898
|
adminTurn: () => this.host.adminTurn?.(state.id) ?? Promise.resolve(true),
|
|
28899
|
+
removed: (id) => this.isRemoved(state.id, id),
|
|
28511
28900
|
save: async (next) => {
|
|
28512
28901
|
const group = this.stored.get(state.id);
|
|
28513
28902
|
if (!group || this.sessions.get(state.id) !== session) return;
|
|
@@ -28535,7 +28924,7 @@ var Groups = class {
|
|
|
28535
28924
|
message: async (m) => {
|
|
28536
28925
|
const timestamp = m.timestamp;
|
|
28537
28926
|
const mentioned = m.sender !== session.myKey && mentionsMember(m.mentions, session.myKey);
|
|
28538
|
-
const file = m.file && this.files ? await this.files.announced(state.id, {
|
|
28927
|
+
const file = m.file && this.files && !this.isRemoved(state.id, m.id) ? await this.files.announced(state.id, {
|
|
28539
28928
|
id: m.id,
|
|
28540
28929
|
sender: m.sender,
|
|
28541
28930
|
ts: m.timestamp,
|
|
@@ -28578,10 +28967,12 @@ var Groups = class {
|
|
|
28578
28967
|
...row,
|
|
28579
28968
|
at: this.now()
|
|
28580
28969
|
}, placedAbove);
|
|
28970
|
+
if (stored === false && !completed && this.isRemoved(state.id, m.id)) {
|
|
28971
|
+
this.typings.messageFrom(state.id, m.sender);
|
|
28972
|
+
return;
|
|
28973
|
+
}
|
|
28581
28974
|
const came = m.sender === session.myKey ? timestamp : cameAt(timestamp, stored, arrivalNow(this.now()));
|
|
28582
|
-
this.
|
|
28583
|
-
if (mentioned) this.lastMentionAt.set(state.id, Math.max(this.lastMentionAt.get(state.id) ?? 0, came));
|
|
28584
|
-
if (m.sender !== session.myKey) this.lastPeerMessageAt.set(state.id, Math.max(this.lastPeerMessageAt.get(state.id) ?? 0, came));
|
|
28975
|
+
markCame(this.marks, state.id, m.id, came, m.sender !== session.myKey, mentioned);
|
|
28585
28976
|
noteCame(this.stored.get(state.id), came, m.sender !== session.myKey, mentioned);
|
|
28586
28977
|
this.typings.messageFrom(state.id, m.sender);
|
|
28587
28978
|
},
|
|
@@ -28592,10 +28983,10 @@ var Groups = class {
|
|
|
28592
28983
|
edit: (e) => this.host.groupEdit?.(state.id, e),
|
|
28593
28984
|
changed: () => {
|
|
28594
28985
|
if (session.status === "removed" && this.hubs.isHub(state.id) && !this.removedAt.has(state.id)) this.removedAt.set(state.id, this.now());
|
|
28595
|
-
this.membershipChanged(state.id);
|
|
28986
|
+
this.membershipChanged(state.id).catch(() => {});
|
|
28596
28987
|
},
|
|
28597
28988
|
metaChanged: (by, change, at) => {
|
|
28598
|
-
this.metaChanged(state.id, session, by, change, at);
|
|
28989
|
+
this.metaChanged(state.id, session, by, change, at).catch(() => {});
|
|
28599
28990
|
},
|
|
28600
28991
|
...this.host.linkHandled && { handled: (to) => {
|
|
28601
28992
|
const edge = this.host.edges(state.id).get(to);
|
|
@@ -29131,6 +29522,8 @@ var GroupEdits = class {
|
|
|
29131
29522
|
heard = /* @__PURE__ */ new Map();
|
|
29132
29523
|
/** The connection `resend` last spoke on, per group and member: a new one hears my latest edits again. */
|
|
29133
29524
|
resentOn = /* @__PURE__ */ new Map();
|
|
29525
|
+
/** The list of my edited messages a paced resend goes on with, and the edge it was read for (`resendNow`). */
|
|
29526
|
+
keptMine = /* @__PURE__ */ new Map();
|
|
29134
29527
|
resendPace = /* @__PURE__ */ new Map();
|
|
29135
29528
|
resendTimers = /* @__PURE__ */ new Map();
|
|
29136
29529
|
resending = /* @__PURE__ */ new Map();
|
|
@@ -29431,23 +29824,30 @@ var GroupEdits = class {
|
|
|
29431
29824
|
* A new connection hears my latest `GROUP_EDIT_RESEND` again whatever it heard: one may have come before its message
|
|
29432
29825
|
* and been dropped. Called again while the edge is the same, it goes on from where it was.
|
|
29433
29826
|
*/
|
|
29434
|
-
resend(groupId, to) {
|
|
29827
|
+
resend(groupId, to, paced = false) {
|
|
29435
29828
|
const key = resendKey(groupId, to);
|
|
29436
|
-
const run = (this.resending.get(key) ?? Promise.resolve()).then(() => this.resendNow(groupId, to));
|
|
29829
|
+
const run = (this.resending.get(key) ?? Promise.resolve()).then(() => this.resendNow(groupId, to, paced));
|
|
29437
29830
|
const settled = run.catch(() => {}).finally(() => {
|
|
29438
29831
|
if (this.resending.get(key) === settled) this.resending.delete(key);
|
|
29439
29832
|
});
|
|
29440
29833
|
this.resending.set(key, settled);
|
|
29441
29834
|
return run;
|
|
29442
29835
|
}
|
|
29443
|
-
|
|
29836
|
+
/**
|
|
29837
|
+
* `paced`: the pace's timer goes on with the list of my edited messages read when the edge opened (`keptMine`), on
|
|
29838
|
+
* that same edge. Read again each window, 7 edges with 256 edits each to say read a history of 10,000 rows 112
|
|
29839
|
+
* times at a start, ~5.9 s of a CLI's engine, not 7 (agents#1679). Edits made meanwhile go live (`flush`).
|
|
29840
|
+
*/
|
|
29841
|
+
async resendNow(groupId, to, paced = false) {
|
|
29444
29842
|
const key = resendKey(groupId, to), chat = chatOf(groupId);
|
|
29445
29843
|
clearTimeout(this.resendTimers.get(key));
|
|
29446
29844
|
this.resendTimers.delete(key);
|
|
29447
29845
|
const open = () => this.host.edge ? this.host.edge(groupId, to) : true;
|
|
29448
29846
|
const edge = open(), membership = this.host.membership(groupId);
|
|
29847
|
+
const kept = this.keptMine.get(key);
|
|
29848
|
+
this.keptMine.delete(key);
|
|
29449
29849
|
if (this.stopped || edge === void 0 || !membership || membership.community || !membership.members.has(to)) return;
|
|
29450
|
-
const mine = (await (this.host.history ? this.host.history(chat) : this.host.messages(chat))).filter((m) => m.sender === "me" && m.edit && !m.edit.pending && canEditInGroup(m)).sort((a, b) => a.edit.at - b.edit.at || (a.id < b.id ? -1 : 1));
|
|
29850
|
+
const mine = paced && kept?.edge === edge ? kept.mine : (await (this.host.history ? this.host.history(chat) : this.host.messages(chat))).filter((m) => m.sender === "me" && m.edit && !m.edit.pending && canEditInGroup(m)).sort((a, b) => a.edit.at - b.edit.at || (a.id < b.id ? -1 : 1));
|
|
29451
29851
|
const last = this.heard.get(key);
|
|
29452
29852
|
const after = (m) => !last || m.edit.at > last.at || m.edit.at === last.at && m.id > last.id;
|
|
29453
29853
|
const unheard = last ? mine.filter(after).length : Math.min(mine.length, 256);
|
|
@@ -29459,8 +29859,12 @@ var GroupEdits = class {
|
|
|
29459
29859
|
for (const m of due) {
|
|
29460
29860
|
if (this.stopped || open() !== edge) return;
|
|
29461
29861
|
if (!pace.take()) {
|
|
29862
|
+
this.keptMine.set(key, {
|
|
29863
|
+
edge,
|
|
29864
|
+
mine
|
|
29865
|
+
});
|
|
29462
29866
|
this.resendTimers.set(key, setTimeout(() => {
|
|
29463
|
-
this.resend(groupId, to).catch(() => {});
|
|
29867
|
+
this.resend(groupId, to, true).catch(() => {});
|
|
29464
29868
|
}, Math.max(50, pace.wait())));
|
|
29465
29869
|
return;
|
|
29466
29870
|
}
|
|
@@ -29482,6 +29886,7 @@ var GroupEdits = class {
|
|
|
29482
29886
|
for (const key of [...this.heard.keys()]) if (of(key)) this.heard.delete(key);
|
|
29483
29887
|
for (const key of [...this.resendPace.keys()]) if (of(key)) this.resendPace.delete(key);
|
|
29484
29888
|
for (const key of [...this.resentOn.keys()]) if (of(key)) this.resentOn.delete(key);
|
|
29889
|
+
for (const key of [...this.keptMine.keys()]) if (of(key)) this.keptMine.delete(key);
|
|
29485
29890
|
}
|
|
29486
29891
|
forget(groupId) {
|
|
29487
29892
|
clearTimeout(this.timers.get(groupId));
|
|
@@ -31858,6 +32263,8 @@ var SWAP_POLL_MS = 3e4;
|
|
|
31858
32263
|
var SWAP_SLOW_POLL_MS = 6e5;
|
|
31859
32264
|
/** How long a swap whose inputs were given back is still asked about, in case the mint made it after all. */
|
|
31860
32265
|
var SWAP_WATCH_MS = 36e5;
|
|
32266
|
+
/** How many proofs of tokens refused as spent are remembered. */
|
|
32267
|
+
var SPENT_KEPT = 1e3;
|
|
31861
32268
|
/** Cashu's library (174 KiB) loads with the wallet's first use of a mint or a token, not with the app's start. */
|
|
31862
32269
|
var loadCashu = () => import("@cashu/cashu-ts");
|
|
31863
32270
|
async function reviewedCashuFee(preview) {
|
|
@@ -31958,6 +32365,11 @@ var CashuWallet = class CashuWallet {
|
|
|
31958
32365
|
failedFees = /* @__PURE__ */ new Map();
|
|
31959
32366
|
/** Melt quotes that ended unpaid with proofs the mint read spent: ecash spent somewhere else, said as such. */
|
|
31960
32367
|
spentAway = /* @__PURE__ */ new Set();
|
|
32368
|
+
/**
|
|
32369
|
+
* Proofs of tokens the mint read spent by something else (`mint secret`), the newest SPENT_KEPT: spent stays spent,
|
|
32370
|
+
* so the same token sent again, under any id or encoding, is refused without asking the mint again.
|
|
32371
|
+
*/
|
|
32372
|
+
spentTokens = /* @__PURE__ */ new Set();
|
|
31961
32373
|
/** Per melt quote shown to the person: the invoice, its amount and the fee reserve the mint quoted. Only these are paid. */
|
|
31962
32374
|
shownQuotes = /* @__PURE__ */ new Map();
|
|
31963
32375
|
/**
|
|
@@ -32127,7 +32539,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32127
32539
|
paymentId,
|
|
32128
32540
|
...paysItsOwnInvoices(mint) ? { held: true } : {}
|
|
32129
32541
|
};
|
|
32130
|
-
await
|
|
32542
|
+
await committed((await store(STORES$1.quotes, "readwrite")).put(quote));
|
|
32131
32543
|
this.pollQuotes();
|
|
32132
32544
|
return quote;
|
|
32133
32545
|
}
|
|
@@ -32140,7 +32552,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32140
32552
|
const wanted = invoice.trim().toLowerCase();
|
|
32141
32553
|
const quote = (await wrap((await store(STORES$1.quotes, "readonly")).getAll())).find((q) => q.invoice.toLowerCase() === wanted);
|
|
32142
32554
|
if (!quote) return false;
|
|
32143
|
-
if (quote.held) await
|
|
32555
|
+
if (quote.held) await committed((await store(STORES$1.quotes, "readwrite")).put({
|
|
32144
32556
|
...quote,
|
|
32145
32557
|
held: void 0
|
|
32146
32558
|
}));
|
|
@@ -32170,7 +32582,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32170
32582
|
expiresAt: response.expiry ? response.expiry * 1e3 : null,
|
|
32171
32583
|
testCoins: true
|
|
32172
32584
|
};
|
|
32173
|
-
await
|
|
32585
|
+
await committed((await store(STORES$1.quotes, "readwrite")).put(quote));
|
|
32174
32586
|
const deadline = Date.now() + TEST_COINS_WAIT_MS;
|
|
32175
32587
|
for (;;) {
|
|
32176
32588
|
if (await this.locked(mint, () => this.settleQuote(quote.quote))) {
|
|
@@ -32209,7 +32621,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32209
32621
|
this.quoteTimer = null;
|
|
32210
32622
|
if (this.stopped) return;
|
|
32211
32623
|
const quotes = await wrap((await store(STORES$1.quotes, "readonly")).getAll());
|
|
32212
|
-
for (const held of quotes.filter((q) => q.held && q.expiresAt && q.expiresAt + 6e4 < Date.now())) await
|
|
32624
|
+
for (const held of quotes.filter((q) => q.held && q.expiresAt && q.expiresAt + 6e4 < Date.now())) await committed((await store(STORES$1.quotes, "readwrite")).delete(held.quote));
|
|
32213
32625
|
await this.settleQuotes(quotes);
|
|
32214
32626
|
const remaining = await wrap((await store(STORES$1.quotes, "readonly")).getAll());
|
|
32215
32627
|
if (!this.stopped && remaining.some((q) => !q.issuedUnclaimed && !q.held)) this.quoteTimer = setTimeout(() => void this.pollQuotes(), QUOTE_POLL_MS);
|
|
@@ -32232,7 +32644,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32232
32644
|
const answer = await wallet.checkMintQuoteBolt11(quote.quote);
|
|
32233
32645
|
const { state } = answer;
|
|
32234
32646
|
if (state === "UNPAID") {
|
|
32235
|
-
if (quote.expiresAt && quote.expiresAt + 6e4 < Date.now()) await
|
|
32647
|
+
if (quote.expiresAt && quote.expiresAt + 6e4 < Date.now()) await committed((await store(STORES$1.quotes, "readwrite")).delete(quote.quote));
|
|
32236
32648
|
return null;
|
|
32237
32649
|
}
|
|
32238
32650
|
const saved = quote.outputs?.map((o) => OutputData.deserialize(o));
|
|
@@ -32240,7 +32652,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32240
32652
|
const issued = saved?.length ? await this.signedOutputs(wallet, saved) : void 0;
|
|
32241
32653
|
if (Array.isArray(issued)) return this.storeMinted(quote, issued);
|
|
32242
32654
|
console.warn(`[wallet] ${quote.mint} issued quote ${quote.quote} (${quote.amount} sats) but this wallet holds no ecash for it`);
|
|
32243
|
-
await
|
|
32655
|
+
await committed((await store(STORES$1.quotes, "readwrite")).put({
|
|
32244
32656
|
...quote,
|
|
32245
32657
|
issuedUnclaimed: true
|
|
32246
32658
|
}));
|
|
@@ -32256,14 +32668,14 @@ var CashuWallet = class CashuWallet {
|
|
|
32256
32668
|
paid: true,
|
|
32257
32669
|
outputs: saved ? quote.outputs : preview.outputData.map((o) => OutputData.serialize(o))
|
|
32258
32670
|
};
|
|
32259
|
-
if (!quote.paid || !saved) await
|
|
32671
|
+
if (!quote.paid || !saved) await committed((await store(STORES$1.quotes, "readwrite")).put(written));
|
|
32260
32672
|
let proofs;
|
|
32261
32673
|
try {
|
|
32262
32674
|
proofs = await wallet.completeMint(preview);
|
|
32263
32675
|
} catch (error) {
|
|
32264
32676
|
if (saved && isMintOperationError(error) && (await wallet.checkMintQuoteBolt11(quote.quote).catch(() => null))?.state === "PAID") {
|
|
32265
32677
|
const { outputs: _refused, ...fresh } = written;
|
|
32266
|
-
await
|
|
32678
|
+
await committed((await store(STORES$1.quotes, "readwrite")).put(fresh));
|
|
32267
32679
|
}
|
|
32268
32680
|
throw error;
|
|
32269
32681
|
}
|
|
@@ -32654,6 +33066,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32654
33066
|
};
|
|
32655
33067
|
if (!swap) {
|
|
32656
33068
|
const preview = await (await this.wallet(mint)).prepareSwapToReceive(token);
|
|
33069
|
+
if (preview.inputs.some((p) => this.spentTokens.has(`${mint} ${p.secret}`))) throw engineError("ecashAlreadySpent");
|
|
32657
33070
|
const redeeming = new Set(written.flatMap((s) => (swapOf(s).inputs ?? []).map((p) => p.secret)));
|
|
32658
33071
|
if (preview.inputs.some((p) => redeeming.has(p.secret))) throw engineError("ecashBeingReceived");
|
|
32659
33072
|
swap = {
|
|
@@ -32665,7 +33078,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32665
33078
|
token,
|
|
32666
33079
|
...records(preview.amount.toNumber())
|
|
32667
33080
|
};
|
|
32668
|
-
await
|
|
33081
|
+
await committed((await store(STORES$1.swaps, "readwrite")).put(swap));
|
|
32669
33082
|
}
|
|
32670
33083
|
const { keep } = await this.completeSwap(swap);
|
|
32671
33084
|
const credited = sats(keep);
|
|
@@ -32757,11 +33170,12 @@ var CashuWallet = class CashuWallet {
|
|
|
32757
33170
|
...swap,
|
|
32758
33171
|
attemptEndedAt: Date.now()
|
|
32759
33172
|
};
|
|
32760
|
-
await (async () =>
|
|
33173
|
+
await (async () => committed((await store(STORES$1.swaps, "readwrite")).put(ended)))().catch(() => {});
|
|
32761
33174
|
const outcome = await this.swapOutcome(ended, refused).catch(() => ({ state: "open" }));
|
|
32762
33175
|
if (outcome.state === "done") return outcome;
|
|
32763
33176
|
if (outcome.state === "never" && outcome.final) {
|
|
32764
33177
|
await this.dropSwap(ended, outcome.gone);
|
|
33178
|
+
if (swap.kind === "receive") this.rememberSpent(swap.mint, outcome.gone);
|
|
32765
33179
|
throw outcome.gone.size > 0 ? Object.assign(engineError("ecashAlreadySpent"), { cause: error }) : error;
|
|
32766
33180
|
}
|
|
32767
33181
|
this.swapsAgainIn(SWAP_POLL_MS);
|
|
@@ -32901,6 +33315,17 @@ var CashuWallet = class CashuWallet {
|
|
|
32901
33315
|
});
|
|
32902
33316
|
if (gone.size > 0 && inputs.length > 0) this.recheck(swap.mint).catch(() => {});
|
|
32903
33317
|
}
|
|
33318
|
+
rememberSpent(mint, secrets) {
|
|
33319
|
+
for (const secret of secrets) {
|
|
33320
|
+
const key = `${mint} ${secret}`;
|
|
33321
|
+
this.spentTokens.delete(key);
|
|
33322
|
+
this.spentTokens.add(key);
|
|
33323
|
+
}
|
|
33324
|
+
for (const oldest of this.spentTokens) {
|
|
33325
|
+
if (this.spentTokens.size <= SPENT_KEPT) break;
|
|
33326
|
+
this.spentTokens.delete(oldest);
|
|
33327
|
+
}
|
|
33328
|
+
}
|
|
32904
33329
|
/** The proofs a split reserved, as they are stored now. */
|
|
32905
33330
|
async storedInputs(swap) {
|
|
32906
33331
|
const secrets = new Set(swapOf(swap).inputs.map((p) => p.secret));
|
|
@@ -32960,7 +33385,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32960
33385
|
if (!swap) return;
|
|
32961
33386
|
try {
|
|
32962
33387
|
if (swap.finished) {
|
|
32963
|
-
if (await this.tellSwap(swap, true)) await
|
|
33388
|
+
if (await this.tellSwap(swap, true)) await committed((await store(STORES$1.swaps, "readwrite")).delete(swap.id));
|
|
32964
33389
|
else later(SWAP_POLL_MS);
|
|
32965
33390
|
return;
|
|
32966
33391
|
}
|
|
@@ -32973,7 +33398,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32973
33398
|
...swap,
|
|
32974
33399
|
attemptEndedAt: Date.now()
|
|
32975
33400
|
};
|
|
32976
|
-
await
|
|
33401
|
+
await committed((await store(STORES$1.swaps, "readwrite")).put(swap));
|
|
32977
33402
|
}
|
|
32978
33403
|
const outcome = await this.swapOutcome(swap);
|
|
32979
33404
|
if (outcome.state === "open") {
|
|
@@ -32984,7 +33409,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32984
33409
|
if (outcome.slow) {
|
|
32985
33410
|
const stuck = (swap.stuck ?? 0) + 1;
|
|
32986
33411
|
const wait = stuck <= 6 ? SWAP_SLOW_POLL_MS : stuck <= 30 ? 36e5 : 864e5;
|
|
32987
|
-
await
|
|
33412
|
+
await committed((await store(STORES$1.swaps, "readwrite")).put({
|
|
32988
33413
|
...swap,
|
|
32989
33414
|
stuck,
|
|
32990
33415
|
askAt: Date.now() + wait
|
|
@@ -32997,7 +33422,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32997
33422
|
const { keep } = await (await this.wallet(mint)).completeSwap(deserializeSwapPreview(swapOf(swap)));
|
|
32998
33423
|
if (await this.finishSwap(swap, keep, [], true)) {
|
|
32999
33424
|
const told = await this.tellSwap(swap, true);
|
|
33000
|
-
if (swap.payment && told) await
|
|
33425
|
+
if (swap.payment && told) await committed((await store(STORES$1.swaps, "readwrite")).delete(swap.id));
|
|
33001
33426
|
else if (swap.payment) later(SWAP_POLL_MS);
|
|
33002
33427
|
this.events.onChange();
|
|
33003
33428
|
}
|
|
@@ -33006,12 +33431,12 @@ var CashuWallet = class CashuWallet {
|
|
|
33006
33431
|
...swap,
|
|
33007
33432
|
attemptEndedAt: Date.now()
|
|
33008
33433
|
};
|
|
33009
|
-
await
|
|
33434
|
+
await committed((await store(STORES$1.swaps, "readwrite")).put(swap));
|
|
33010
33435
|
const refusal = isMintOperationError(error) ? await this.swapOutcome(swap, true).catch(() => void 0) : void 0;
|
|
33011
33436
|
if (refusal?.state === "done") {
|
|
33012
33437
|
if (await this.finishSwap(swap, refusal.keep, refusal.send, true)) {
|
|
33013
33438
|
const told = await this.tellSwap(swap, true);
|
|
33014
|
-
if (swap.payment && told) await
|
|
33439
|
+
if (swap.payment && told) await committed((await store(STORES$1.swaps, "readwrite")).delete(swap.id));
|
|
33015
33440
|
}
|
|
33016
33441
|
this.events.onChange();
|
|
33017
33442
|
} else if (refusal?.state === "never") {
|
|
@@ -33022,7 +33447,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33022
33447
|
}
|
|
33023
33448
|
} else if (outcome.pending && swap.kind === "receive" && !swap.released && Date.now() >= swapOverdueAt(swap)) {
|
|
33024
33449
|
if (Date.now() < swap.createdAt + SWAP_WATCH_MS) {
|
|
33025
|
-
await
|
|
33450
|
+
await committed((await store(STORES$1.swaps, "readwrite")).put({
|
|
33026
33451
|
...swap,
|
|
33027
33452
|
askAt: Date.now() + SWAP_SLOW_POLL_MS
|
|
33028
33453
|
}));
|
|
@@ -33038,7 +33463,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33038
33463
|
if (outcome.state === "done") {
|
|
33039
33464
|
if (await this.finishSwap(swap, outcome.keep, outcome.send, true)) {
|
|
33040
33465
|
const told = await this.tellSwap(swap, true);
|
|
33041
|
-
if (swap.payment && told) await
|
|
33466
|
+
if (swap.payment && told) await committed((await store(STORES$1.swaps, "readwrite")).delete(swap.id));
|
|
33042
33467
|
else if (swap.payment) later(SWAP_POLL_MS);
|
|
33043
33468
|
}
|
|
33044
33469
|
} else if (swap.released) {
|
|
@@ -33446,10 +33871,95 @@ var allows = (link, method) => method === "arkade" ? link.supportsArkPayments :
|
|
|
33446
33871
|
/** Federation ecash is counted in msats; a chat counts whole sats. */
|
|
33447
33872
|
var fedimintSats = (msats) => Math.floor(msats / 1e3);
|
|
33448
33873
|
/**
|
|
33449
|
-
*
|
|
33450
|
-
*
|
|
33874
|
+
* The bytes of notes as the Fedimint client reads them (OOBNotes::from_str), whitespace already dropped: base32hex
|
|
33875
|
+
* after a `fedimint` prefix in any case (least significant bits first, a short last group dropped), else URL-safe
|
|
33876
|
+
* or standard base64. Undefined: no such text.
|
|
33877
|
+
*/
|
|
33878
|
+
function oobNotesBytes(text) {
|
|
33879
|
+
const lower = text.toLowerCase();
|
|
33880
|
+
if (lower.startsWith("fedimint")) {
|
|
33881
|
+
const out = [];
|
|
33882
|
+
let buffer = 0, bits = 0;
|
|
33883
|
+
for (const ch of lower.slice(8)) {
|
|
33884
|
+
const value = "0123456789abcdefghijklmnopqrstuv".indexOf(ch);
|
|
33885
|
+
if (value < 0) {
|
|
33886
|
+
out.length = 0;
|
|
33887
|
+
bits = -1;
|
|
33888
|
+
break;
|
|
33889
|
+
}
|
|
33890
|
+
buffer |= value << bits;
|
|
33891
|
+
bits += 5;
|
|
33892
|
+
while (bits >= 8) {
|
|
33893
|
+
out.push(buffer & 255);
|
|
33894
|
+
buffer >>>= 8;
|
|
33895
|
+
bits -= 8;
|
|
33896
|
+
}
|
|
33897
|
+
}
|
|
33898
|
+
if (bits >= 0) return Uint8Array.from(out);
|
|
33899
|
+
}
|
|
33900
|
+
try {
|
|
33901
|
+
return fromBase64Url(text.replace(/=+$/, "").replace(/\+/g, "-").replace(/\//g, "_"));
|
|
33902
|
+
} catch {
|
|
33903
|
+
return;
|
|
33904
|
+
}
|
|
33905
|
+
}
|
|
33906
|
+
/** A BigSize number (Fedimint's consensus integer) at `at`, and where what follows it starts. */
|
|
33907
|
+
function bigSize(bytes, at) {
|
|
33908
|
+
const first = bytes[at];
|
|
33909
|
+
const width = first === 253 ? 2 : first === 254 ? 4 : first === 255 ? 8 : 0;
|
|
33910
|
+
if (first === void 0 || at + 1 + width > bytes.length) throw new Error("short");
|
|
33911
|
+
let value = width ? 0 : first;
|
|
33912
|
+
for (let i = 1; i <= width; i++) value = value * 256 + bytes[at + i];
|
|
33913
|
+
return [value, at + 1 + width];
|
|
33914
|
+
}
|
|
33915
|
+
/**
|
|
33916
|
+
* The signatures of the notes the federation redeems, sorted, each once: OOBNotes are a list of parts (tag, length,
|
|
33917
|
+
* bytes) and the client takes the first Notes part (tag 0: tiers of amount, count, then 48-byte signature and 32-byte
|
|
33918
|
+
* key per note). Undefined: the bytes are no OOBNotes.
|
|
33919
|
+
*/
|
|
33920
|
+
function oobNoteSignatures(bytes) {
|
|
33921
|
+
try {
|
|
33922
|
+
let [parts, at] = bigSize(bytes, 0);
|
|
33923
|
+
let signatures;
|
|
33924
|
+
for (; parts > 0; parts--) {
|
|
33925
|
+
const [tag, sized] = bigSize(bytes, at);
|
|
33926
|
+
const [length, start] = bigSize(bytes, sized);
|
|
33927
|
+
const end = start + length;
|
|
33928
|
+
if (end > bytes.length) return void 0;
|
|
33929
|
+
if (tag === 0 && !signatures) {
|
|
33930
|
+
const found = /* @__PURE__ */ new Set();
|
|
33931
|
+
const part = bytes.subarray(0, end);
|
|
33932
|
+
let [tiers, i] = bigSize(part, start);
|
|
33933
|
+
for (; tiers > 0; tiers--) {
|
|
33934
|
+
let count;
|
|
33935
|
+
[, i] = bigSize(part, i);
|
|
33936
|
+
[count, i] = bigSize(part, i);
|
|
33937
|
+
if (i + count * 80 > end) return void 0;
|
|
33938
|
+
for (; count > 0; count--, i += 80) found.add(hexOf(bytes.subarray(i, i + 48)));
|
|
33939
|
+
}
|
|
33940
|
+
if (i !== end || !found.size) return void 0;
|
|
33941
|
+
signatures = [...found].sort();
|
|
33942
|
+
}
|
|
33943
|
+
at = end;
|
|
33944
|
+
}
|
|
33945
|
+
return at === bytes.length ? signatures : void 0;
|
|
33946
|
+
} catch {
|
|
33947
|
+
return;
|
|
33948
|
+
}
|
|
33949
|
+
}
|
|
33950
|
+
var hexOf = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
33951
|
+
/**
|
|
33952
|
+
* Which notes these are, whatever the encoding: the digest of the signatures of the notes the federation redeems, so
|
|
33953
|
+
* reordered or repeated parts, an unknown part, notes reordered in a tier and base32 or base64 spellings all give the
|
|
33954
|
+
* same one. Text that is no OOBNotes is digested as `fedimintBytesDigest` does.
|
|
33451
33955
|
*/
|
|
33452
33956
|
function fedimintNotesDigest(notes) {
|
|
33957
|
+
const bytes = oobNotesBytes(notes.replace(/\s+/g, ""));
|
|
33958
|
+
const signatures = bytes && oobNoteSignatures(bytes);
|
|
33959
|
+
return signatures ? digestHex(`fedimint-notes:${signatures.join(",")}`) : fedimintBytesDigest(notes);
|
|
33960
|
+
}
|
|
33961
|
+
/** What earlier versions wrote down for notes: the digest of their base64 bytes, or of the text without its whitespace. */
|
|
33962
|
+
function fedimintBytesDigest(notes) {
|
|
33453
33963
|
const text = notes.replace(/\s+/g, "");
|
|
33454
33964
|
try {
|
|
33455
33965
|
return digestHex(toBase64Url(fromBase64Url(text.replace(/=+$/, ""))));
|
|
@@ -34246,6 +34756,7 @@ var PaymentDesk = class {
|
|
|
34246
34756
|
if (now - (this.lastAskFrom.get(linkId) ?? 0) < 3e3) return;
|
|
34247
34757
|
this.lastAskFrom.set(linkId, now);
|
|
34248
34758
|
if ([...this.payments.values()].filter((p) => p.linkId === linkId && p.kind === "request" && p.direction === "out" && p.state === "pending" && p.ask).length >= 5 || !/^[1-9]\d{0,15}$/.test(ask.amount.value)) return;
|
|
34759
|
+
if (ask.method === "bitcoin" && [...this.payments.values()].filter((p) => p.kind === "request" && p.direction === "out" && p.ask && p.target?.method === "bitcoin" && now - p.createdAt < 36e5).length >= 10) return;
|
|
34249
34760
|
if (ask.amount.asset !== (ask.method === "usdt" ? "usdtbase" : UNIT)) return;
|
|
34250
34761
|
if (!allows(link, ask.method)) return;
|
|
34251
34762
|
if (!this.accepts(linkId, ask.method, ask.network ?? this.defaultNetwork())) return;
|
|
@@ -34533,10 +35044,11 @@ var PaymentDesk = class {
|
|
|
34533
35044
|
error: reason
|
|
34534
35045
|
});
|
|
34535
35046
|
const sats = parseSats(payment.amount.value, payment.amount.asset);
|
|
35047
|
+
const spent = error instanceof EngineError && error.engineCode === "ecashAlreadySpent";
|
|
34536
35048
|
try {
|
|
34537
35049
|
await this.host.storeMessage({
|
|
34538
35050
|
linkId,
|
|
34539
|
-
id: `peer_${payment.timestamp}_refused`,
|
|
35051
|
+
id: spent ? `peer_spent_${digestHex(token).slice(0, 32)}` : `peer_${payment.timestamp}_refused`,
|
|
34540
35052
|
text: `Could not receive ${sats === null ? "a payment" : `${sats.toLocaleString()} sats`}: ${reason}`,
|
|
34541
35053
|
sender: "peer",
|
|
34542
35054
|
timestamp: payment.timestamp,
|
|
@@ -34721,6 +35233,8 @@ var PaymentDesk = class {
|
|
|
34721
35233
|
lastCheckFrom = /* @__PURE__ */ new Map();
|
|
34722
35234
|
/** `receiveInvoicePaid`'s last look, by `<link id>:<invoice>`: only the last 3 seconds' are kept. */
|
|
34723
35235
|
lastInvoiceCheck = /* @__PURE__ */ new Map();
|
|
35236
|
+
/** The looks `receiveInvoicePaid` made for each chat in the last 3 s (at most `INVOICE_LOOKS_PER_CHAT`). */
|
|
35237
|
+
invoiceLooks = /* @__PURE__ */ new Map();
|
|
34724
35238
|
/**
|
|
34725
35239
|
* "I paid it from another wallet": the contact's app is asked to look at its wallet now. Nothing here
|
|
34726
35240
|
* marks anything paid; the request settles when the payee's wallet sees the money, with or without this.
|
|
@@ -34780,7 +35294,9 @@ var PaymentDesk = class {
|
|
|
34780
35294
|
* The contact says it paid an invoice of ours it found in the chat, with no request: a Receive-screen invoice is
|
|
34781
35295
|
* held on a test mint until then (StoredQuote `held`), and that one alone is let go. A request's invoice is spoken
|
|
34782
35296
|
* for by its own contact only (`receiveCheck`). Bounded: one look every 3 seconds per invoice of a chat, so two
|
|
34783
|
-
* invoices paid one right after the other are both let go
|
|
35297
|
+
* invoices paid one right after the other are both let go, and `INVOICE_LOOKS_PER_CHAT` looks every 3 seconds per
|
|
35298
|
+
* chat: the invoice is the contact's text, and a frame per text made each one a read of every invoice of the wallet
|
|
35299
|
+
* (2,000 frames, 2,000 reads), each also walking every key of the last 3 s (agents#1586).
|
|
34784
35300
|
*/
|
|
34785
35301
|
async receiveInvoicePaid(linkId, link, invoice) {
|
|
34786
35302
|
if (!link.allowsPayment("lightning")) return;
|
|
@@ -34788,8 +35304,19 @@ var PaymentDesk = class {
|
|
|
34788
35304
|
const wanted = invoice.trim().toLowerCase();
|
|
34789
35305
|
const key = `${linkId}:${wanted}`;
|
|
34790
35306
|
if (now - (this.lastInvoiceCheck.get(key) ?? 0) < 3e3) return;
|
|
34791
|
-
|
|
35307
|
+
const looks = (this.invoiceLooks.get(linkId) ?? []).filter((at) => now - at < 3e3);
|
|
35308
|
+
if (looks.length >= 5) {
|
|
35309
|
+
this.invoiceLooks.set(linkId, looks);
|
|
35310
|
+
return;
|
|
35311
|
+
}
|
|
35312
|
+
this.invoiceLooks.set(linkId, [...looks, now]);
|
|
35313
|
+
for (const [seen, at] of this.lastInvoiceCheck) {
|
|
35314
|
+
if (now - at < 3e3) break;
|
|
35315
|
+
this.lastInvoiceCheck.delete(seen);
|
|
35316
|
+
}
|
|
35317
|
+
this.lastInvoiceCheck.delete(key);
|
|
34792
35318
|
this.lastInvoiceCheck.set(key, now);
|
|
35319
|
+
for (const [chat, times] of this.invoiceLooks) if (chat !== linkId && times.every((at) => now - at >= 3e3)) this.invoiceLooks.delete(chat);
|
|
34793
35320
|
try {
|
|
34794
35321
|
const quote = (await this.wallet.quotes()).find((q) => q.held && !q.paymentId && q.invoice.toLowerCase() === wanted);
|
|
34795
35322
|
if (quote) await this.wallet.vouch(quote.invoice);
|
|
@@ -35558,8 +36085,9 @@ var PaymentDesk = class {
|
|
|
35558
36085
|
return;
|
|
35559
36086
|
}
|
|
35560
36087
|
const digest = fedimintNotesDigest(notes);
|
|
36088
|
+
const bytes = fedimintBytesDigest(notes);
|
|
35561
36089
|
const spelled = digestHex(notes.trim());
|
|
35562
|
-
const before = [...this.payments.values()].find((p) => (p.notesDigest === digest || p.notesDigest === spelled) && p.direction === "in" && p.kind === "payment");
|
|
36090
|
+
const before = [...this.payments.values()].find((p) => (p.notesDigest === digest || p.notesDigest === bytes || p.notesDigest === spelled) && p.direction === "in" && p.kind === "payment");
|
|
35563
36091
|
if (before) {
|
|
35564
36092
|
link.sendPaymentResult({
|
|
35565
36093
|
id: payment.id,
|
|
@@ -36103,7 +36631,7 @@ var PaymentDesk = class {
|
|
|
36103
36631
|
}
|
|
36104
36632
|
async save(payment) {
|
|
36105
36633
|
this.payments.set(payment.id, payment);
|
|
36106
|
-
await
|
|
36634
|
+
await committed((await store(STORES$1.payments, "readwrite")).put(payment));
|
|
36107
36635
|
this.host.onChange();
|
|
36108
36636
|
}
|
|
36109
36637
|
/**
|
|
@@ -36613,6 +37141,8 @@ var LIMITED_MODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
36613
37141
|
"setFastPoll",
|
|
36614
37142
|
"exportLinks",
|
|
36615
37143
|
"walletBackupReminder",
|
|
37144
|
+
"savedMessages",
|
|
37145
|
+
"saveMessage",
|
|
36616
37146
|
"deviceRestoreStartOwn"
|
|
36617
37147
|
]);
|
|
36618
37148
|
/** Thrown by the transport when something tries to publish in limited mode: a bug in a switch point, never a wait. */
|
|
@@ -36634,6 +37164,19 @@ function refusingWhileLimited(transport, limited) {
|
|
|
36634
37164
|
if (transport.publishPayload) guarded.publishPayload = (pubKeyZ32, payload, options) => limited() ? Promise.reject(new LimitedModeError()) : transport.publishPayload(pubKeyZ32, payload, options);
|
|
36635
37165
|
return guarded;
|
|
36636
37166
|
}
|
|
37167
|
+
/**
|
|
37168
|
+
* My key in an active group, and who is in it, from its one view. A received reaction, edit or pin reads it per frame:
|
|
37169
|
+
* built from every group's sorted views, a 256-frame catch-up in 10 communities of 256 took 11 s, not 1.1 s
|
|
37170
|
+
* (agents#1700).
|
|
37171
|
+
*/
|
|
37172
|
+
function membershipOf(group) {
|
|
37173
|
+
return group?.status === "active" && group.myKey ? {
|
|
37174
|
+
me: group.myKey,
|
|
37175
|
+
members: new Set(group.members.map((m) => m.key))
|
|
37176
|
+
} : void 0;
|
|
37177
|
+
}
|
|
37178
|
+
/** The wire part of the ids the payment desk gives a contact's payment, request or refusal line (`peer_<this>`). */
|
|
37179
|
+
var PAYMENT_LINE_ID = /^(?:\d+(?:_refused)?|spent_[0-9a-f]{32})$/;
|
|
36637
37180
|
var GhostlyNode = class GhostlyNode {
|
|
36638
37181
|
events;
|
|
36639
37182
|
options;
|
|
@@ -36807,6 +37350,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
36807
37350
|
cardEdits = new CardEditPacer();
|
|
36808
37351
|
/** When each message's buttons were last pressed here (`pressButton`). */
|
|
36809
37352
|
pressedAt = /* @__PURE__ */ new Map();
|
|
37353
|
+
/**
|
|
37354
|
+
* The presses taken on each message of mine with a `once` button (`resolveReply`), by chat and message id: each
|
|
37355
|
+
* member's replies that pressed it and the button. Read from the history once, at the message's first press here,
|
|
37356
|
+
* then added to as presses are taken (only `resolveReply` gives a row its press). Rows it names are read again
|
|
37357
|
+
* before they refuse a press: one deleted since answers nothing.
|
|
37358
|
+
*/
|
|
37359
|
+
cardPresses = /* @__PURE__ */ new Map();
|
|
36810
37360
|
/** At most one wake-up per contact per `WAKE_INTERVAL_MS` (WISP 401 § Wake-up push). */
|
|
36811
37361
|
wakeLimiter = new WakeLimiter();
|
|
36812
37362
|
/** Call wake-ups have their own, shorter limit: a call is rarer than a message and cannot wait five minutes. */
|
|
@@ -37556,9 +38106,25 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37556
38106
|
for (const pc of this.chatPeers) if (pc.connectionState === "closed") this.chatPeers.delete(pc);
|
|
37557
38107
|
return this.chatPeers.size;
|
|
37558
38108
|
}
|
|
38109
|
+
/**
|
|
38110
|
+
* The rows of a 1:1 chat a wire id may name besides `peer_`/`me_` and that id: a file of mine is `me_<its time>` and a
|
|
38111
|
+
* payment `me_` or `peer_` and its time, as `fileMessage` and `paymentMessage` read them. What a reaction, a reply or a
|
|
38112
|
+
* pin names is read so, alone, before a chat is read whole.
|
|
38113
|
+
*/
|
|
38114
|
+
async rowsNamed(chat, id) {
|
|
38115
|
+
const file = await fileStore.get(GhostlyNode.outgoingFileId(chat, id)).catch(() => void 0);
|
|
38116
|
+
const payment = this.desk.payment(paymentAlias(id, chat)) ?? this.desk.payment(id);
|
|
38117
|
+
return [...file?.linkId === chat && file.metadata ? [`me_${file.metadata.timestamp}`] : [], ...payment?.linkId === chat ? [`me_${payment.createdAt}`, `peer_${payment.createdAt}`] : []];
|
|
38118
|
+
}
|
|
38119
|
+
pinsHost = {
|
|
38120
|
+
messages: (chat) => db.getMessages(chat),
|
|
38121
|
+
message: (chat, id) => db.getMessage(chat, id),
|
|
38122
|
+
rows: (chat, id) => this.rowsNamed(chat, id)
|
|
38123
|
+
};
|
|
37559
38124
|
reactions = new Reactions({
|
|
37560
38125
|
messages: (chat) => db.getMessages(chat),
|
|
37561
38126
|
message: (chat, id) => db.getMessage(chat, id),
|
|
38127
|
+
rows: (chat, id) => this.rowsNamed(chat, id),
|
|
37562
38128
|
patch: (chat, id, change) => db.patchMessage(chat, id, change),
|
|
37563
38129
|
changed: async (chat, id, note) => {
|
|
37564
38130
|
const shown = this.reactionNotes.get(chat);
|
|
@@ -37603,7 +38169,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37603
38169
|
},
|
|
37604
38170
|
linkReady: (linkId, version = 1) => !!this.links.get(linkId)?.link?.supportsGroupVersion(version),
|
|
37605
38171
|
linkHandled: (linkId) => this.links.get(linkId)?.link?.handled() ?? Promise.resolve(false),
|
|
38172
|
+
linkWaiting: (linkId) => this.links.get(linkId)?.link?.framesWaiting() ?? 0,
|
|
37606
38173
|
linkOpen: (linkId) => !!this.links.get(linkId)?.link?.isDataLinkOpen,
|
|
38174
|
+
loaded: (groupId, history) => {
|
|
38175
|
+
const note = latestReaction(history);
|
|
38176
|
+
if (note) this.reactionNotes.set(`group:${groupId}`, note);
|
|
38177
|
+
},
|
|
37607
38178
|
myNick: () => this.sharedNick,
|
|
37608
38179
|
seqFloor: () => this.counterFloor,
|
|
37609
38180
|
adminWork: (groupId) => !this.limitedMode && !this.groupAdminOff.has(groupId),
|
|
@@ -37614,7 +38185,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37614
38185
|
if (typeof RTCPeerConnection === "undefined" && native.length) {
|
|
37615
38186
|
let held = 0;
|
|
37616
38187
|
for (const live of this.links.values()) if (live.stored.group && live.stored.group !== groupId && live.link) held++;
|
|
37617
|
-
return Math.max(0, Math.max(...native.map((key) => this.
|
|
38188
|
+
return Math.max(0, Math.max(...native.map((key) => this.groupNativeRoom(key))) - held);
|
|
37618
38189
|
}
|
|
37619
38190
|
const budget = this.options.peerBudget;
|
|
37620
38191
|
if (budget === void 0) return void 0;
|
|
@@ -37651,6 +38222,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37651
38222
|
door,
|
|
37652
38223
|
back
|
|
37653
38224
|
}))?.records ?? null,
|
|
38225
|
+
readHeldBackFor: (pubKeyZ32) => this.groupTransport.readHeldBackFor?.(pubKeyZ32),
|
|
37654
38226
|
expectPeer: (linkId) => this.links.get(linkId)?.link?.expectPeer(),
|
|
37655
38227
|
signalIn: (linkId, payload, direct) => !!this.links.get(linkId)?.carried?.accept(payload, direct),
|
|
37656
38228
|
edgeSignal: (linkId) => this.links.get(linkId)?.carried?.latest() ?? null,
|
|
@@ -37738,11 +38310,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37738
38310
|
},
|
|
37739
38311
|
changed: (chat, id) => this.messagesChanged(chat, [id]),
|
|
37740
38312
|
membership: (groupId) => {
|
|
37741
|
-
const
|
|
38313
|
+
const view = this.groups.view(groupId), membership = membershipOf(view);
|
|
37742
38314
|
return membership && {
|
|
37743
38315
|
...membership,
|
|
37744
38316
|
community: this.groups.isCommunityGroup(groupId),
|
|
37745
|
-
admin: !!
|
|
38317
|
+
admin: !!view?.isAdmin
|
|
37746
38318
|
};
|
|
37747
38319
|
},
|
|
37748
38320
|
send: (groupId, edit, to) => this.groups.sendEdit(groupId, edit, to),
|
|
@@ -37750,7 +38322,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37750
38322
|
removeMine: async (chat, message, removal) => {
|
|
37751
38323
|
const groupId = chat.slice(6);
|
|
37752
38324
|
await this.groups.setRemovals(groupId, withRemoval(this.groups.removals(groupId), removal));
|
|
37753
|
-
await this.forgetGroupMessage(chat, message.id);
|
|
38325
|
+
await this.forgetGroupMessage(chat, message.id, message);
|
|
37754
38326
|
},
|
|
37755
38327
|
edge: (groupId, member) => {
|
|
37756
38328
|
const link = this.links.get(this.memberEdges(groupId).get(member) ?? "")?.link;
|
|
@@ -37761,9 +38333,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37761
38333
|
* A group's message deleted for everyone, by its author or by me: gone from this device with its file, and noted so a
|
|
37762
38334
|
* copy that comes again (a catch-up, a member handing it on) is not stored. The replies here that quote it lose its line.
|
|
37763
38335
|
*/
|
|
37764
|
-
async forgetGroupMessage(chat, id) {
|
|
37765
|
-
|
|
38336
|
+
async forgetGroupMessage(chat, id, row) {
|
|
38337
|
+
const groupId = chat.slice(6);
|
|
38338
|
+
const moved = row ?? (this.groups.movedMarks(groupId, id) ? await db.getMessage(chat, id) : void 0);
|
|
38339
|
+
await this.groups.removed(groupId, id);
|
|
37766
38340
|
await db.deleteMessage(chat, id);
|
|
38341
|
+
if (moved) await this.groups.unmark(groupId, moved);
|
|
37767
38342
|
this.quoteSweeps.add(chat, id, id);
|
|
37768
38343
|
await this.messagesChanged(chat, [id]);
|
|
37769
38344
|
this.emitState();
|
|
@@ -37783,11 +38358,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37783
38358
|
}
|
|
37784
38359
|
/** My key in an active group, and who is in it. */
|
|
37785
38360
|
membership(groupId) {
|
|
37786
|
-
|
|
37787
|
-
return group?.status === "active" && group.myKey ? {
|
|
37788
|
-
me: group.myKey,
|
|
37789
|
-
members: new Set(group.members.map((m) => m.key))
|
|
37790
|
-
} : void 0;
|
|
38361
|
+
return membershipOf(this.groups.view(groupId));
|
|
37791
38362
|
}
|
|
37792
38363
|
/** The link payments with `linkId` go over: a chat's or an edge's, or a community member's through the group. */
|
|
37793
38364
|
paymentLink(linkId) {
|
|
@@ -38153,13 +38724,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38153
38724
|
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
38154
38725
|
const note = latestReaction(messages);
|
|
38155
38726
|
if (note) this.reactionNotes.set(stored.id, note);
|
|
38156
|
-
if (stored.profile) await this.outboxFor(stored.id).recover();
|
|
38727
|
+
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
38157
38728
|
}
|
|
38158
38729
|
this.transfersRestored = true;
|
|
38159
|
-
for (const group of this.groups.views()) {
|
|
38160
|
-
const note = latestReaction(await db.getMessages(`group:${group.id}`));
|
|
38161
|
-
if (note) this.reactionNotes.set(`group:${group.id}`, note);
|
|
38162
|
-
}
|
|
38163
38730
|
this.publicProfiles.start();
|
|
38164
38731
|
await this.startLinks(links.map((stored) => stored.id), (linkId) => {
|
|
38165
38732
|
if (!this.links.get(linkId)?.stored.group) this.refreshPublicProfiles({ linkId }).catch(() => {});
|
|
@@ -38258,7 +38825,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38258
38825
|
return wrap((await store(STORES$1.settings, "readonly")).get(RESTORE_UNCHECKED_KEY)).catch(() => null);
|
|
38259
38826
|
}
|
|
38260
38827
|
async clearRestoreMark() {
|
|
38261
|
-
await
|
|
38828
|
+
await committed((await store(STORES$1.settings, "readwrite")).delete(RESTORE_UNCHECKED_KEY));
|
|
38262
38829
|
}
|
|
38263
38830
|
/**
|
|
38264
38831
|
* "Start it as a profile of its own" on a restored copy whose read found a tombstone (WISP 06 § A backup restored where
|
|
@@ -38321,7 +38888,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38321
38888
|
}
|
|
38322
38889
|
await this.groups.files?.sweep((await db.getGroups()).map((group) => group.id)).catch(() => {});
|
|
38323
38890
|
await this.leaveLimited(start.readAt ?? null).catch(() => {});
|
|
38324
|
-
if (!this.options.singleDevice && !this.limitedMode && this.networkOn && knownDeviceGate()?.state === "active") this.startDeviceSet().catch(() => {});
|
|
38891
|
+
if (!this.options.singleDevice && !this.limitedMode && this.networkOn && knownDeviceGate()?.state === "active") this.startDeviceSet({ justRead: start.readAt !== void 0 }).catch(() => {});
|
|
38325
38892
|
}
|
|
38326
38893
|
readTurnWhileLimited(after = 3e4) {
|
|
38327
38894
|
if (this.limitedTimer) clearTimeout(this.limitedTimer);
|
|
@@ -38341,7 +38908,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38341
38908
|
}
|
|
38342
38909
|
if (outcome && (outcome.kind === "start" || outcome.kind === "go-on" && !outcome.restricted)) {
|
|
38343
38910
|
await this.leaveLimited().catch(() => {});
|
|
38344
|
-
if (!this.limitedMode && this.networkOn) this.startDeviceSet().catch(() => {});
|
|
38911
|
+
if (!this.limitedMode && this.networkOn) this.startDeviceSet({ justRead: true }).catch(() => {});
|
|
38345
38912
|
return;
|
|
38346
38913
|
}
|
|
38347
38914
|
this.readTurnWhileLimited();
|
|
@@ -38630,7 +39197,6 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38630
39197
|
for (const queue of this.editQueues.values()) queue.stop();
|
|
38631
39198
|
for (const restore of this.cardRestores.values()) clearTimeout(restore.timer);
|
|
38632
39199
|
this.cardRestores.clear();
|
|
38633
|
-
this.quoteSweeps.stop();
|
|
38634
39200
|
this.groupEdits.stop();
|
|
38635
39201
|
this.reactions.stop();
|
|
38636
39202
|
this.cardEdits.stop();
|
|
@@ -38638,6 +39204,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38638
39204
|
linksStopped,
|
|
38639
39205
|
links?.stop(),
|
|
38640
39206
|
this.groups.flush(),
|
|
39207
|
+
this.quoteSweeps.stop(),
|
|
38641
39208
|
...WALLET_NETWORKS.flatMap((network) => [
|
|
38642
39209
|
this.arkWallets,
|
|
38643
39210
|
this.barkWallets,
|
|
@@ -38857,6 +39424,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38857
39424
|
async getMessages(linkId) {
|
|
38858
39425
|
return (await db.getMessages(linkId)).map(withoutFrame);
|
|
38859
39426
|
}
|
|
39427
|
+
/** The ids of the messages deleted in a chat (`deletedIds`, the newest `MAX_DELETED_IDS`): a whole history goes with them. */
|
|
39428
|
+
deletedIdsOf(linkId) {
|
|
39429
|
+
return this.links.get(linkId)?.stored.deletedIds ?? [];
|
|
39430
|
+
}
|
|
38860
39431
|
/** One message of a chat, read by its id: the whole history costs a read of every row. */
|
|
38861
39432
|
async getMessage(linkId, id) {
|
|
38862
39433
|
const message = await db.getMessage(linkId, id);
|
|
@@ -39750,10 +40321,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39750
40321
|
error: `Message too large for DHT (${bytes} bytes, max 500). Try a shorter message or share a link instead.`,
|
|
39751
40322
|
refused: true
|
|
39752
40323
|
};
|
|
39753
|
-
|
|
40324
|
+
const waitsForCheck = !!live && !live.link && this.limitedMode && !!live.stored.profile;
|
|
40325
|
+
if (live && !live.link && this.limitedMode && !live.stored.profile) return { error: LIMITED_MODE_ERROR };
|
|
40326
|
+
if (!live || !live.link && !waitsForCheck) return { error: "You are offline" };
|
|
39754
40327
|
if (!trimmed) return { error: null };
|
|
39755
40328
|
const timestamp = params.timestamp ?? arrivalKey(Date.now(), this.placedAt.get(linkId));
|
|
39756
|
-
if (live.stored.profile) live.link
|
|
40329
|
+
if (live.stored.profile) live.link?.setTyping(false);
|
|
39757
40330
|
if (live.stored.profile) {
|
|
39758
40331
|
const found = params.replyTo === void 0 ? void 0 : await this.replyFor(linkId, params.replyTo);
|
|
39759
40332
|
if (typeof found === "string") return {
|
|
@@ -39779,6 +40352,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39779
40352
|
error: "Replies need a current chat; this compatibility chat sends text only.",
|
|
39780
40353
|
refused: true
|
|
39781
40354
|
};
|
|
40355
|
+
if (!live.link) return { error: "You are offline" };
|
|
39782
40356
|
const via = live.link.isDataLinkOpen ? "datalink" : "pkarr";
|
|
39783
40357
|
await this.storeMessage({
|
|
39784
40358
|
linkId,
|
|
@@ -39822,7 +40396,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39822
40396
|
*/
|
|
39823
40397
|
async sendChatText(live, trimmed, timestamp, preview, reply, forwarded, card) {
|
|
39824
40398
|
const { link } = live, linkId = live.stored.id;
|
|
39825
|
-
if (!link) return { error: "You are offline" };
|
|
40399
|
+
if (!link && !this.limitedMode) return { error: "You are offline" };
|
|
39826
40400
|
this.chatInUse(live);
|
|
39827
40401
|
const bytes = new TextEncoder().encode(trimmed).length;
|
|
39828
40402
|
if (bytes > LIMITS.maxChatMessageBytes) return {
|
|
@@ -39835,6 +40409,32 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39835
40409
|
};
|
|
39836
40410
|
const stop = this.chatStopped(live);
|
|
39837
40411
|
if (stop) return { error: stop };
|
|
40412
|
+
const answers = {
|
|
40413
|
+
...reply && { replyTo: reply },
|
|
40414
|
+
...forwarded && { forwarded },
|
|
40415
|
+
...card && { card }
|
|
40416
|
+
};
|
|
40417
|
+
if (!link) {
|
|
40418
|
+
const id = `me_${toBase64Url(randomBytes(16))}`, wireId = id.slice(3), reason = "Sent once Ghostly can check which device is active.";
|
|
40419
|
+
await this.storeMessage({
|
|
40420
|
+
linkId,
|
|
40421
|
+
id,
|
|
40422
|
+
wireId,
|
|
40423
|
+
text: trimmed,
|
|
40424
|
+
sender: "me",
|
|
40425
|
+
timestamp,
|
|
40426
|
+
via: "datalink",
|
|
40427
|
+
delivery: "waiting",
|
|
40428
|
+
deliveryError: reason,
|
|
40429
|
+
...preview && { preview },
|
|
40430
|
+
...answers
|
|
40431
|
+
});
|
|
40432
|
+
await this.outboxFor(linkId).wait(id, reason);
|
|
40433
|
+
return {
|
|
40434
|
+
error: null,
|
|
40435
|
+
messageId: id
|
|
40436
|
+
};
|
|
40437
|
+
}
|
|
39838
40438
|
if (!link.isDataLinkOpen && link.dhtDelivery?.inviteTaken) return {
|
|
39839
40439
|
error: INVITE_TAKEN,
|
|
39840
40440
|
refused: true
|
|
@@ -39842,11 +40442,6 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39842
40442
|
const wireId = toBase64Url(randomBytes(16)), id = `me_${wireId}`;
|
|
39843
40443
|
const delivery = link.isDataLinkOpen ? "stream" : link.textDelivery === "dht" ? "dht" : "unavailable";
|
|
39844
40444
|
if (delivery !== "stream") this.wakePeer(live);
|
|
39845
|
-
const answers = {
|
|
39846
|
-
...reply && { replyTo: reply },
|
|
39847
|
-
...forwarded && { forwarded },
|
|
39848
|
-
...card && { card }
|
|
39849
|
-
};
|
|
39850
40445
|
if (delivery === "stream" || delivery === "dht" && bytes <= 256) {
|
|
39851
40446
|
const validationError = link.validateText(trimmed, timestamp, wireId, reply && pairedWireReply(reply));
|
|
39852
40447
|
if (!validationError) {
|
|
@@ -39922,14 +40517,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39922
40517
|
* The message of a chat a reply answers, by its id here or the id both sides know it by (`replyRef`): what the
|
|
39923
40518
|
* reply keeps of it, or why there is nothing to reply to. A group's reply needs the author's member key too.
|
|
39924
40519
|
* Read alone by its id, or a chat's `peer_`/`me_` row for a wire id, as `resolveReply` does: a group's message goes
|
|
39925
|
-
* by its row's id, so a miss there is not here; a chat's
|
|
39926
|
-
* whole chat.
|
|
40520
|
+
* by its row's id, so a miss there is not here; a chat's file of mine or payment is read alone by its time
|
|
40521
|
+
* (`rowsNamed`), and any other row is looked for in the whole chat.
|
|
39927
40522
|
*/
|
|
39928
40523
|
async replyFor(linkId, messageId) {
|
|
39929
40524
|
if (typeof messageId !== "string" || !messageId) return "No message to reply to";
|
|
39930
40525
|
const group = linkId.startsWith("group:");
|
|
39931
40526
|
let original = await db.getMessage(linkId, messageId);
|
|
39932
|
-
for (const rowId of group ? [] : [
|
|
40527
|
+
for (const rowId of group || original ? [] : [
|
|
40528
|
+
`peer_${messageId}`,
|
|
40529
|
+
`me_${messageId}`,
|
|
40530
|
+
...await this.rowsNamed(linkId, messageId)
|
|
40531
|
+
]) {
|
|
39933
40532
|
if (original) break;
|
|
39934
40533
|
const row = await db.getMessage(linkId, rowId);
|
|
39935
40534
|
if (row && replyRef(row) === messageId) original = row;
|
|
@@ -39945,14 +40544,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39945
40544
|
* here gives the line and the author (and it is then checked); one not found keeps what the wire said, unchecked.
|
|
39946
40545
|
* The original is read alone where its id says its row (a group's message id, a chat's `peer_`/`me_` text): a reply
|
|
39947
40546
|
* costs what a plain message does, however long the chat. A group's row goes by its own id only, so a miss there is
|
|
39948
|
-
* not here; a chat's
|
|
40547
|
+
* not here; a chat's file of mine or payment is read alone by its time (`rowsNamed`), and any other row is looked
|
|
40548
|
+
* for in the whole chat.
|
|
39949
40549
|
*/
|
|
39950
40550
|
async resolveReply(message) {
|
|
39951
40551
|
const reply = message.replyTo;
|
|
39952
40552
|
if (!reply || reply.messageId) return message;
|
|
39953
40553
|
const group = message.linkId.startsWith("group:");
|
|
39954
40554
|
let original, history;
|
|
39955
|
-
for (const rowId of group ? [reply.id] : [
|
|
40555
|
+
for (const rowId of group ? [reply.id] : [
|
|
40556
|
+
`peer_${reply.id}`,
|
|
40557
|
+
`me_${reply.id}`,
|
|
40558
|
+
...await this.rowsNamed(message.linkId, reply.id)
|
|
40559
|
+
]) {
|
|
39956
40560
|
const row = rowId === message.id ? void 0 : await db.getMessage(message.linkId, rowId);
|
|
39957
40561
|
if (row && replyRef(row, group) === reply.id) {
|
|
39958
40562
|
original = row;
|
|
@@ -39973,12 +40577,42 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39973
40577
|
}
|
|
39974
40578
|
};
|
|
39975
40579
|
const pressed = buttonPress(resolved, original, []);
|
|
39976
|
-
const press = pressed && messageButtons(original)?.buttons.some((b) => b.once) ?
|
|
40580
|
+
const press = pressed && messageButtons(original)?.buttons.some((b) => b.once) ? await this.oncePress(resolved, original, history) : pressed;
|
|
39977
40581
|
return press ? {
|
|
39978
40582
|
...resolved,
|
|
39979
40583
|
press
|
|
39980
40584
|
} : resolved;
|
|
39981
40585
|
}
|
|
40586
|
+
/**
|
|
40587
|
+
* A press on a message of mine with a `once` button: refused when this member's earlier press of it with a `once`
|
|
40588
|
+
* button is still here. The history is read at the message's first press only (`cardPresses`); after that, a press
|
|
40589
|
+
* reads that member's earlier presses of it alone, and none when there are none. 255 presses handed back at once
|
|
40590
|
+
* in a 10k-message group read the history 255 times, 15.7 s on the CLI's store, before.
|
|
40591
|
+
*/
|
|
40592
|
+
async oncePress(reply, original, history) {
|
|
40593
|
+
const key = `${reply.linkId}\n${original.id}`;
|
|
40594
|
+
let presses = this.cardPresses.get(key);
|
|
40595
|
+
if (!presses) {
|
|
40596
|
+
const read = /* @__PURE__ */ new Map();
|
|
40597
|
+
for (const row of history ?? await db.getMessages(reply.linkId)) {
|
|
40598
|
+
if (row.sender !== "peer" || row.press?.messageId !== original.id) continue;
|
|
40599
|
+
read.set(row.member ?? "", [...read.get(row.member ?? "") ?? [], {
|
|
40600
|
+
id: row.id,
|
|
40601
|
+
button: row.press.button
|
|
40602
|
+
}]);
|
|
40603
|
+
}
|
|
40604
|
+
presses = this.cardPresses.get(key) ?? read;
|
|
40605
|
+
this.cardPresses.set(key, presses);
|
|
40606
|
+
}
|
|
40607
|
+
const member = reply.member ?? "", card = messageButtons(original);
|
|
40608
|
+
const earlier = (presses.get(member) ?? []).filter((p) => p.id !== reply.id && card?.buttons.find((b) => b.id === p.button)?.once).map((p) => p.id);
|
|
40609
|
+
const press = buttonPress(reply, original, (await db.getMessagesById(reply.linkId, earlier)).filter((row) => !!row));
|
|
40610
|
+
if (press) presses.set(member, [...(presses.get(member) ?? []).filter((p) => p.id !== reply.id), {
|
|
40611
|
+
id: reply.id,
|
|
40612
|
+
button: press.button
|
|
40613
|
+
}]);
|
|
40614
|
+
return press;
|
|
40615
|
+
}
|
|
39982
40616
|
/** A paired row's reply as it goes on the wire again (a resend, a hold). */
|
|
39983
40617
|
/** `localStorage["ghostly-test-no-edit"]`: this app offers no edit/1, as an older one (the e2e's old contact). Nothing else reads it. */
|
|
39984
40618
|
static testNoEdit() {
|
|
@@ -40102,6 +40736,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40102
40736
|
}
|
|
40103
40737
|
if (edit.rm) {
|
|
40104
40738
|
const message = await db.getMessage(linkId, id);
|
|
40739
|
+
if (!message && PAYMENT_LINE_ID.test(edit.id)) return true;
|
|
40105
40740
|
if (!message || canRemove(message)) await this.forgetMessage(linkId, id, true);
|
|
40106
40741
|
return true;
|
|
40107
40742
|
}
|
|
@@ -40285,7 +40920,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40285
40920
|
...live.stored,
|
|
40286
40921
|
removals: live.stored.removals.filter((r) => r.id !== messageId)
|
|
40287
40922
|
};
|
|
40288
|
-
await
|
|
40923
|
+
await this.writeDeletions(linkId, { removals: live.stored.removals }, true);
|
|
40289
40924
|
return;
|
|
40290
40925
|
}
|
|
40291
40926
|
if (await db.patchMessage(linkId, messageId, (current) => {
|
|
@@ -40698,13 +41333,50 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40698
41333
|
...live.stored,
|
|
40699
41334
|
removals: withRemoval(live.stored.removals, removal)
|
|
40700
41335
|
};
|
|
40701
|
-
|
|
40702
|
-
|
|
41336
|
+
const written = this.writeDeletions(linkId, { removals: live.stored.removals });
|
|
41337
|
+
const forgot = this.forgetMessage(linkId, messageId, true);
|
|
41338
|
+
await written;
|
|
41339
|
+
await forgot;
|
|
40703
41340
|
const edits = this.editsFor(linkId);
|
|
40704
41341
|
edits.edited(messageId);
|
|
40705
41342
|
edits.flush().catch(() => {});
|
|
40706
41343
|
return { error: null };
|
|
40707
41344
|
}
|
|
41345
|
+
/** A chat's row write of its removals and deleted ids waiting to go, by chat (`writeDeletions`). */
|
|
41346
|
+
deletionWrites = /* @__PURE__ */ new Map();
|
|
41347
|
+
/** The last such write of each chat, which the next one follows. */
|
|
41348
|
+
deletionTail = /* @__PURE__ */ new Map();
|
|
41349
|
+
/**
|
|
41350
|
+
* Writes a chat's `removals` and `deletedIds` to its row, merged with any other change of them not written yet: one
|
|
41351
|
+
* write of the row for what a burst changed, not one per change. The row carries up to 500 removals on their way and
|
|
41352
|
+
* the last 500 deleted ids, rewritten whole each time: a CLI daemon deleting 300 messages for everyone wrote 19.5 MB of
|
|
41353
|
+
* journal and synced it 1,207 times, a removal and its id written apart, then each receipt again (agents#1572). The
|
|
41354
|
+
* values are `live.stored`'s at the time of the call, so the newest of each field wins. `relaxed` (no disk sync of its
|
|
41355
|
+
* own, `db.patchLink`) holds only while every change merged into the write is.
|
|
41356
|
+
*/
|
|
41357
|
+
writeDeletions(linkId, patch, relaxed = false) {
|
|
41358
|
+
const waiting = this.deletionWrites.get(linkId);
|
|
41359
|
+
if (waiting) {
|
|
41360
|
+
Object.assign(waiting.patch, patch);
|
|
41361
|
+
waiting.relaxed &&= relaxed;
|
|
41362
|
+
return waiting.done;
|
|
41363
|
+
}
|
|
41364
|
+
const entry = {
|
|
41365
|
+
patch: { ...patch },
|
|
41366
|
+
relaxed,
|
|
41367
|
+
done: Promise.resolve()
|
|
41368
|
+
};
|
|
41369
|
+
this.deletionWrites.set(linkId, entry);
|
|
41370
|
+
entry.done = (this.deletionTail.get(linkId) ?? Promise.resolve()).catch(() => {}).then(() => {
|
|
41371
|
+
this.deletionWrites.delete(linkId);
|
|
41372
|
+
return db.patchLink(linkId, entry.patch, entry.relaxed);
|
|
41373
|
+
});
|
|
41374
|
+
this.deletionTail.set(linkId, entry.done);
|
|
41375
|
+
entry.done.catch(() => {}).then(() => {
|
|
41376
|
+
if (this.deletionTail.get(linkId) === entry.done) this.deletionTail.delete(linkId);
|
|
41377
|
+
});
|
|
41378
|
+
return entry.done;
|
|
41379
|
+
}
|
|
40708
41380
|
/**
|
|
40709
41381
|
* Forgets one message of a chat on this device, the bytes of its file and any transfer of it, and keeps its id so a
|
|
40710
41382
|
* copy that comes again is not stored: a delete here, or the contact's own removal (WISP 400 § Delete for everyone),
|
|
@@ -40717,7 +41389,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40717
41389
|
...live.stored,
|
|
40718
41390
|
deletedIds: [...live.stored.deletedIds ?? [], messageId].slice(-500)
|
|
40719
41391
|
};
|
|
40720
|
-
|
|
41392
|
+
this.writeDeletions(linkId, { deletedIds: live.stored.deletedIds }).catch(() => {});
|
|
40721
41393
|
this.hold.forget(linkId, messageId).catch(() => {});
|
|
40722
41394
|
const message = await db.getMessage(linkId, messageId);
|
|
40723
41395
|
if (message?.paymentId && message.delivery === "waiting") await this.desk.withdraw(message.paymentId).catch(() => {});
|
|
@@ -41592,7 +42264,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41592
42264
|
if (!this.links.get(linkId)?.stored.profile || this.links.get(linkId)?.stored.group) throw new Error("Invite a paired contact");
|
|
41593
42265
|
return this.groups.invite(groupId, linkId);
|
|
41594
42266
|
}
|
|
41595
|
-
|
|
42267
|
+
/** Offline, every chat's link is down: said as this app's state, not as the inviter's (who may well be online). */
|
|
42268
|
+
async acceptGroupInvitation({ groupId }) {
|
|
42269
|
+
if (!this.networkOn) throw new Error("Go online to join a group");
|
|
41596
42270
|
return this.groups.accept(groupId);
|
|
41597
42271
|
}
|
|
41598
42272
|
declineGroupInvitation({ groupId }) {
|
|
@@ -41765,7 +42439,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41765
42439
|
if (ids.length > 30) throw new Error(`Forward at most 30 messages at once`);
|
|
41766
42440
|
if (!targets.length) throw new Error("No chat to forward to");
|
|
41767
42441
|
if (targets.length > 5) throw new Error(`Forward to at most 5 chats at once`);
|
|
41768
|
-
if (linkId.startsWith("group:") ? !this.groups.
|
|
42442
|
+
if (linkId.startsWith("group:") ? !this.groups.view(linkId.slice(6)) : this.links.get(linkId)?.stored.group !== void 0 || !this.links.has(linkId)) throw new Error("Chat not found");
|
|
41769
42443
|
const chosen = await Promise.all(ids.map((id) => db.getMessage(linkId, id)));
|
|
41770
42444
|
if (chosen.some((m) => !m)) throw new Error("That message is not in this chat");
|
|
41771
42445
|
const messages = chosen.sort((a, b) => a.timestamp - b.timestamp);
|
|
@@ -41797,7 +42471,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41797
42471
|
const hops = forwardedAgain(message.forwarded);
|
|
41798
42472
|
try {
|
|
41799
42473
|
if (forwardKind(message) === "text") {
|
|
41800
|
-
const sent = groupId ? await this.groups.send(groupId, message.text, [], void 0, hops) : !live.link ? { error: "You are offline" } : live.stored.profile ? await this.sendChatText(live, message.text.trim(), now(), message.preview, void 0, hops) : await this.sendMessage({
|
|
42474
|
+
const sent = groupId ? await this.groups.send(groupId, message.text, [], void 0, hops) : !live.link && !(this.limitedMode && live.stored.profile) ? { error: this.limitedMode ? LIMITED_MODE_ERROR : "You are offline" } : live.stored.profile ? await this.sendChatText(live, message.text.trim(), now(), message.preview, void 0, hops) : await this.sendMessage({
|
|
41801
42475
|
linkId: to,
|
|
41802
42476
|
text: message.text,
|
|
41803
42477
|
timestamp: now()
|
|
@@ -41899,7 +42573,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41899
42573
|
if (linkId.startsWith("group:")) {
|
|
41900
42574
|
const groupId = linkId.slice(6);
|
|
41901
42575
|
if (!this.membership(groupId)) return {
|
|
41902
|
-
error: this.groups.
|
|
42576
|
+
error: this.groups.view(groupId)?.statusReason ?? "You are not in this group",
|
|
41903
42577
|
refused: true
|
|
41904
42578
|
};
|
|
41905
42579
|
const result = await this.reactions.mine(linkId, messageId, emoji);
|
|
@@ -42053,12 +42727,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42053
42727
|
*/
|
|
42054
42728
|
async pinMessage({ linkId, messageId, remove }) {
|
|
42055
42729
|
if (typeof linkId !== "string" || !linkId) return { error: "No chat to pin in" };
|
|
42056
|
-
const host =
|
|
42057
|
-
messages: (chat) => db.getMessages(chat),
|
|
42058
|
-
message: (chat, id) => db.getMessage(chat, id)
|
|
42059
|
-
};
|
|
42730
|
+
const host = this.pinsHost;
|
|
42060
42731
|
if (linkId.startsWith("group:")) {
|
|
42061
|
-
const groupId = linkId.slice(6), view = this.groups.
|
|
42732
|
+
const groupId = linkId.slice(6), view = this.groups.view(groupId);
|
|
42062
42733
|
if (!view || view.status !== "active") return { error: "You are not in this group" };
|
|
42063
42734
|
if (!mayPinIn(view)) return { error: "Only the admin pins in a community" };
|
|
42064
42735
|
const pin = await myPin(host, linkId, messageId, !!remove, this.groups.pinOf(groupId));
|
|
@@ -42170,6 +42841,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42170
42841
|
* ask again while the page still reads the first ask, whose answer must not go out as the second's.
|
|
42171
42842
|
*/
|
|
42172
42843
|
appRangeAsked(linkId, task) {
|
|
42844
|
+
const link = this.links.get(linkId)?.link;
|
|
42845
|
+
for (const [key, held] of this.appRanges) if (key.startsWith(`${linkId} `) && (!link || !link.holdsAppRange(held))) this.appRanges.delete(key);
|
|
42173
42846
|
const request = ++this.nextAppRangeAsk;
|
|
42174
42847
|
this.appRanges.set(`${linkId} ${task.app} ${request}`, task);
|
|
42175
42848
|
const { app, serve, file, offset, length } = task;
|
|
@@ -42182,29 +42855,49 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42182
42855
|
length
|
|
42183
42856
|
});
|
|
42184
42857
|
}
|
|
42858
|
+
/** The app reference and running version behind each chat app id that served a file, by chat: what an answer is checked against. */
|
|
42859
|
+
appServing = /* @__PURE__ */ new Map();
|
|
42185
42860
|
/** Lets the contact's app read `file`, one of this side's linked files, while both have the app open on this session. */
|
|
42186
|
-
appServe({ linkId, ref, file }) {
|
|
42861
|
+
async appServe({ linkId, ref, file, digest }) {
|
|
42187
42862
|
const { live, app } = this.appChat(linkId, ref);
|
|
42188
42863
|
if (typeof file !== "string" || !file) throw new Error("Not a file");
|
|
42189
|
-
|
|
42864
|
+
await this.appChatRunnable(ref, digest);
|
|
42865
|
+
if (!live.link) return { error: "offline" };
|
|
42866
|
+
const served = live.link.serveAppFile(app, file);
|
|
42867
|
+
if ("serve" in served) this.appServing.set(`${linkId} ${app}`, {
|
|
42868
|
+
ref,
|
|
42869
|
+
...digest !== void 0 && { digest }
|
|
42870
|
+
});
|
|
42871
|
+
return served;
|
|
42190
42872
|
}
|
|
42191
42873
|
appUnserve({ linkId, serve }) {
|
|
42192
42874
|
if (!this.appsOn) throw this.appsOff();
|
|
42193
42875
|
this.links.get(linkId)?.link?.unserveAppFile(serve);
|
|
42194
42876
|
}
|
|
42195
42877
|
/** A page's answer to an `app-range` it served: the bytes and the file's size go to the contact, or why they cannot. */
|
|
42196
|
-
appRangeAnswer({ linkId, app, request, bytes, size, error }) {
|
|
42878
|
+
async appRangeAnswer({ linkId, app, request, bytes, size, error }) {
|
|
42197
42879
|
if (!this.appsOn) throw this.appsOff();
|
|
42198
|
-
const key = `${linkId} ${app} ${request}`, task = this.appRanges.get(key)
|
|
42880
|
+
const key = `${linkId} ${app} ${request}`, task = this.appRanges.get(key);
|
|
42199
42881
|
this.appRanges.delete(key);
|
|
42200
|
-
if (!task
|
|
42882
|
+
if (!task) return;
|
|
42883
|
+
const serving = this.appServing.get(`${linkId} ${app}`);
|
|
42884
|
+
const stopped = serving && await this.appChatRunnable(serving.ref, serving.digest).then(() => false, () => true);
|
|
42885
|
+
const link = this.links.get(linkId)?.link;
|
|
42886
|
+
if (!link) return;
|
|
42887
|
+
if (stopped) {
|
|
42888
|
+
link.failAppRange(task, "gone");
|
|
42889
|
+
for (const serve of link.appServes(app)) link.unserveAppFile(serve);
|
|
42890
|
+
this.appServing.delete(`${linkId} ${app}`);
|
|
42891
|
+
return;
|
|
42892
|
+
}
|
|
42201
42893
|
if (error === "changed" || error === "gone") return link.failAppRange(task, error);
|
|
42202
42894
|
if (!(bytes instanceof Uint8Array) || typeof size !== "number" || !Number.isSafeInteger(size) || size < 0) return link.failAppRange(task, "gone");
|
|
42203
42895
|
link.sendAppRange(task, bytes, size);
|
|
42204
42896
|
}
|
|
42205
42897
|
/** Reads a range of what the contact's app serves in this chat, or why not. */
|
|
42206
|
-
async appRemoteRead({ linkId, ref, serve, offset, length }) {
|
|
42898
|
+
async appRemoteRead({ linkId, ref, serve, offset, length, digest }) {
|
|
42207
42899
|
const { live, app } = this.appChat(linkId, ref);
|
|
42900
|
+
await this.appChatRunnable(ref, digest);
|
|
42208
42901
|
if (!live.link) return { error: "offline" };
|
|
42209
42902
|
if (!isServeId(serve)) return { error: "not-served" };
|
|
42210
42903
|
if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || length < 1 || length > APP_RANGE_LIMITS.requestBytes || !Number.isSafeInteger(offset + length)) throw new Error("Not a range");
|
|
@@ -42270,10 +42963,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42270
42963
|
}
|
|
42271
42964
|
/** A pin that came, as it is kept: who pinned, and its row when it is here. */
|
|
42272
42965
|
async pinCame(chat, by, pin) {
|
|
42273
|
-
const row = await pinnedRow(
|
|
42274
|
-
messages: (c) => db.getMessages(c),
|
|
42275
|
-
message: (c, id) => db.getMessage(c, id)
|
|
42276
|
-
}, chat, pin.id);
|
|
42966
|
+
const row = await pinnedRow(this.pinsHost, chat, pin.id);
|
|
42277
42967
|
return {
|
|
42278
42968
|
id: pin.id,
|
|
42279
42969
|
n: pin.n,
|
|
@@ -42288,7 +42978,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42288
42978
|
* other edges, so members with no edge to the pinner get it.
|
|
42289
42979
|
*/
|
|
42290
42980
|
async receiveGroupPin(groupId, member, pin, via) {
|
|
42291
|
-
const view = this.groups.
|
|
42981
|
+
const view = this.groups.view(groupId);
|
|
42292
42982
|
if (!pin || !view?.myKey || view.status !== "active" || !view.members.some((m) => m.key === member)) return;
|
|
42293
42983
|
if (!mayPin(view.profile, member, view.members.find((m) => m.role === "admin")?.key)) return;
|
|
42294
42984
|
if (!pinIsNewer(this.groups.pinOf(groupId), pin)) return;
|
|
@@ -43260,7 +43950,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43260
43950
|
}
|
|
43261
43951
|
/** A request any member of a group may pay, once (WISP 902 § Payments). */
|
|
43262
43952
|
requestGroupPayment(params) {
|
|
43263
|
-
const group = this.groups.
|
|
43953
|
+
const group = this.groups.view(params.groupId);
|
|
43264
43954
|
if (group?.status !== "active") throw new Error("You are not in this group");
|
|
43265
43955
|
if (group.members.length < 2) throw new Error("Nobody else is in the group yet");
|
|
43266
43956
|
return this.desk.requestFromGroup({
|
|
@@ -43562,7 +44252,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43562
44252
|
const next = new Set(this.groupAdminOff);
|
|
43563
44253
|
if (on) next.delete(groupId);
|
|
43564
44254
|
else next.add(groupId);
|
|
43565
|
-
await
|
|
44255
|
+
await committed((await store(STORES$1.settings, "readwrite")).put({
|
|
43566
44256
|
at: Date.now(),
|
|
43567
44257
|
groups: [...next].sort()
|
|
43568
44258
|
}, GROUP_ADMIN_OFF_KEY));
|
|
@@ -43638,9 +44328,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43638
44328
|
/**
|
|
43639
44329
|
* The active device's links to the other devices, and its stored turn record put again (WISP 06 § Publishing and
|
|
43640
44330
|
* reading: "The active device puts its stored bytes at start"). This is also what completes an enrollment that a
|
|
43641
|
-
* crash stopped after the record with the new device was stored and before it was put.
|
|
44331
|
+
* crash stopped after the record with the new device was stored and before it was put. `justRead`: it starts on a good
|
|
44332
|
+
* turn read made a moment before (the read at start, or limited mode's), which counts while it is fresh.
|
|
43642
44333
|
*/
|
|
43643
|
-
async startDeviceSet() {
|
|
44334
|
+
async startDeviceSet({ justRead = false } = {}) {
|
|
43644
44335
|
if (this.shuttingDown) return;
|
|
43645
44336
|
const own = await readDeviceRecord(databaseName()).catch(() => null);
|
|
43646
44337
|
this.ownDeviceKey = own?.ownSlot !== void 0 ? own.deviceSet[own.ownSlot]?.key ?? null : null;
|
|
@@ -43671,15 +44362,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43671
44362
|
await recoverEnrollment(databaseName(), this.turnNetwork()).catch(() => false);
|
|
43672
44363
|
await this.syncDeviceVerifier().catch(() => {});
|
|
43673
44364
|
const keeper = await this.deviceLinks.turnKeeper();
|
|
43674
|
-
|
|
43675
|
-
|
|
43676
|
-
|
|
43677
|
-
|
|
43678
|
-
|
|
43679
|
-
|
|
43680
|
-
|
|
43681
|
-
if (
|
|
43682
|
-
|
|
44365
|
+
if (justRead && this.turnFresh()) await keeper?.stateVerifier().catch(() => null);
|
|
44366
|
+
else {
|
|
44367
|
+
const outcome = await keeper?.check(false);
|
|
44368
|
+
if (outcome?.kind === "go-on" && !outcome.restricted) {
|
|
44369
|
+
this.noteGoodTurn();
|
|
44370
|
+
await keeper?.stateVerifier().catch(() => null);
|
|
44371
|
+
}
|
|
44372
|
+
if (outcome?.kind === "gated" && !this.shuttingDown) {
|
|
44373
|
+
const record = await readDeviceRecord(databaseName());
|
|
44374
|
+
if (record) await this.stopReplaced(viewOf(record));
|
|
44375
|
+
return;
|
|
44376
|
+
}
|
|
43683
44377
|
}
|
|
43684
44378
|
this.watchActiveTurn();
|
|
43685
44379
|
this.watchTombstones();
|
|
@@ -44042,7 +44736,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44042
44736
|
}
|
|
44043
44737
|
try {
|
|
44044
44738
|
const verifier = await makeHandoffVerifier(password);
|
|
44045
|
-
await
|
|
44739
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(verifier, GhostlyNode.HANDOFF_VERIFIER));
|
|
44046
44740
|
await this.syncDeviceVerifier().catch(() => {});
|
|
44047
44741
|
await this.stateDeviceVerifier();
|
|
44048
44742
|
} catch (error) {
|
|
@@ -44052,7 +44746,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44052
44746
|
}
|
|
44053
44747
|
/** The profile has no verifier any more: its settings, the device state, and what the turn record states. */
|
|
44054
44748
|
async dropHandoffVerifier() {
|
|
44055
|
-
await
|
|
44749
|
+
await committed((await store(STORES$1.settings, "readwrite")).delete(GhostlyNode.HANDOFF_VERIFIER)).catch(() => {});
|
|
44056
44750
|
await this.syncDeviceVerifier().catch(() => {});
|
|
44057
44751
|
await this.stateDeviceVerifier();
|
|
44058
44752
|
}
|
|
@@ -44430,7 +45124,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44430
45124
|
throw error;
|
|
44431
45125
|
}
|
|
44432
45126
|
if (this.networkOn) this.startLink(id);
|
|
44433
|
-
if (expectPeer) this.links.get(id)?.link?.expectPeer();
|
|
45127
|
+
if (expectPeer) this.links.get(id)?.link?.expectPeer(true);
|
|
44434
45128
|
return id;
|
|
44435
45129
|
}
|
|
44436
45130
|
/**
|
|
@@ -44800,6 +45494,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44800
45494
|
} : void 0;
|
|
44801
45495
|
const resumed = stored.pairedPeerKey && stored.deliveryMode !== "dht" ? resumeHere(this.transportLogOf(live), this.transportsHere(), stored.peerTransports ?? live.caps?.peer?.transports) : {};
|
|
44802
45496
|
let dhtShown;
|
|
45497
|
+
let dhtFlushed;
|
|
44803
45498
|
let wasTaken = false;
|
|
44804
45499
|
live.link = new GhostLink({
|
|
44805
45500
|
paymentMethods: stored.paymentMethods,
|
|
@@ -44891,6 +45586,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44891
45586
|
throw error;
|
|
44892
45587
|
}
|
|
44893
45588
|
if (!previous.pairedPeerKey) {
|
|
45589
|
+
if (!live.stored.group) live.pairedAt = Date.now();
|
|
44894
45590
|
if (!live.stored.group && live.stored.deliveryMode !== "dht") this.ensureNativeEndpoints(stored.id);
|
|
44895
45591
|
live.caps?.update().catch(() => {});
|
|
44896
45592
|
live.caps?.refresh(true);
|
|
@@ -44929,7 +45625,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44929
45625
|
onGroupFrame: stored.profile ? (frame) => this.groups.handleContactFrame(linkId, frame) : void 0,
|
|
44930
45626
|
onGroupsSupport: () => this.emitState(),
|
|
44931
45627
|
onDhtDelivery: (view) => {
|
|
44932
|
-
|
|
45628
|
+
const viewed = JSON.stringify(view);
|
|
45629
|
+
if (stored.profile && !stored.group && viewed !== dhtFlushed) {
|
|
45630
|
+
dhtFlushed = viewed;
|
|
45631
|
+
this.outboxes.get(linkId)?.flush().catch(() => {}).then(() => this.editQueues.get(linkId)?.flush()).catch(() => {});
|
|
45632
|
+
}
|
|
44933
45633
|
this.observeTransport(linkId);
|
|
44934
45634
|
const taken = !!live.link?.takenFromUs;
|
|
44935
45635
|
if (taken !== wasTaken) {
|
|
@@ -45058,6 +45758,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45058
45758
|
const was = live.dataLink;
|
|
45059
45759
|
live.dataLink = state;
|
|
45060
45760
|
if (state === "open") {
|
|
45761
|
+
live.pairedAt = void 0;
|
|
45061
45762
|
this.wakeLimiter.reset(linkId);
|
|
45062
45763
|
this.desk.replay(linkId).catch(() => {}).then(() => this.sendWaiting(linkId)).catch(() => {});
|
|
45063
45764
|
this.identities.ready(linkId);
|
|
@@ -45304,7 +46005,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45304
46005
|
get nativeFactories() {
|
|
45305
46006
|
const relay = this.relaysHyperdht ? this.hyperdhtRelay : "";
|
|
45306
46007
|
return {
|
|
45307
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
46008
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-BcrwJRtb.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
45308
46009
|
...this.options.nativeTransports,
|
|
45309
46010
|
...this.ownIrohRelays ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
45310
46011
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
|
|
@@ -45452,20 +46153,23 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45452
46153
|
}
|
|
45453
46154
|
anchorCheckAt = 0;
|
|
45454
46155
|
/**
|
|
45455
|
-
* A group's edge whose native listener has been up `GROUP_ANCHOR_ANSWER_MS` with no session, and whose member
|
|
45456
|
-
*
|
|
46156
|
+
* A group's edge whose native listener has been up `GROUP_ANCHOR_ANSWER_MS` with no session, and whose member is there
|
|
46157
|
+
* and says in its packet it holds none for it: nobody answers it. Not one whose member is away: no other edge would
|
|
46158
|
+
* be answered either, and the one passed over gave its listener up and asked for none again once its member came
|
|
46159
|
+
* back, whose texts then came only through another member (a hub with no WebRTC, 2026-10-20); nor did passing stop
|
|
46160
|
+
* while every member was away, a listener moving from edge to edge every few minutes for nothing.
|
|
45457
46161
|
*/
|
|
45458
46162
|
unanswered(live, now) {
|
|
45459
46163
|
const link = live.link;
|
|
45460
|
-
if (!link || link.isDataLinkOpen) return false;
|
|
46164
|
+
if (!link || link.isDataLinkOpen || !live.presence.online) return false;
|
|
45461
46165
|
const up = Object.keys(this.nativeFactories).filter((t) => link.availableTransports.includes(t)).map((t) => live.nativeUpAt?.[t] ?? now);
|
|
45462
46166
|
if (!up.length || now - Math.min(...up) < 2e4) return false;
|
|
45463
|
-
return !this.chosenByPeer(live)
|
|
46167
|
+
return !this.chosenByPeer(live);
|
|
45464
46168
|
}
|
|
45465
46169
|
/**
|
|
45466
46170
|
* Every few seconds, each group not on screen whose edges run native transports: the one edge it keeps has a
|
|
45467
46171
|
* listener (or waits for one, `groupNativeWaiting`), and when its member has not answered it in
|
|
45468
|
-
* `GROUP_ANCHOR_ANSWER_MS` (it is
|
|
46172
|
+
* `GROUP_ANCHOR_ANSWER_MS` (it is there with no listener for it: all its own taken), the group keeps the next
|
|
45469
46173
|
* one instead (hub, then admin, then the member heard from last), whose member answers the edge it keeps
|
|
45470
46174
|
* (`chosenByPeer`). Not while any edge of the group is live: the group is reachable through it. Every other one passed
|
|
45471
46175
|
* over lately too: the one it keeps stays, without its listener going back and forth.
|
|
@@ -45550,6 +46254,17 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45550
46254
|
return this.nativeSlots(key) - CHAT_NATIVE_SLOTS;
|
|
45551
46255
|
}
|
|
45552
46256
|
/**
|
|
46257
|
+
* The links its groups may have on an app with no WebRTC (`peerRoom`): the transport's listeners that 1:1 chats do
|
|
46258
|
+
* not hold, and what is kept for groups (`groupNativeSlots`) at least. Capped at that alone, a Desktop with no chats
|
|
46259
|
+
* opened four edges in a private group of seven, and the two members left out were never reached, even on screen
|
|
46260
|
+
* with half its listeners free: an edge of the group on screen takes a free listener, or a held one (WISP 902 § Transports).
|
|
46261
|
+
*/
|
|
46262
|
+
groupNativeRoom(key) {
|
|
46263
|
+
let chats = 0;
|
|
46264
|
+
for (const live of this.links.values()) if (!live.stored.group && live.link?.availableTransports.includes(key)) chats++;
|
|
46265
|
+
return Math.max(this.groupNativeSlots(key), this.nativeSlots(key) - chats);
|
|
46266
|
+
}
|
|
46267
|
+
/**
|
|
45553
46268
|
* One transport's listener for one chat, in that transport's queue. "no-slot" when a group's link found no slot free,
|
|
45554
46269
|
* "failed" when the listener could not start.
|
|
45555
46270
|
*/
|
|
@@ -45580,8 +46295,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45580
46295
|
const full = owners.length >= slots, entry = !!live.stored.groupEntry;
|
|
45581
46296
|
if (group && (entry || extra(live)) && (full || groups >= this.groupNativeSlots(key) || !entry && !anchorOf(live.stored.group)?.link?.availableTransports.includes(key))) return "no-slot";
|
|
45582
46297
|
if (full || !group && owners.length - groups >= NATIVE_SLOTS) {
|
|
45583
|
-
const
|
|
45584
|
-
const
|
|
46298
|
+
const paired = !group && live.pairedAt !== void 0 && now - live.pairedAt < 6e5 ? live.pairedAt : void 0;
|
|
46299
|
+
const taking = group || this.activeLinkId === linkId || inUse || paired !== void 0;
|
|
46300
|
+
const mine = taking && (inUse || onScreen(live)) ? now : Math.max(paired ?? 0, used(live));
|
|
45585
46301
|
const groupVictim = !full ? void 0 : owners.filter((other) => other !== live && extra(other) && other.link?.canReleaseEndpoint(key)).sort((a, b) => (a.link?.isDataLinkOpen ? 1 : 0) - (b.link?.isDataLinkOpen ? 1 : 0) || used(a) - used(b))[0];
|
|
45586
46302
|
const quiet = (other) => other !== live && (full || !other.stored.group) && !other.stored.groupEntry && !onScreen(other) && now - (other.nativeTakenAt?.[key] ?? 0) >= 12e4 && used(other) <= now - 12e4 && used(other) < mine;
|
|
45587
46303
|
const victim = groupVictim ?? (taking ? owners.filter((other) => quiet(other) && other.link?.canReleaseEndpoint(key)).sort((a, b) => used(a) - used(b))[0] : void 0);
|
|
@@ -46202,11 +46918,7 @@ var EngineServer = class {
|
|
|
46202
46918
|
if (sent.has(link.id)) continue;
|
|
46203
46919
|
await this.inOrder(link.id, async () => {
|
|
46204
46920
|
if (!this.clients.has(client)) return;
|
|
46205
|
-
client.post(scope.newest ? await this.newestOf(link.id, scope.newest) :
|
|
46206
|
-
kind: "messages",
|
|
46207
|
-
linkId: link.id,
|
|
46208
|
-
messages: await this.node.getMessages(link.id)
|
|
46209
|
-
});
|
|
46921
|
+
client.post(scope.newest ? await this.newestOf(link.id, scope.newest) : this.historyEvent(link.id, await this.node.getMessages(link.id)));
|
|
46210
46922
|
this.histories.get(client)?.add(link.id);
|
|
46211
46923
|
});
|
|
46212
46924
|
}
|
|
@@ -46277,29 +46989,21 @@ var EngineServer = class {
|
|
|
46277
46989
|
linkId,
|
|
46278
46990
|
limit
|
|
46279
46991
|
});
|
|
46280
|
-
return
|
|
46281
|
-
kind: "messages",
|
|
46282
|
-
linkId,
|
|
46283
|
-
messages: page.messages,
|
|
46284
|
-
...page.more ? { more: true } : {}
|
|
46285
|
-
};
|
|
46992
|
+
return this.historyEvent(linkId, page.messages, page.more);
|
|
46286
46993
|
}
|
|
46287
46994
|
/**
|
|
46288
46995
|
* A chat's or group's whole history, to this client alone as a `messages` event, after what is still being sent for it
|
|
46289
|
-
* (a `HistoryRequest`, which the host hands here): what changes while it is read follows it.
|
|
46996
|
+
* (a `HistoryRequest`, which the host hands here): what changes while it is read follows it. A group's, once the groups
|
|
46997
|
+
* are read, as `groupMessages` answers: a group that opens while the engine starts is not left on its newest page.
|
|
46290
46998
|
*/
|
|
46291
46999
|
async history(client, linkId) {
|
|
46292
47000
|
if (typeof linkId !== "string" || !this.clients.has(client)) return;
|
|
46293
47001
|
try {
|
|
46294
|
-
await this.ready;
|
|
47002
|
+
await (linkId.startsWith("group:") ? Promise.race([this.ready, this.node.groupsRead]) : this.ready);
|
|
46295
47003
|
await this.inOrder(linkId, async () => {
|
|
46296
47004
|
if (!this.clients.has(client)) return;
|
|
46297
47005
|
const messages = await this.node.getMessages(linkId);
|
|
46298
|
-
if (this.clients.has(client) && this.post(client,
|
|
46299
|
-
kind: "messages",
|
|
46300
|
-
linkId,
|
|
46301
|
-
messages
|
|
46302
|
-
})) this.histories.get(client)?.add(linkId);
|
|
47006
|
+
if (this.clients.has(client) && this.post(client, this.historyEvent(linkId, messages))) this.histories.get(client)?.add(linkId);
|
|
46303
47007
|
});
|
|
46304
47008
|
} catch {}
|
|
46305
47009
|
}
|
|
@@ -46314,12 +47018,22 @@ var EngineServer = class {
|
|
|
46314
47018
|
});
|
|
46315
47019
|
return running;
|
|
46316
47020
|
}
|
|
46317
|
-
|
|
46318
|
-
|
|
47021
|
+
/**
|
|
47022
|
+
* A history (whole, or its newest page with `more`) as a client gets it: with the ids the engine deleted in it, which
|
|
47023
|
+
* a list cannot show.
|
|
47024
|
+
*/
|
|
47025
|
+
historyEvent(linkId, messages, more) {
|
|
47026
|
+
const deleted = this.node.deletedIdsOf(linkId);
|
|
47027
|
+
return {
|
|
46319
47028
|
kind: "messages",
|
|
46320
47029
|
linkId,
|
|
46321
|
-
messages
|
|
46322
|
-
|
|
47030
|
+
messages,
|
|
47031
|
+
...more ? { more: true } : {},
|
|
47032
|
+
...deleted.length > 0 && { deleted }
|
|
47033
|
+
};
|
|
47034
|
+
}
|
|
47035
|
+
sendHistory(linkId, messages) {
|
|
47036
|
+
this.broadcast(this.historyEvent(linkId, messages));
|
|
46323
47037
|
for (const client of this.clients) this.histories.get(client)?.add(linkId);
|
|
46324
47038
|
}
|
|
46325
47039
|
sendChanges(linkId, changes) {
|
|
@@ -46339,11 +47053,7 @@ var EngineServer = class {
|
|
|
46339
47053
|
return this.node.getMessages(linkId).then((messages) => {
|
|
46340
47054
|
for (const client of behind) {
|
|
46341
47055
|
if (!this.clients.has(client)) continue;
|
|
46342
|
-
if (this.post(client,
|
|
46343
|
-
kind: "messages",
|
|
46344
|
-
linkId,
|
|
46345
|
-
messages
|
|
46346
|
-
})) this.histories.get(client)?.add(linkId);
|
|
47056
|
+
if (this.post(client, this.historyEvent(linkId, messages))) this.histories.get(client)?.add(linkId);
|
|
46347
47057
|
}
|
|
46348
47058
|
});
|
|
46349
47059
|
}
|
|
@@ -46377,4 +47087,4 @@ function signalKind(signal) {
|
|
|
46377
47087
|
//#endregion
|
|
46378
47088
|
export { EngineServer };
|
|
46379
47089
|
|
|
46380
|
-
//# sourceMappingURL=server-
|
|
47090
|
+
//# sourceMappingURL=server-DPzt5V2x.js.map
|