Skip to content

Telegram /sessions: paginate the switcher, pin starred, exclude cron - #304

Open
serxa wants to merge 2 commits into
mainfrom
serxa/telegram-sessions-paging
Open

Telegram /sessions: paginate the switcher, pin starred, exclude cron#304
serxa wants to merge 2 commits into
mainfrom
serxa/telegram-sessions-paging

Conversation

@serxa

@serxa serxa commented Aug 10, 2026

Copy link
Copy Markdown
Member

Problem

On Telegram, /sessions surfaced only a handful of recent sessions, and starred (kept-alive) sessions were usually not among them:

  • The switcher fetched the 30 most-recently-updated sessions across all sources, then filtered to interactive (telegram/web) ones in Python. Cron/automation sessions update constantly, so they dominated that 30-row window — in practice only a few interactive sessions survived the filter, well under the button cap (a user reported seeing 4).
  • Ordering was pure recency, and starring only added a ⭐ to a label if the session already appeared. Since starring exists to keep idle sessions alive, those sessions have an old updated_at and sank below the cutoff — so the sessions a user most wants to return to were the least reachable.
  • There was no way to reach anything past the first page.

Change

  • New SessionStore.list_interactive_sessions(limit, offset, sources, current_id) that does the work in SQL: filters to interactive sources and non-empty sessions (so cron/automation and 0-message sessions never consume the window), and orders current → starred → most-recent. Exposed through SessionManager and the channel Router.
  • _sessions_view_for now fetches one page (page_size + 1, to detect a further page) instead of over-fetching and counting messages per session in Python.
  • build_sessions_view renders ⬅️ Prev / ➡️ More buttons (new sess:page:<offset> callback) so every switchable session is reachable. Pinning the current session first keeps it on page 1 regardless of how many starred sessions precede it; starred sessions are pinned ahead of merely-recent ones so an idle kept-alive session is never buried.
  • Page size 8 → 10.
  • Dropped the per-row ⭐/☆ toggle: Telegram sizes a row's buttons evenly with no API for a narrow second column, so the toggle took half of every session row. The ⭐ stays as a read-only "kept alive" marker in the switch label; star/unstar via /star · /unstar. Each row is now a single full-width tap-to-switch button.

Tests

  • tests/test_list_interactive_sessions.py (new) — current→starred→recent ordering; exclusion of cron / empty / archived; pagination via limit/offset; next-page probe.
  • tests/test_telegram_sessions.py — updated the switcher tests for the paged, single-button-per-row view; added first/middle/last-page nav assertions.
  • Full suite: 3196 passed, 1 pre-existing unrelated failure (test_xmemory_bridge — an xmemory package version mismatch, independent of this change).

serxa and others added 2 commits August 10, 2026 19:02
The /sessions switcher fetched the 30 most-recently-updated sessions
across all sources, then filtered to interactive (telegram/web) ones.
Cron/automation sessions update constantly and dominated that window,
so only a few interactive sessions survived the filter — often well
under the button cap. Ordering was pure recency, and starring only
added a marker to a label if the session already appeared, so starred
(kept-alive) sessions — which exist precisely to survive going idle —
sank below the cutoff and became the least reachable.

Add SessionStore.list_interactive_sessions(): filter to interactive
sources and non-empty sessions in SQL (so cron/automation and 0-message
sessions never consume the window) and order current -> starred ->
most-recent. /sessions now pages over it with Prev/More buttons
(sess:page:<offset>) so every switchable session is reachable; the
current session is pinned first (always visible on page one) and
starred sessions ahead of merely-recent ones. Page size 8 -> 10. The
per-row star toggle is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Telegram splits a keyboard row's width evenly across its buttons with no
API to size a narrow second column, so the per-row star toggle took half
of every session row. Keep the star as a read-only "kept alive" marker in
the switch label; star/unstar via /star and /unstar. Each row is now a
single full-width tap-to-switch button. Removes the dead sessstar callback
and routing, and the unused Router.toggle_session_starred wrapper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@serxa
serxa marked this pull request as ready for review August 10, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant