From 776131b1de214dbdf1dd5c267610b7b188c1b9e2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 16 Sep 2026 11:47:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E5=85=A8=E6=96=B0=E5=A5=BD?= =?UTF-8?q?=E5=8F=8B=E5=85=B3=E7=B3=BB=E4=B8=8D=E4=BC=9A=E7=AB=8B=E5=8D=B3?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E5=9C=A8=E4=BC=9A=E8=AF=9D=E5=88=97=E8=A1=A8?= =?UTF-8?q?/=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一条commit修的是"消息本身发不出去",这条修的是同一个根因链条上更早 一环:SDK只对`me`话题的onMetaSub/onSubsUpdated两个回调做了这个"联系 人变化了"的通知(读tinode.dev.js确认:无论是哪个话题触发的订阅,SDK 永远只调用me.onMetaSub/me.onSubsUpdated,不是触发订阅的那个话题自己 的回调),但这个项目的wireTopicCallbacks只接了onSubsUpdated,漏了 onMetaSub——这正是brand-new P2P话题从usr别名被服务端改名成真实 p2p...哈希的那一刻,SDK唯一会触发的两个回调之一。 现在两个回调都接上、都指向同一个notify(),会话列表和ConversationView 自己的contact查找(决定头部显示真实昵称还是裸id、在线还是离线)应该 能在好友关系刚建立、还没有任何一方发过消息时就正确更新,不用等一次不 相关的全量重连才被动捡回正确状态。 Co-Authored-By: Claude Sonnet 5 --- web/src/lib/tinode/tinode-sdk.d.ts | 8 ++++++++ web/src/lib/tinode/topics.ts | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/web/src/lib/tinode/tinode-sdk.d.ts b/web/src/lib/tinode/tinode-sdk.d.ts index 89544a37..c519d8e8 100644 --- a/web/src/lib/tinode/tinode-sdk.d.ts +++ b/web/src/lib/tinode/tinode-sdk.d.ts @@ -246,6 +246,14 @@ declare module 'tinode-sdk' { onAllMessagesReceived?: (count: number) => void; onInfo?: (info: { what: 'read' | 'recv' | 'kp' | 'call'; seq?: number; from?: string; event?: string; payload?: Record }) => void; onMetaDesc?: (desc: unknown) => void; + /** `me`-topic-only in practice (verified tinode.dev.js:4654-4657): fired with the just-subscribed + * Topic itself the moment a brand-new contact's subscribe resolves -- notably including the + * usr-alias -> real-topic-name rename case (Topic#subscribe, same code block that updates + * `this.name`). Distinct from `onSubsUpdated` below (which the SDK ALSO fires in that same + * block, with just the name/count) -- wired to the identical notify callback here since both + * ultimately mean the same thing for this app's purposes: "the chat list's contact set changed, + * recompute it." */ + onMetaSub?: (topic: Topic) => void; onSubsUpdated?: (subs: string[], count?: number) => void; onPres?: (pres: unknown) => void; onAuxUpdated?: (aux: unknown) => void; diff --git a/web/src/lib/tinode/topics.ts b/web/src/lib/tinode/topics.ts index 190dc5a9..b958211b 100644 --- a/web/src/lib/tinode/topics.ts +++ b/web/src/lib/tinode/topics.ts @@ -73,6 +73,15 @@ function wireTopicCallbacks(topic: Topic) { if (info) infoListeners.forEach((cb) => cb(topic.name, info)); }; topic.onMetaDesc = notify; + // Only ever actually invoked on the `me` topic (the SDK reads `me.onMetaSub`/`me.onSubsUpdated` + // specifically, regardless of which topic's subscribe triggered it -- confirmed tinode.dev.js: + // 4654-4659) -- wiring it here on every topic is a no-op for anything else, same as onSubsUpdated + // right below, which already gets this same treatment. Without this, a brand-new P2P conversation + // reached by the other user's `usr...` id (no established topic yet) never tells the chat list a + // new contact exists the instant the server assigns its real `p2p...` name on first subscribe -- + // the contact stays invisible in the sidebar, and ConversationView's own `contact` lookup (peer + // name, online status) keeps missing until some UNRELATED full resync happens to pick it up. + topic.onMetaSub = notify; topic.onSubsUpdated = notify; topic.onPres = notify; topic.onAuxUpdated = notify;