mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6211] [MERGED] refactor(tgbot): share numeric keypad transitions #6173
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#6173
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/6211
Author: @n0ctal
Created: 8/12/2026
Status: ✅ Merged
Merged: 8/13/2026
Merged by: @MHSanaei
Base:
main← Head:codex/upstream-tgbot-keypad-transition📝 Commits (2)
f959420refactor(tgbot): share numeric keypad transitions1a06376Merge branch 'main' into codex/upstream-tgbot-keypad-transition📊 Changes
3 files changed (+62 additions, -60 deletions)
View changed files
➕
internal/web/service/tgbot/numeric_input.go(+18 -0)➕
internal/web/service/tgbot/numeric_input_test.go(+38 -0)📝
internal/web/service/tgbot/tgbot_router.go(+6 -60)📄 Description
Summary
The inline number pad's state transition is copy-pasted into six callback branches in
tgbot_router.go. This extracts it into one unexported helper.Why
The six copies are byte-for-byte identical:
-2clears,-1drops the last digit, anything else appends. That is fine until one of them needs a change — a new clear key, a maximum length, a guard against overflow — at which point the change has to be made six times and reviewed six times, and missing one produces a keypad that behaves differently from its five siblings for reasons no one can see at the call site.This is a pure extraction: no behaviour changes, no caller-specific validation is touched, and the button labels and callback payloads are untouched.
Scope
internal/web/service/tgbot/numeric_input.go: newupdateNumericInput(value, key int) int, which reproduces the existingswitchexactly.internal/web/service/tgbot/tgbot_router.go: six branches call it.Net effect on the router is 36 fewer lines.
Validation
TestUpdateNumericInputis a table test over reset, backspace, append and the zero case.TestNumericInputTransitionIsUsedByEveryKeypadasserts there are six call sites, so a future keypad that open-codes the switch again is caught.tgbot_router.goreverted, that test fails withnumeric keypad transition call sites = 0, want 6.go build ./internal/...,go vet,internal/web/service/tgbottests,golangci-lint,staticcheck -checks=U1000(host andGOOS=linux),make gen-check: all clean.Risk
Lowest of the set in behaviour and highest in review cost, since a reviewer has to satisfy themselves that all six copies really were identical. The helper is a verbatim copy of the block it replaces, and the transitions are covered by the table test. No Telegram or browser interaction was exercised.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.