Repository navigation
bridge: 新 peer 的第一条消息被当成已读,没有未读标识 - #24
Open
std-external wants to merge 1 commit into
Open
std-external wants to merge 1 commit into
std-external wants to merge 1 commit into
Conversation
The stored conversation counter is the only unread state messages.getPeerDialogs can answer with. A live inbound message never touched it, so the first message of a peer the client has never seen made it request the dialog entry and get unread_count=0 with read_inbox_max_id at the message itself, which the client applied as already read: no badge, no unread divider.
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.
问题
之前没在 crossgram 聊过的人(全新 peer)发来第一条消息时,客户端没有未读标识:会话列表不显示未读数,也没有未读分割线,看起来像已经读过了。老会话再来消息一切正常。
来源:群里 Anillc 报的(「如果有人之前没在 crossgram 给我发过消息,然后给我发第一条消息之后,似乎不会有未读的标识」)。
成因
这条消息本身没丢,是服务端把他报成了「已读」。
packages/bridge/src/platform-manager.ts:428的event.type === 'message'分支只有store.ingest(),从来没动过会话的unreadCount。全仓库只有请求收件箱(message-store.ts:178)和markRead(message-store.ts:601)会写这个计数。message-store.ts:1754。messages.getPeerDialogs(Telegram Desktop 的Histories::requestDialogEntry→history.cpp:1712-1723)。dialogs.ts:519用store.readDialogs(...),_hydrateDialogs只带unreadCount和最新一条lastMessage,不带readInboxMaxMessage;于是dialogs.ts:4007算出readInboxMaxId = source.unreadCount > 0 ? 0 : topMessage,返回unreadCount: 0, readInboxMaxId: topMessage。applyDialogFields(history.cpp:3666-3681)拿到0+ 「读到最新」,把这条消息标记成已读,标识就没有了。老会话不受影响:客户端已知它的未读数(哪怕 0),来信由客户端本地 +1,不会发第 3 步那轮询问。
修复
来信落库后,如果这条消息是新行、不是自己发的、不是请求收件箱,并且该会话在库里还是 0 未读,就记成 1 未读。
packages/bridge/src/platform-manager.ts:428-446incrementConversationUnread本来就在(message-store.ts:766,之前没有任何调用点),这里给它加一个onlyWhenRead选项:只在计数为 0 时加 1。为什么只在 0 时加:
unreadCount了,无脑 +1 会把 5 条未读变成 10 条。getDialogs快照或markRead会覆盖成准确值。验证
新增
packages/bridge/src/new-peer-first-unread.e2e.test.ts,用真 store + 真事件管线(PlatformSubscriptionManager)复现,再通过messages.getPeerDialogs看客户端拿到什么:unreadCount: 1且readInboxMaxId < topMessage。修复前是{"unreadCount":0,"readInboxMaxId":1073741824}(等于最新消息 id)。跑过的:
npx vitest run packages/bridge/src:855 通过,1 失败(voice/voice-worker-client,本机缺cargo)。npx vitest run --config vitest.mtproto-e2e.config.mts packages/bridge/src:74 通过,8 失败(android-rpc / member-pagination / notification-settings ×3 / send-observer / unread-mentions ×2),与本改动无关,把改动 stash 掉后同样失败。npx tsc -p tsconfig.json --noEmit通过。后续(不在这个 PR 里)
精确计数可以把平台给的
readInboxMaxMessage/firstUnread(platform.ts:645-648已经在传)持久化到会话行,未读数改成「读点之后的来信条数」,markRead已经是这个口径(message-store.ts:601-660)。那需要加列并改ingestDialogs/readDialogs,可以另开一个任务。