mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6503] [MERGED] refactor(tgbot): make the add-client expiry presets say what they do #6314
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6314
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6503
Author: @BlindMaster24
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:refactor/tgbot-add-client-expiry-preset📝 Commits (3)
c315481refactor(tgbot): make the add-client expiry presets say what they do9bd4999refactor(tgbot): fold in the review of the expiry-preset changecba7f56chore(tgbot): merge main into the expiry-preset refactor📊 Changes
3 files changed (+83 additions, -64 deletions)
View changed files
➕
internal/web/service/tgbot/tgbot_add_client_expiry_test.go(+61 -0)📝
internal/web/service/tgbot/tgbot_draft_render_test.go(+9 -44)📝
internal/web/service/tgbot/tgbot_router.go(+13 -20)📄 Description
Summary
Removes the dead accumulate branch in the add-client wizard's expiry presets, makes the preset labels say what they do, and pins the intent with a test.
Why
The automated review of #6499 raised this twice as a LOW pre-existing:
draft.expiryTime = 0runs unconditionally at the top ofadd_client_reset_exp_c, so theif draft.expiryTime > 0below it tests a value set to zero one line earlier. The branch is unreachable and onlydate = 0 - daysever runs.I said in that PR I would not fix it there, because reviving the branch is a behaviour change rather than a drive-by, and I did not want to guess which semantics you want. Here is the decision, with the reasoning, so you can disagree with something concrete.
The wizard sets the term; it does not add to it.
add_client_tostarts every field at its default, expiry at 0.add_client_reset_exp_in <n>types a number and confirms throughadd_client_reset_exp_c <n>. With add semantics, correcting 30 days to 90 would silently produce 120.0stays the Unlimited button — it clears the term, which is what the button says.So the whole reachable behaviour collapses to one assignment, and the code now reads as the decision instead of as an accident. The renewal handler (
reset_exp_c, the same preset row on an existing client) is the opposite case and is untouched: there the client does have remaining time, so it adds to the current expiry, and itsif days > 0guard is what keeps0meaning Unlimited.The labels follow. The wizard's preset buttons read Add 7 Days, Add 1 Month, … while assigning rather than adding, so the operator-facing half contradicted the code. They now read 7 Days, 1 Month, 3 Months, with the term the presets actually set. The renewal keyboard keeps its Add — there the word is true. No translation key was added or removed: the wizard rows compose
"7 " + tgbot.daysinstead oftgbot.add + " 7 " + tgbot.days, andtgbot.addstays in use by the renewal row.Honest framing
This is a refactor with no behaviour change, so the test passes on the base commit too — I am not going to pretend otherwise. What it pins is the decision, and after the review pass it pins it per row: each row starts from a term a preset could have left (
client_ExpiryTime = -7 * 86400000), soadd_client_reset_exp_c 30,90and0each fail on their own if the accumulate branch is revived — the card would read37 Days,97 Daysand7 Daysinstead of30 Days,90 DaysandUnlimited. Before that, only the90row discriminated, and only because the30row had run first.Type of change
Areas affected
How was this tested?
TestAddClientExpiryPresetReplacesTheTermdrives the realanswerCallbackpath with a mocked Telegram API, so the assertion is on the card text that would actually be sent:30 Days/90 Days/Unlimited. It installs a go-i18n bundle for the two labels the card prints, becauseI18nreturns the bare key with no localizer, and it clearsreceiver_inbound_IDsso the card's attached-inbounds line cannot reach the database from whatever test ran before it — both the expiry global and that slice are saved and restored around the test.The mocked-Telegram helpers are the package's shared ones (
draftLocalizer,draftTexts), which now register only the messages a test passes in and recordeditMessageTextalongsidesendMessage. They replaced a second, near-identical copy this PR had added, as the review asked.Behaviour is otherwise untouched: the renewal preset and the custom keypad keep their existing paths.
Verification
This machine has no C compiler, so the local run substitutes a pure-Go SQLite driver (
modernc.org/sqlite) behind ago build -overlaywhose only entries areinternal/database's three driver call sites. No source file this PR touches is overlaid, so the handler and the test below are the ones in the diff.Under that rig:
go test ./internal/web/service/tgbot/— the whole package passes, including the prompt-escaping test that shares the helpers the review asked me to consolidate.37 Days,97 Daysand7 Daysinstead of30 Days,90 DaysandUnlimited.main's handler verbatim, the same test passes — the "no behaviour change" claim above, checked rather than asserted.gofmtandgo vetare clean on all three files. CI still runs the full gate against the real CGo driver.Screenshots / recordings
N/A — Telegram message text, covered by the test above.
Breaking changes
None. Existing drafts and clients keep the expiry the wizard already gave them.
Checklist
go build ./...and the test suite pass locally. (as-is they need the CGo driver; CI covers that)npm run lint,npm run typecheck, andnpm run buildpass. (no frontend change in this PR)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.