From 224308f0e0c1b1a3ba8be7d49ff843559742512b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= <969409112@qq.com> Date: Sun, 2 Aug 2026 16:20:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20macOS=20=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E6=98=B5=E7=A7=B0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit be092c64e528cfc363f0ddd32c480eea5532799f) --- src/main/services/chat-service.ts | 4 +++- tests/unit/chat-service.test.ts | 39 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/unit/chat-service.test.ts diff --git a/src/main/services/chat-service.ts b/src/main/services/chat-service.ts index 10c4686..13494b3 100644 --- a/src/main/services/chat-service.ts +++ b/src/main/services/chat-service.ts @@ -179,7 +179,9 @@ export function listContacts(filter?: string): FormattedContact[] { export async function listContactsAsync(filter?: string): Promise { if (!dbRef) return [] await dbRef.getWcdb4Client().getSessionsAsync({ - hydrateDisplayNames: false, + // macOS session rows frequently contain only wxid/chatroom ids. Hydrate + // contact display names before exposing the list to the renderer. + hydrateDisplayNames: true, hydrateStatuses: true }) return listContacts(filter) diff --git a/tests/unit/chat-service.test.ts b/tests/unit/chat-service.test.ts new file mode 100644 index 0000000..a24409d --- /dev/null +++ b/tests/unit/chat-service.test.ts @@ -0,0 +1,39 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import type { WechatDb } from '../../src/main/wechat-db' +import { listContactsAsync, setChatDb } from '../../src/main/services/chat-service' + +describe('chat service contacts', () => { + afterEach(() => setChatDb(null)) + + it('hydrates display names before returning macOS-style session ids', async () => { + const session = { + username: '57101206391@chatroom', + nickname: '57101206391@chatroom' + } + const getSessionsAsync = vi.fn(async (options: { hydrateDisplayNames?: boolean }) => { + if (options.hydrateDisplayNames) session.nickname = '测试群聊' + return [session] + }) + const fakeDb = { + close: vi.fn(), + md5: () => 'fixture-md5', + getAllGroupContacts: () => ({ fixture: session.nickname }), + getUserList: () => [ + { + m_nsUsrName: session.username, + nickname: session.nickname + } + ], + getWcdb4Client: () => ({ getSessionsAsync }) + } as unknown as WechatDb + + setChatDb(fakeDb) + const contacts = await listContactsAsync() + + expect(getSessionsAsync).toHaveBeenCalledWith({ + hydrateDisplayNames: true, + hydrateStatuses: true + }) + expect(contacts[0]?.m_nsNickName).toBe('测试群聊') + }) +})