Repository navigation
fix(chats): cache joined communities and refuse to sync one - #76
Merged
Merged
Conversation
…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
force-pushed
the
feat/cache-joined-communities-58
branch
from
October 22, 2026 17:46
e46d390 to
1aa1a28
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Telegram lists a joined community as
dialogCommunity, apart from the other dialogs. mtcute's dialog list keeps onlydialog, so neither the daemon's dialog pass nortg chats list --freshcached a community, andtg chats list --type communityfound none. A community also has no messages of its own (dialogCommunityhas no top message), sotg chats sync <community>would queue jobs that can only fail.Change
fetchJoinedCommunities(insrc/commands/chats/helpers.ts) makes onecommunities.getJoinedCommunitiescall and maps eachcommunity/communityForbiddenthroughrawChatToCacheInput: typecommunity, marked-100…ID, access hash. A min community is skipped, because its access hash works only in the update that carried it.withParamsclient. A community gets nochat_sync_staterow and isn't added tovisited. 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 infetchChatsFromApi. 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 withINVALID_ARGS(exit 3), writes nothing and points at the linked supergroups and channels.--offand--autostill work.cli-commands.md,database-schema.mdandsync-strategy.mdno 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 realTelegramClientwith a mocked_client.callgets the signal and keeps only the community and the communityForbidden (it drops the min community and the channel).chats.test.ts:fetchChatsFromApicaches 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;--offstill succeeds.bun run check,bun run test(1767 pass), and the affected unit and e2e files. The threecommands.e2e.test.tstests 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