Repository navigation
feat: list unread messages and mark chats read - #167
Merged
Merged
Conversation
tg chats list --unread lists only chats with unread messages, and every chat item has unreadCount. tg messages unread prints each chat's oldest unread messages from the cache, with the unread count and how many of them the cache lacks; --fresh reads both from Telegram. tg messages read marks a chat read with messages.readHistory or channels.readHistory and caches the chat's new unread state. chats_cache gets unread_count and read_inbox_max_id from the dialog list. The daemon raises the count for each new incoming message and takes reads on other devices from updateReadHistoryInbox and updateReadChannelInbox, so the counts stay current between dialog passes. Fixes #25 Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
feat/unread
branch
from
November 17, 2026 20:39
f81f757 to
5d23b93
Compare
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
"Summarize my unread messages" is a headline agent workflow, but
tgcould neither list unread chats or messages nor mark them read. The cache did not store any unread state either:chats_cachehad no unread column.tg chats list --unreadlists only chats with unread messages. The order is the same as without the flag, and every chat item now hasunreadCount.tg messages unread [--chat <peer>] [--limit N]shows, for each chat with unread messages, its oldest unread messages from the cache: incoming ones above the read boundary, newest first, at most--limitper chat. Each chat also getsunreadCount,readInboxMaxId,returned,missing(unread messages the cache doesn't hold, which is common in large groups and channels the daemon doesn't sync) andnextAfter.--freshreads the counts from Telegram and fetches the first unread page of each chat that is missing messages.tg messages read --chat <peer> [--max-id <id>]callsmessages.readHistoryfor private chats, basic groups and Saved Messages, andchannels.readHistoryfor supergroups and channels. The default max_id is 0, which marks everything read. It then reads the dialog back (messages.getPeerDialogs) and caches the new unread count and boundary. Marking read happens only in the CLI. The daemon stays read-only.chats_cachegets two new columns,unread_countandread_inbox_max_id. Old caches get them throughensureColumnand they start as NULL. Every dialog list sets them. Other writes to the row keep them.last_message_idadds one, so a message delivered twice counts once.updateReadHistoryInboxandupdateReadChannelInboxset both values fromstillUnreadCount. Reads inside a single forum topic are skipped.last_message_idandlast_message_at.Before / After
Before:
tg chats list --unreadfailed with an unknown flag.tg messages unreadandtg messages readdid not exist.After:
{ "chats": [ { "chat": { "id": -1001234567890, "title": "Team Chat", "username": "teamchat", "type": "supergroup" }, "unreadCount": 5, "readInboxMaxId": 20, "missing": 3, "returned": 2, "nextAfter": 25, "items": [ … ], "source": "cache" } ], "unreadCount": 5, "missing": 3, "returned": 2, "limit": 20, "source": "cache", "stale": false }{ "chatId": -1001234567890, "maxId": null, "method": "channels.readHistory", "unreadCount": 0, "readInboxMaxId": 30 }Testing
bun run checkbun run test: 2266 pass. The newsrc/__tests__/read-state.test.tsuses a mocked client and checks:--freshfetches--unreadfilter worksbun run test:e2e: 379 pass. The newsrc/__e2e__/unread.e2e.test.tscovers:chats list --unreadandmessages unreadfrom a seeded cache with no credentialsmessages readfor a private chat, a basic group, a supergroup and a channel. These run through the fake Telegram client thattg api's e2e already uses, extended to answerreadHistoryandgetPeerDialogs. Each test then checks that the cached count changed.--freshNot checked offline: real Telegram behaviour of the read calls and updates. That needs a live run.
Fixes #25
🤖 Generated with Claude Code