Skip to content

fix(telegram): search only on click, stop search floods and lost Telegram sources - #757

Merged
ProdigyV21 merged 4 commits into
ProdigyV21:mainfrom
silentbil:fix/telegram-search
Sep 27, 2026
Merged

ProdigyV21 merged 4 commits into
ProdigyV21:mainfrom
silentbil:fix/telegram-search

Conversation

@silentbil

Copy link
Copy Markdown
Collaborator

Telegram search is rate-limited per account. The app searched it automatically from every source list, firing about 26 requests per episode, so lookups kept timing out, sometimes with a toast over playback.

  • New setting in Telegram settings, on by default and synced to the cloud: "Only search Telegram when clicking the Telegram source". The source list shows a "Click to search Telegram" row, results appear as they are found, and the player never searches.
  • Lighter search: one request per phrase instead of two. The four phrasings that found every result in testing run first, two at a time. The rest only run if those find nothing.
  • A timed-out search is no longer cached as "no results", which used to hide Telegram sources for hours.
  • One shared search per episode. Starting playback stops running searches, and no Telegram toasts appear during playback.
  • Fixed: the player's addons-only source lookup overwrote the saved source list, so Telegram sources disappeared when reopening an episode.
  • The Telegram library now logs errors only.
  • The source list shows "still checking N addons" while a source is still loading.
  • Added Hebrew translations for the new texts.

@github-actions github-actions Bot added the area: android Changes to the Android app or Gradle build label Sep 25, 2026
@ProdigyV21

Copy link
Copy Markdown
Owner

Thanks for working on this! Searching only when requested and reducing Telegram traffic are useful improvements. It merges cleanly, the Play build compiles, and all 22 existing Telegram tests pass. I found three remaining issues to fix before merging:

  1. Request timeouts can still be cached as no results. TelegramClient.sendRequest() returns null after its 20-second timeout, but TelegramRepository treats that as an empty response. A movie lookup can therefore finish before the outer 30-second deadline and cache an empty result for hours. Please propagate an incomplete outcome from individual requests and never cache it as a completed search.

  2. Unfiltered search can miss playable files. The new request uses filter = null, reads only the first page, then discards non-video messages. Newer text/photo messages can fill that page while matching videos are further back. TDLib documents this as a paginated, newest-first search. Please use bounded pagination or a targeted video/document fallback, while keeping the rate-limit protection.

  3. Manual results can still disappear when reopening Sources. searchTelegramNow() updates the resolver cache/UI, not the source-list cache. Reopening can return the older addon-only list before checking Telegram's cache. With Telegram as the only provider, the no-addons early return also discards cached Telegram results. Please merge those results on every cache-return path, or update/invalidate the relevant list caches after manual search.

Please add regression tests for a per-request timeout, non-video first-page results, and reopening after a successful manual search (including Telegram-only). The existing tests don't cover these new paths. I haven't tested this build on a physical TV or live Telegram account. Thanks!

…eopened Sources

- A request Telegram did not answer in time now makes the whole lookup
  incomplete, so it is never cached as "no results" (the per-request 20s
  timeout used to look like an empty answer).
- When a phrasing's unfiltered first page has more results behind it, the
  phrasing is repeated with the video and document filters, so newer text or
  photo posts cannot push the files off the only page read. Pages with nothing
  behind them still cost one request.
- Telegram results found by a click-search are merged into every saved source
  list that Sources returns (fresh, stale, disk and addon-less paths), so
  reopening Sources keeps them, including with Telegram as the only provider.
- The phrase loop and the result cache moved into TelegramPhraseSearch /
  TelegramResultCache (no Android dependencies) with regression tests for a
  per-request timeout, a cut-off first page, and reopening after a
  click-search (including Telegram-only).
@silentbil

Copy link
Copy Markdown
Collaborator Author

@ProdigyV21 thanks for the review! All three are fixed in 4bde881:

  1. Per-request timeouts: a request Telegram doesn't answer in time now marks the whole lookup incomplete. Whatever was found is still shown, but it's never cached as a completed search.
  2. Cut-off first page: when a phrasing's unfiltered page has more results behind it, the phrasing is repeated with the video and document filters. Pages with nothing behind them still cost a single request, so the rate-limit protection stays.
  3. Reopening Sources: Telegram results found by clicking are now added on every path that returns a saved source list (fresh, stale, disk and no-addons), so they survive reopening, including with Telegram as the only provider.

The phrase loop and the result cache moved into Android-free classes (TelegramPhraseSearch / TelegramResultCache), with regression tests for a per-request timeout, a first page full of non-video posts, and reopening after a click-search (including Telegram-only).

Tested on an Android TV emulator with a live Telegram account: the click-search found all 10 matching files for Special Ops: Lioness S1E1 in about 2s, reopening Sources kept them without a new search, and nothing was cached from incomplete lookups.

@ProdigyV21
ProdigyV21 merged commit 57f19a7 into ProdigyV21:main Sep 27, 2026
5 checks passed
@ProdigyV21

Copy link
Copy Markdown
Owner

Thanks @silentbil for addressing all three review points and adding the regression coverage. I checked the updated changes against current main and added one small follow-up: publish each answered page immediately, so a stalled sibling query or filtered follow-up cannot hide files already found when the overall deadline expires. Request counts and the two-query concurrency limit are unchanged. Both new regression tests reproduced the old behavior and now pass; all 36 focused Telegram tests pass, along with GitHub's full Sideload test build, web/backend tests and web type check. Merged with your original commits and authorship preserved. I have not repeated the live-account/emulator test or tested this on a physical TV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: android Changes to the Android app or Gradle build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants