fix: 修复公众号消息读取与 Windows 中文路径兼容

- 支持从 biz_message 分片读取公众号聊天记录
- 在左侧栏增加独立的公众号折叠分组
- 为 Windows 中文数据目录建立 ASCII 路径桥接 (#12)
- 补充公众号分片、侧栏分类和路径桥接测试
This commit is contained in:
Wxw-Gu
2026-08-07 16:21:39 +08:00
parent 0b845db2e0
commit 96c67f5bf8
6 changed files with 306 additions and 36 deletions
@@ -0,0 +1,57 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { ConversationSidebar } from '../../src/renderer/src/components/conversation/ConversationSidebar'
vi.mock('@tanstack/react-virtual', () => ({
useVirtualizer: ({ count }: { count: number }) => ({
getTotalSize: () => count * 58,
getVirtualItems: () =>
Array.from({ length: count }, (_, index) => ({
index,
key: index,
start: index * 58,
size: 58
}))
})
}))
describe('ConversationSidebar', () => {
it('keeps official accounts in their own collapsible section', async () => {
render(
<ConversationSidebar
contacts={[
{
m_nsUsrName: 'gh_fixture',
m_nsNickName: '测试公众号',
md5: 'official-md5',
type: 'user',
isOfficialAccount: true
},
{
m_nsUsrName: 'wxid_fixture',
m_nsNickName: '测试联系人',
md5: 'contact-md5',
type: 'user'
}
]}
selectedContact={null}
onSelectContact={vi.fn()}
onSearch={vi.fn()}
onContentFilter={vi.fn()}
width={320}
selfInfo={null}
dbReady
onOpenSettings={vi.fn()}
onRefresh={vi.fn(async () => undefined)}
/>
)
expect(screen.getByRole('button', { name: '公众号 (1)' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: '联系人 (1)' })).toBeInTheDocument()
expect(screen.queryByText('测试公众号')).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: '公众号 (1)' }))
expect(screen.getByText('测试公众号')).toBeInTheDocument()
})
})
+61 -2
View File
@@ -1,5 +1,12 @@
import { describe, expect, it, vi } from 'vitest'
import { Wcdb4Client, type Wcdb4Message } from '../../src/main/wcdb4-client'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import {
resolveWindowsNativeAccountRoot,
Wcdb4Client,
type Wcdb4Message
} from '../../src/main/wcdb4-client'
const message = (id: string, year: number, serverId = `server-${id}`): Wcdb4Message => ({
mesLocalID: id,
@@ -12,6 +19,12 @@ const message = (id: string, year: number, serverId = `server-${id}`): Wcdb4Mess
})
describe('WCDB message shard pagination', () => {
const temporaryDirectories: string[] = []
afterEach(() => {
for (const directory of temporaryDirectories.splice(0)) fs.removeSync(directory)
})
it('keeps messages whose local ids repeat across database shards', async () => {
const cursor = vi.fn(async () => [
message('1', 2024, 'server-2024'),
@@ -57,4 +70,50 @@ describe('WCDB message shard pagination', () => {
client.getMessagesAsync('fixture@chatroom', undefined, 1_767_225_600, { limit: 20 })
).rejects.toThrow('无法检查历史消息分片')
})
it('falls back to biz_message shards for official-account sessions', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wxe-biz-shards-'))
temporaryDirectories.push(root)
const messageRoot = path.join(root, 'db_storage', 'message')
fs.ensureDirSync(messageRoot)
const bizDbPath = path.join(messageRoot, 'biz_message_0.db')
fs.writeFileSync(bizDbPath, '')
const client = Object.assign(Object.create(Wcdb4Client.prototype), {
dbStoragePath: path.join(root, 'db_storage'),
wcdbGetMessageTableStats: null,
wcdbExecQuery: vi.fn(),
callJson: vi.fn(() => [{ name: 'Msg_19cde0e21f4f938ca1fcebd7146dbbd2' }])
}) as Wcdb4Client
const stores = Reflect.get(client, 'listMessageStores').call(client, 'gh_23069e016533')
expect(stores).toEqual([
{
tableName: 'Msg_19cde0e21f4f938ca1fcebd7146dbbd2',
dbPath: bizDbPath
}
])
})
it('creates a stable ASCII junction for a Windows account path containing Chinese', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wxe-path-bridge-'))
temporaryDirectories.push(root)
const publicRoot = path.join(root, 'Public')
const accountRoot = path.join(root, '微信聊天记录', 'wxid_fixture')
fs.ensureDirSync(path.join(accountRoot, 'db_storage'))
const first = resolveWindowsNativeAccountRoot(accountRoot, {
platform: 'win32',
publicRoot
})
const second = resolveWindowsNativeAccountRoot(accountRoot, {
platform: 'win32',
publicRoot
})
expect(first).toBe(second)
expect(first).not.toContain('微信聊天记录')
expect(fs.realpathSync(first)).toBe(fs.realpathSync(accountRoot))
})
})