Repository navigation
fix(chats): cache communities as type community with their access hash - #55
Merged
Merged
Conversation
A Telegram community (mtcute's community and communityForbidden) has a channel ID, but the chat cache typed it 'group' and kept the access hash only for channels. A community row therefore had access_hash NULL, its sync jobs built inputPeerChannel with hash 0, which Telegram may refuse, and `tg chats list --type group` listed it among basic groups. It now gets its own 'community' type, matching mtcute, because it is neither a basic group nor a channel with posts, and its access hash is kept from dialogs, raw chats and live updates like a channel's. Like a channel, it syncs only on request. `tg chats list --type community` filters on it, and the --type help, the schema annotations and the docs list the new value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The community notes promised that `tg chats list --type community` lists communities, that a community syncs on request, and that a 0.3.0 `group` row gets fixed when the community is cached again. No path can do any of that: mtcute's dialog list drops `dialogCommunity`, a message's peer is never a community, and a community has no username for `tg chats get`. So the docs now say communities aren't cached yet (#58), that one is off by default, and that its linked chats sync as the supergroups and channels they are. The legacy-row claim is gone, since no 0.3.0 version could cache a community either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What and why
Fixes #45
A Telegram community (mtcute's
communityandcommunityForbidden, a collection of linked chats) has a channel ID (-100…), but the chat cache typed itgroupand kept the access hash only forchannelandchannelForbidden. A community row would have hadaccess_hash = NULL,tg chats list --type groupwould have listed it among basic groups, and syncing it withtg chats syncwould have builtinputPeerChannelwith access hash 0, which Telegram may refuse.Now a community is mapped to type
communitywith its access hash, from a dialog (getChatTypereads mtcute'schatType === 'community'), from a raw chat (rawChatType,rawChatToCacheInput) and from a raw peer (rawPeerToCacheInput, which skips a min community like a min channel).buildInputPeerthen builds itsinputPeerChannelwith the stored hash.Why a new type: a community is neither a basic group (it has a channel ID and needs an access hash) nor a channel with posts, and mtcute reports it as its own
chatType.communityfollows mtcute and lets--typefilter on it. Like a channel it is off by default (determineSyncPolicy, andresolveSyncChatType, which used to fall back togroupand the group member-count policy). The chats linked to a community are ordinary supergroups and channels and keep their own policy.toMarkedPeerIdtakescommunitytoo (channel marking), so code that marks a stored bare ID by its chat type keeps typechecking with the widerChatType.New CLI surface
tg chats list --type community. The--typehelp and theINVALID_ARGSmessage both build the list fromCHAT_TYPE_VALUES.typevaluecommunityintg chats list/get/search/syncoutput,chat_typeintg status, andchats_cache.type/chat_sync_state.chat_type(tg sql,tg sql --schemaannotations). A script that switches on the four old values can meet it.Docs:
docs/database-schema.md(Peer IDs row, both type comments, a note on communities),docs/cli-commands.md(the--typevalues, communities in Chat sync and the cache-only bullet),docs/sync-strategy.md(Policy).Known limitations
--type communityfinds none so far; the docs say so and link Joined communities aren't cached: the dialog pass and chats list --fresh skip them #58. mtcute'sDialog.parseTlDialogskeeps onlydialogand dropsdialogCommunity, so the daemon's dialog pass andtg chats list --freshskip joined communities. A message's peer is never a community (Peeris only user, chat or channel), so live updates don't cache one, and a community has no username, sotg chats get --id @usernamecan't resolve one. Joined communities aren't cached: the dialog pass and chats list --fresh skip them #58 tracks caching them withclient.getJoinedCommunities(). This PR makes sure that once a community reaches the cache, it has the right type and hash.messages.getHistoryreturns anything for a community is unchecked (dialogCommunityhas no top message). It stays off by default; Joined communities aren't cached: the dialog pass and chats list --fresh skip them #58 covers whattg chats syncshould do for one.How I checked it
All offline, made-up IDs and titles only:
bun test --isolateon chats, sync-worker-real-context, daemon-accounts, sync-schema, telegram-peer-ids, sql and peer-id-migration: the new tests failed before the fix and pass after it.Dialogbuilt withPeersIndexfor a community givestype: 'community'with its access hash. A rawcommunityand acommunityForbiddendo the same; acommunityForbiddenwith no hash givesnull.buildInputPeerbuildsinputPeerChannelwith the cached hash for a dialog-cached and a raw-cached community.chatsCache.list({ type: 'community' })returns only the communities, andassertPeerIdInvariantspasses on a cache that holds them.CHAT_TYPE_VALUES.e2e:
tg chats list --type communityreturns only the seeded community, and an invalid--typelistscommunityin its message.bun run check,bun run test(1563 pass) andbun run test:e2e(194 pass).Tests pass locally and use made-up data only
README, docs and affected demos follow the product content standard
Title follows the repo's commit style: Conventional Commits (
feat: …,fix: …) unlessAGENTS.mdsays otherwise🤖 Generated with Claude Code