fix: 修复 macOS 会话昵称显示

(cherry picked from commit be092c64e528cfc363f0ddd32c480eea5532799f)
This commit is contained in:
电摇小子
2026-08-03 10:08:59 +08:00
committed by Wxw-Gu
parent 3e57a8432d
commit 224308f0e0
2 changed files with 42 additions and 1 deletions
+3 -1
View File
@@ -179,7 +179,9 @@ export function listContacts(filter?: string): FormattedContact[] {
export async function listContactsAsync(filter?: string): Promise<FormattedContact[]> { export async function listContactsAsync(filter?: string): Promise<FormattedContact[]> {
if (!dbRef) return [] if (!dbRef) return []
await dbRef.getWcdb4Client().getSessionsAsync({ 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 hydrateStatuses: true
}) })
return listContacts(filter) return listContacts(filter)
+39
View File
@@ -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('测试群聊')
})
})