Skip to content

fix(chats): cache joined communities and refuse to sync one - #76

Merged
neoromantic merged 6 commits into
mainfrom
feat/cache-joined-communities-58
Oct 22, 2026
Merged

neoromantic merged 6 commits into
mainfrom
feat/cache-joined-communities-58

Conversation

@neoromantic

Copy link
Copy Markdown
Owner

Problem

Telegram lists a joined community as dialogCommunity, apart from the other dialogs. mtcute's dialog list keeps only dialog, so neither the daemon's dialog pass nor tg chats list --fresh cached a community, and tg chats list --type community found none. A community also has no messages of its own (dialogCommunity has no top message), so tg chats sync <community> would queue jobs that can only fail.

Change

  • fetchJoinedCommunities (in src/commands/chats/helpers.ts) makes one communities.getJoinedCommunities call and maps each community / communityForbidden through rawChatToCacheInput: type community, marked -100… ID, access hash. A min community is skipped, because its access hash works only in the update that carried it.
  • Daemon dialog pass: after the dialogs are saved, the pass caches the joined communities through the same stop-aware withParams client. A community gets no chat_sync_state row and isn't added to visited. If the request fails, the daemon logs a warning and the pass still counts as complete. A stop skips the request or cuts it short. The log line now also counts communities. Reconnect passes pick this up too.
  • tg chats list --fresh: the fetch now runs in fetchChatsFromApi. It caches the dialogs and the joined communities with one upsert. A failed communities request is reported only with --verbose, and the dialogs are still listed.
  • tg chats sync <community> (no flag) exits with INVALID_ARGS (exit 3), writes nothing and points at the linked supergroups and channels. --off and --auto still work.
  • Docs: cli-commands.md, database-schema.md and sync-strategy.md no longer say communities aren't cached.

No schema change and no migration.

Tests

  • daemon-bootstrap.test.ts: caches a community with its access hash and the stop signal and creates no sync state; an account without communities makes one call and logs no warning; a failed request is one warning and the pass stays complete (left chats are still marked caught up); a stop during the request ends it with no timer wait; a stop right after a complete pass skips it; a real TelegramClient with a mocked _client.call gets the signal and keeps only the community and the communityForbidden (it drops the min community and the channel).
  • chats.test.ts: fetchChatsFromApi caches communities next to the dialogs, and still caches the dialogs when the communities request fails.
  • chats-sync.e2e.test.ts: refuses to turn on a community and points at its linked chats; --off still succeeds.
  • Local: bun run check, bun run test (1767 pass), and the affected unit and e2e files. The three commands.e2e.test.ts tests that try the API with dummy credentials time out locally on the base commit as well; CI runs the full e2e suite.

Fixes #58

🤖 Generated with Claude Code

neoromantic and others added 6 commits October 22, 2026 21:45
…t --fresh

Telegram lists a joined community as dialogCommunity, apart from the
other dialogs, and mtcute's dialog list keeps only dialog, so
tg chats list --type community never found one. The daemon's dialog pass
(on start and after a reconnect) and tg chats list --fresh now also call
communities.getJoinedCommunities and cache each community with its
access hash. An account without communities pays one request.

A community has no messages of its own, so it gets no sync state. A
failure of the extra request is logged and leaves the pass complete and
the list working: it says nothing about the chats. A min community is
skipped, since its access hash works only in the update that carried it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Telegram community only groups linked chats: dialogCommunity has no
top message, so jobs queued for one would only fail. tg chats sync
<community> now exits with INVALID_ARGS and points at the linked
supergroups and channels, which sync as ordinary chats. It writes
nothing and queues no jobs. --off and --auto still succeed, since they
match the default policy, which leaves a community off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The joined-communities request went through the daemon's flood waiter,
which sleeps up to 5 minutes per retry. The dialog pass runs the accounts
one after another and the scheduler starts only after it, so one
FLOOD_WAIT on this best-effort request held up the start of sync for every
account, though the dialogs were already saved. tg chats list --fresh
could wait up to 60 s the same way.

Both now make the request with floodSleepThreshold 0: a FLOOD_WAIT fails
it at once, the existing warning or verbose line reports it, and the next
pass retries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uest short

The communities request is the one await between the dialog pages and the
pass's return. A stop that ended it left the pass complete and not
stopped, so it logged "Bootstrapped ..., 0 communities" during the
shutdown, and the caller marked unvisited chats and refreshed queues while
the cache databases were closing. A stop there now ends the pass like a
stop during a page.

The test now checks the result, that no Bootstrapped line was logged, and
that the stop signal, not the fake's guard timer, ended the wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
0.4 could turn a community on, so the daemon keeps queueing jobs for it
that fail. The usual retry, tg chats sync <chat>, is now refused, and the
refusal only pointed at the linked chats. When the community's sync mode
is on, the suggestion now also says that --auto turns it off and clears
its failed jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… row

The schema doc said a community never gets a chat_sync_state row, but
tg chats sync <community> --off or --auto writes one, with sync off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@neoromantic
neoromantic force-pushed the feat/cache-joined-communities-58 branch from e46d390 to 1aa1a28 Compare October 22, 2026 17:46
@neoromantic
neoromantic merged commit 141bcbb into main Oct 22, 2026
5 checks passed
@neoromantic
neoromantic deleted the feat/cache-joined-communities-58 branch October 22, 2026 17:49
@neoromantic neoromantic mentioned this pull request Oct 22, 2026
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.

Joined communities aren't cached: the dialog pass and chats list --fresh skip them

1 participant