Skip to content

fix(chats): cache communities as type community with their access hash - #55

Merged
neoromantic merged 2 commits into
mainfrom
fix/community-chats-45
Oct 21, 2026
Merged

neoromantic merged 2 commits into
mainfrom
fix/community-chats-45

Conversation

@neoromantic

@neoromantic neoromantic commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

What and why

Fixes #45

A Telegram community (mtcute's community and communityForbidden, a collection of linked chats) has a channel ID (-100…), but the chat cache typed it group and kept the access hash only for channel and channelForbidden. A community row would have had access_hash = NULL, tg chats list --type group would have listed it among basic groups, and syncing it with tg chats sync would have built inputPeerChannel with access hash 0, which Telegram may refuse.

Now a community is mapped to type community with its access hash, from a dialog (getChatType reads mtcute's chatType === 'community'), from a raw chat (rawChatType, rawChatToCacheInput) and from a raw peer (rawPeerToCacheInput, which skips a min community like a min channel). buildInputPeer then builds its inputPeerChannel with 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. community follows mtcute and lets --type filter on it. Like a channel it is off by default (determineSyncPolicy, and resolveSyncChatType, which used to fall back to group and the group member-count policy). The chats linked to a community are ordinary supergroups and channels and keep their own policy.

toMarkedPeerId takes community too (channel marking), so code that marks a stored bare ID by its chat type keeps typechecking with the wider ChatType.

New CLI surface

  • tg chats list --type community. The --type help and the INVALID_ARGS message both build the list from CHAT_TYPE_VALUES.
  • New type value community in tg chats list / get / search / sync output, chat_type in tg status, and chats_cache.type / chat_sync_state.chat_type (tg sql, tg sql --schema annotations). 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 --type values, communities in Chat sync and the cache-only bullet), docs/sync-strategy.md (Policy).

Known limitations

How I checked it

All offline, made-up IDs and titles only:

  • bun test --isolate on 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.

    • A real mtcute Dialog built with PeersIndex for a community gives type: 'community' with its access hash. A raw community and a communityForbidden do the same; a communityForbidden with no hash gives null.
    • buildInputPeer builds inputPeerChannel with the cached hash for a dialog-cached and a raw-cached community.
    • chatsCache.list({ type: 'community' }) returns only the communities, and assertPeerIdInvariants passes on a cache that holds them.
    • The schema annotation enum values equal CHAT_TYPE_VALUES.
  • e2e: tg chats list --type community returns only the seeded community, and an invalid --type lists community in its message.

  • bun run check, bun run test (1563 pass) and bun 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: …) unless AGENTS.md says otherwise

🤖 Generated with Claude Code

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]>
@neoromantic
neoromantic merged commit 285b2eb into main Oct 21, 2026
5 checks passed
@neoromantic
neoromantic deleted the fix/community-chats-45 branch October 21, 2026 21:54
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.

Community chats are cached as groups without an access hash

1 participant