Repository navigation
fix(send): resolve @username through Telegram for writes - #222
Merged
Merged
Conversation
A username can move to another user or chat while its previous owner keeps it in the cache, so tg send, tg messages read and tg api write methods could act on the old owner. Writes now resolve @username with contacts.resolveUsername, the allowedChats check included. Reads stay cache-first and take the latest fetched owner of a username. Refs #217 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rough Telegram The write's own @username resolved through Telegram while the list stayed cache-first, so after a username moved the check allowed its previous owner by ID, and refused the chat that holds it now when a user kept the name in the cache. The list now resolves the same way as the target, as docs/configuration.md says. Refs #217 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/test/fake-client-cli.test-utils.ts
Merged
This was referenced Nov 20, 2026
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
The stale
@usernamepart of #217. A username can move to another user or chat, and its previous owner keeps it inusers_cache/chats_cacheuntil fetched again, sotg send --to @namecould send to the old owner.tg send,tg messages read, atg apimethod that is not a read) resolve@usernamewithcontacts.resolveUsername, never from the cache (freshUsername).allowedChatscheck of a write resolves both its target and the list's@usernameentries that way. docs/configuration.md says the chat and the list resolve the same way. With only the target fresh, two cases broke after a username moved, and both are reproduced:An
@nameentry now allows the chat that holds it now.getByUsernamein both caches returns the latest fetched owner, so reads converge once the new owner is fetched. Reads and the cross-chat lists stay cache-first.Cost: one
contacts.resolveUsernameper write by@username, plus one per@usernameentry inallowedChats. Telegram rate-limits that method. Use IDs, in--toand in the list, to avoid it. UnderallowedChats, a write now needs a connection even to be refused when the list has@usernameentries.Refs #217. Follows #220.
How I checked it
New tests, each failing before its fix:
@testuser→ user 123456, Telegram says 654321: the send goes to 654321;@testuserstale on 123456, now on user 654321:--to 123456isCHAT_NOT_ALLOWED;@testusermoved from a cached user to channel 777:--to @testuseris sent to the channel.contacts.resolveUsernamecalls: target and list.bun run check,bun run test(1209 pass),bun run test:e2e(339 pass),bun run build. The e2e allowedChats refusals oftg sendandtg messages readnow run on the fake client, which answerscontacts.resolveUsernamefor its made-up@aliceand@teamchat.Live, on a snapshot of the owner's session in a temp data dir:
bun run test:integration7/7.tg send --to @<own username>resolved throughcontacts.resolveUsernameand landed in Saved Messages. WithTELEGRAM_SYNC_CLI_ALLOWED_CHATS=@<own username>,tg send --to mewas allowed (the list resolved through Telegram) and--to 777000wasCHAT_NOT_ALLOWED. Both test messages were then deleted (messages.getMessagesreturnsmessageEmpty).Merged with
mainat 0.15.0. This entry stays under[Unreleased].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
🤖 Generated with Claude Code