Skip to content

fix(send): resolve @username through Telegram for writes - #222

Merged
neoromantic merged 4 commits into
mainfrom
fix/217-fresh-username
Nov 19, 2026
Merged

neoromantic merged 4 commits into
mainfrom
fix/217-fresh-username

Conversation

@neoromantic

@neoromantic neoromantic commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

What and why

The stale @username part of #217. A username can move to another user or chat, and its previous owner keeps it in users_cache/chats_cache until fetched again, so tg send --to @name could send to the old owner.

  • Writes (tg send, tg messages read, a tg api method that is not a read) resolve @username with contacts.resolveUsername, never from the cache (freshUsername).
  • The allowedChats check of a write resolves both its target and the list's @username entries 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:
    • the previous owner, sent to by ID, was allowed (bypass);
    • the chat that holds the name now was refused when a user kept the name in the cache.
      An @name entry now allows the chat that holds it now.
  • getByUsername in 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.resolveUsername per write by @username, plus one per @username entry in allowedChats. Telegram rate-limits that method. Use IDs, in --to and in the list, to avoid it. Under allowedChats, a write now needs a connection even to be refused when the list has @username entries.

Refs #217. Follows #220.

How I checked it

  • New tests, each failing before its fix:

    • stale cache @testuser → user 123456, Telegram says 654321: the send goes to 654321;
    • list @testuser stale on 123456, now on user 654321: --to 123456 is CHAT_NOT_ALLOWED;
    • @testuser moved from a cached user to channel 777: --to @testuser is sent to the channel.
    • The guard test from fix: act on the checked target, refuse undeclared flags, keep done calls done #220 now expects exactly two contacts.resolveUsername calls: target and list.
  • bun run check, bun run test (1209 pass), bun run test:e2e (339 pass), bun run build. The e2e allowedChats refusals of tg send and tg messages read now run on the fake client, which answers contacts.resolveUsername for its made-up @alice and @teamchat.

  • Live, on a snapshot of the owner's session in a temp data dir: bun run test:integration 7/7. tg send --to @<own username> resolved through contacts.resolveUsername and landed in Saved Messages. With TELEGRAM_SYNC_CLI_ALLOWED_CHATS=@<own username>, tg send --to me was allowed (the list resolved through Telegram) and --to 777000 was CHAT_NOT_ALLOWED. Both test messages were then deleted (messages.getMessages returns messageEmpty).

  • Merged with main at 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

neoromantic and others added 4 commits November 19, 2026 17:38
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
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.

1 participant