[PR #7051] [CLOSED] fix(tgbot): allow pagination callbacks for client users (#7032) #6622

Closed
opened 2026-11-07 14:34:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/7051
Author: @DoctorGuidance
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: fix/tgbot-client-pagination


📝 Commits (1)

  • 9a3b771 fix(tgbot): allow pagination callbacks for non-admin clients (#7032)

📊 Changes

4 files changed (+23 additions, -8 deletions)

View changed files

📝 internal/web/service/tgbot/screen_client_views.go (+2 -6)
📝 internal/web/service/tgbot/screens_test.go (+11 -0)
📝 internal/web/service/tgbot/tgbot_callback_auth_test.go (+6 -1)
📝 internal/web/service/tgbot/tgbot_router.go (+4 -1)

📄 Description

Summary of Changes

Fixes #7032

Root Cause

In internal/web/service/tgbot/tgbot_router.go, when an incoming callback query is processed from a non-admin client (!isAdmin), isClientSelfCallback(callbackQuery.Data) is evaluated to filter allowed per-user callbacks:

if !isAdmin {
    if decoded, err := t.decodeQuery(callbackQuery.Data); err == nil {
        callbackQuery.Data = decoded
    }
    if !isClientSelfCallback(callbackQuery.Data) {
        return
    }
}

However, the pager callback identifiers (cbPageNext = "pg:next", cbPagePrev = "pg:prev", and cbPageNone = "pg:none") were missing from isClientSelfCallback. Consequently, when any client user with multiple accounts or links (which span multiple pages due to Telegram's 1024-character caption limit) tapped next/prev page buttons, isClientSelfCallback returned false, and the router returned immediately without answering the query. This resulted in an endless loading spinner on the button and trapped client users on the first page.

Additionally, in internal/web/service/tgbot/screen_client_views.go, ownSubscriptionOnly returned false for multi-subscription clients due to a strict len(traffics) == 1 check, causing an admin-only "Client card" button (client_get_usage <email>) to be mistakenly offered to non-admin users.

Solution

  1. Added cbPageNext, cbPagePrev, and cbPageNone to isClientSelfCallback:
    Pager navigation callbacks now pass the callback gate safely and trigger t.turnPage(). Pager state is strictly per-chat (t.screens().get(chatID)), maintaining complete chat isolation.
  2. Fixed ownSubscriptionOnly:
    Updated the check to verify t.clientOwnedByTgUser(chatID, email) instead of single-item length, ensuring multi-account client users are recognized as owners and never offered admin-only client management cards.
  3. Unit Tests Added:
    • Extended TestIsClientSelfCallback to assert pg:next, pg:prev, and pg:none are permitted per-user callbacks.
    • Added TestClientCanReachPaginationCallbacks to prevent regressions.
    • Updated client screen tests to verify multi-subscription client scenarios.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7051 **Author:** [@DoctorGuidance](https://github.com/DoctorGuidance) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tgbot-client-pagination` --- ### 📝 Commits (1) - [`9a3b771`](https://github.com/MHSanaei/3x-ui/commit/9a3b77111bdc367fc9d2a8a9d5e82df28fe5ba15) fix(tgbot): allow pagination callbacks for non-admin clients (#7032) ### 📊 Changes **4 files changed** (+23 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/tgbot/screen_client_views.go` (+2 -6) 📝 `internal/web/service/tgbot/screens_test.go` (+11 -0) 📝 `internal/web/service/tgbot/tgbot_callback_auth_test.go` (+6 -1) 📝 `internal/web/service/tgbot/tgbot_router.go` (+4 -1) </details> ### 📄 Description ### Summary of Changes Fixes #7032 #### Root Cause In `internal/web/service/tgbot/tgbot_router.go`, when an incoming callback query is processed from a non-admin client (`!isAdmin`), `isClientSelfCallback(callbackQuery.Data)` is evaluated to filter allowed per-user callbacks: ```go if !isAdmin { if decoded, err := t.decodeQuery(callbackQuery.Data); err == nil { callbackQuery.Data = decoded } if !isClientSelfCallback(callbackQuery.Data) { return } } ``` However, the pager callback identifiers (`cbPageNext = "pg:next"`, `cbPagePrev = "pg:prev"`, and `cbPageNone = "pg:none"`) were missing from `isClientSelfCallback`. Consequently, when any client user with multiple accounts or links (which span multiple pages due to Telegram's 1024-character caption limit) tapped next/prev page buttons, `isClientSelfCallback` returned `false`, and the router returned immediately without answering the query. This resulted in an endless loading spinner on the button and trapped client users on the first page. Additionally, in `internal/web/service/tgbot/screen_client_views.go`, `ownSubscriptionOnly` returned `false` for multi-subscription clients due to a strict `len(traffics) == 1` check, causing an admin-only "Client card" button (`client_get_usage <email>`) to be mistakenly offered to non-admin users. #### Solution 1. **Added `cbPageNext`, `cbPagePrev`, and `cbPageNone` to `isClientSelfCallback`**: Pager navigation callbacks now pass the callback gate safely and trigger `t.turnPage()`. Pager state is strictly per-chat (`t.screens().get(chatID)`), maintaining complete chat isolation. 2. **Fixed `ownSubscriptionOnly`**: Updated the check to verify `t.clientOwnedByTgUser(chatID, email)` instead of single-item length, ensuring multi-account client users are recognized as owners and never offered admin-only client management cards. 3. **Unit Tests Added**: - Extended `TestIsClientSelfCallback` to assert `pg:next`, `pg:prev`, and `pg:none` are permitted per-user callbacks. - Added `TestClientCanReachPaginationCallbacks` to prevent regressions. - Updated client screen tests to verify multi-subscription client scenarios. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:34:12 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6622
No description provided.