Pro glue: expose auto_renewing (key A) and grace period (key G) - #68
Draft
mpretty-cyro wants to merge 1 commit into
Draft
Pro glue: expose auto_renewing (key A) and grace period (key G)#68mpretty-cyro wants to merge 1 commit into
mpretty-cyro wants to merge 1 commit into
Conversation
Mirrors the getProPrepaid/setProPrepaid pattern for libsession's user_profile auto-renewing and grace-period accessors, added by core #121. A is presence-only: set_pro_auto_renewing uses set_nonzero_int, so writing false erases the key and the getter cannot distinguish "not auto-renewing" from "never written". G is deliberately not optional, because the backend sends 0 when the subscription isn't auto-renewing and E - 0 == E, so an absent key and a stored zero describe the same account. Both caveats are documented on the declarations rather than at a call site, since the next reader of the glue meets them there. G is milliseconds in the JS domain, converted to core's whole seconds here. That follows the other Pro accessors and the gracePeriodDurationMs field callers get from get_pro_status, rather than setNoteToSelfExpiry's seconds-through shape. E and G are only jointly meaningful when written from the same get_pro_status response, and a client clearing E must clear G or a later E pairs with a stale grace. Noted in the type declaration because no signature can enforce it. Not compiled against core: #121 is unmerged and the submodule is left at its recorded commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the
libsession_util_nodejsbindings for two synced user-profile config keys that Session Desktop'sPro status-refresh work needs. No behaviour change to anything existing — four new methods, nothing
altered.
getProAutoRenewing()/setProAutoRenewing(bool)user_profile_{get,set}_pro_auto_renewingbooleangetProGracePeriod()/setProGracePeriod(graceMs)user_profile_{get,set}_pro_grace_periodnumber(ms)Mirrors the existing
getProPrepaid/setProPrepaidpair — implementation plusInstanceMethodregistration in
src/user_config.cpp, declarations ininclude/user_config.hpp, and the threedeclaration sites in
types/user/userconfig.d.ts(interface,UserConfigWrapperNode,MakeActionCallunion).
A wrapper reviewer won't have either of these in mind, so stating them plainly:
Auser_profile_{get,set}_pro_auto_renewing8e5634b8— openGuser_profile_{get,set}_pro_grace_period086a420eonfeature/pro-auto-renewing-tristate, not yet pushed or reviewed086a420esits directly on top of8e5634b8(verified:8e5634b8is an ancestor), so the two are achain rather than alternatives — but the second is a branch that completes #121 rather than part of it as
currently proposed. This PR cannot build until both are merged and the submodule pin moves.
What is verified, and what is not
Stated explicitly because "it compiled" is not available here:
InstanceMethodregistrations exactly.That pairing is unchecked at compile time on this platform — napi dispatch is by string — so it's worth
saying it was checked rather than assumed. The core signatures were read from
include/session/config/user_profile.hppat086a420e, not taken from a description.(wrapper as any)[action]with no registry orallow-list, so there's no third site to keep in sync; the two string literals are the whole surface. A
missing or misnamed binding throws a named error on first call rather than failing silently.
recorded commit, because neither core change is merged. So there is no artefact to inspect for symbols,
and CI is the first real build. Two of three verification legs, by construction rather than by omission.
Two deliberate choices a reviewer may want to challenge
Gis milliseconds on the JS side, converted to core's whole seconds here. The wrapper has twoconventions in tension: timestamps are ms-in-JS with C++ converting (
setProAccessExpiry,setProPrepaid,setRefundRequested), while the one existing duration accessor,setNoteToSelfExpiry, takes seconds straight through.Gis a duration in the Pro family. Chose msbecause callers hold
gracePeriodDurationMsfrom theget_pro_statusresponse, and it keeps theconversion in one place instead of at every call site. The conversion floors, so a derived paid-through
never claims coverage the backend didn't grant. Easy to flip if seconds is preferred.
Gis not optional, unlikeA. The backend sends0whenever the subscription isn't auto-renewing,and
E - 0 == E, so "no grace stored" and "a grace of zero" describe the same account. There's nothingfor a presence check to disambiguate, and adding one by symmetry with
Awould copy a trap rather than apattern.
Caveats documented at the declarations, not at call sites
The next reader of this glue won't have the design thread, so both live in the type declaration:
Ais presence-only. Core writes it withset_nonzero_int, sosetProAutoRenewing(false)erasesthe key. The getter therefore returns
falsefor all of "not auto-renewing", "never fetched yet" and"written by a client predating
A". Callers must not treatfalseas "definitely not renewing", andmust not key a change check on whether the key is present.
EandGare only jointly meaningful when written from the sameget_pro_statusresponse. They'rethen internally consistent whatever grace was in force. No signature can enforce that, so it's stated:
write them together, and clear
Gwhen clearingE, or a laterEpairs with a stale grace.Not included:
has_pro_auto_renewing086a420ealso addsuser_profile_has_pro_auto_renewing(), which distinguishes "never written" from"explicitly false". Deliberately not mirrored here — no client calls it yet. It becomes useful only if
the cross-client decision on bootstrapping an unpopulated
Agoes that way, and it's ~6 lines to add in afollow-up commit. Absent rather than overlooked.