mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
fix: 更新打包配置并修复群昵称刷新
更新跨平台 WCDB 和运行时命名。 优化消息获取速度 修复群昵称刷新回退与消息发送者显示,并增加可控的消息读取诊断日志和有界查询优化。
This commit is contained in:
1 parent
fc54c3b946
commit
47e0d7cd1e
25 files changed
+415
-148
No files matched your search
@@ -603,23 +603,49 @@ export function saveCachedGroupSnapshot(
|
||||
accountRoot: string,
|
||||
userMd5: string,
|
||||
snapshot: CachedGroupSnapshot
|
||||
): void {
|
||||
): CachedGroupSnapshot {
|
||||
const normalizedRoot = normalizeRoot(accountRoot)
|
||||
if (!normalizedRoot || !userMd5) return
|
||||
if (!normalizedRoot || !userMd5) return snapshot
|
||||
const paths = getAccountCachePaths(normalizedRoot)
|
||||
const file = getGroupCacheFile(normalizedRoot, userMd5)
|
||||
const previous = readGroupSnapshotFile(normalizedRoot, userMd5)?.snapshot
|
||||
const previousByWxid = new Map((previous?.members || []).map((member) => [member.wxid, member]))
|
||||
const mergedSnapshot: CachedGroupSnapshot = previous && previous.roomId === snapshot.roomId
|
||||
? {
|
||||
...snapshot,
|
||||
members: snapshot.members.map((member) => {
|
||||
const oldMember = previousByWxid.get(member.wxid)
|
||||
const freshGroupNickname = String(member.groupNickname || '').trim()
|
||||
const freshWechatNickname = String(member.wechatNickname || '').trim()
|
||||
const oldGroupNickname = String(oldMember?.groupNickname || '').trim()
|
||||
const freshLooksLikeContactFallback =
|
||||
!freshGroupNickname ||
|
||||
freshGroupNickname === freshWechatNickname
|
||||
const groupNickname =
|
||||
freshLooksLikeContactFallback && oldGroupNickname
|
||||
? oldGroupNickname
|
||||
: freshGroupNickname
|
||||
return {
|
||||
...member,
|
||||
groupNickname,
|
||||
nickname: groupNickname || member.nickname
|
||||
}
|
||||
})
|
||||
}
|
||||
: snapshot
|
||||
const value: CachedGroupSnapshotFile = {
|
||||
version: CACHE_VERSION,
|
||||
platform: process.platform,
|
||||
accountRoot: normalizedRoot,
|
||||
userMd5,
|
||||
updatedAt: Date.now(),
|
||||
snapshot
|
||||
snapshot: mergedSnapshot
|
||||
}
|
||||
touchMemory(groupMemory, file, value, MAX_MEMORY_GROUP_SNAPSHOTS)
|
||||
scheduleWrite(file, value, {
|
||||
prune: { directory: paths.groups, maxFiles: MAX_GROUP_SNAPSHOTS }
|
||||
})
|
||||
return mergedSnapshot
|
||||
}
|
||||
|
||||
export function saveCachedMessages(
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from '../../shared/windows-runtime'
|
||||
import { mergeRecallArchiveMessages, recordRecallArchiveMessages } from './recall-archive-service'
|
||||
import type { ExportImageQuality } from '../../shared/image-quality'
|
||||
import { wcdbDebugLog } from '../wcdb-debug'
|
||||
|
||||
export function getCurrentKey(): string {
|
||||
if (!dbRef) return ''
|
||||
@@ -226,7 +227,8 @@ function listSourceMessages(
|
||||
startTime?: number,
|
||||
endTime?: number,
|
||||
options?: { limit?: number },
|
||||
rawMessagesOverride?: WechatMessage[]
|
||||
rawMessagesOverride?: WechatMessage[],
|
||||
requestId = 'NO-REQUEST'
|
||||
): FormattedMessage[] {
|
||||
if (!dbRef) return []
|
||||
|
||||
@@ -234,13 +236,13 @@ function listSourceMessages(
|
||||
const wcdb4Client = dbRef.getWcdb4Client()
|
||||
const username = wcdb4Client.getUsernameByMd5(userMd5)
|
||||
const isGroupChat = Boolean(username?.endsWith('@chatroom'))
|
||||
console.log(
|
||||
`[ChatService] listMessages begin md5=${userMd5} username=${username || ''} start=${startTime || 0} end=${endTime || 0} limit=${options?.limit || 0}`
|
||||
wcdbDebugLog(
|
||||
`[${requestId}] ChatService listSourceMessages start md5=${userMd5} username=${username || ''} start=${startTime || 0} end=${endTime || 0} limit=${options?.limit || 0}`
|
||||
)
|
||||
const rawMessages =
|
||||
rawMessagesOverride ?? dbRef.getUserMessages(userMd5, startTime, endTime, options)
|
||||
console.log(
|
||||
`[ChatService] listMessages native done md5=${userMd5} raw=${rawMessages.length} cost=${Date.now() - startedAt}ms`
|
||||
wcdbDebugLog(
|
||||
`[${requestId}] ChatService raw snapshot ready raw=${rawMessages.length} cost=${Date.now() - startedAt}ms`
|
||||
)
|
||||
|
||||
const formatted = rawMessages.map((msg: WechatMessage) => {
|
||||
@@ -447,14 +449,43 @@ export async function listMessagesAsync(
|
||||
userMd5: string,
|
||||
startTime?: number,
|
||||
endTime?: number,
|
||||
options?: { limit?: number }
|
||||
options?: { limit?: number },
|
||||
requestId = 'NO-REQUEST'
|
||||
): Promise<FormattedMessage[]> {
|
||||
if (!dbRef) return []
|
||||
const rawMessages = await dbRef.getUserMessagesAsync(userMd5, startTime, endTime, options)
|
||||
const sourceMessages = listSourceMessages(userMd5, startTime, endTime, options, rawMessages)
|
||||
const startedAt = Date.now()
|
||||
wcdbDebugLog(`[${requestId}] ChatService listMessagesAsync start md5=${userMd5}`)
|
||||
const rawMessages = await dbRef.getUserMessagesAsync(
|
||||
userMd5,
|
||||
startTime,
|
||||
endTime,
|
||||
options,
|
||||
requestId
|
||||
)
|
||||
wcdbDebugLog(
|
||||
`[${requestId}] ChatService getUserMessagesAsync end raw=${rawMessages.length} cost=${Date.now() - startedAt}ms`
|
||||
)
|
||||
const sourceMessages = listSourceMessages(
|
||||
userMd5,
|
||||
startTime,
|
||||
endTime,
|
||||
options,
|
||||
rawMessages,
|
||||
requestId
|
||||
)
|
||||
const username = dbRef.getWcdb4Client().getUsernameByMd5(userMd5) || ''
|
||||
recordRecallArchiveMessages(userMd5, username, sourceMessages)
|
||||
return mergeRecallArchiveMessages(userMd5, sourceMessages, startTime, endTime, options?.limit)
|
||||
const result = mergeRecallArchiveMessages(
|
||||
userMd5,
|
||||
sourceMessages,
|
||||
startTime,
|
||||
endTime,
|
||||
options?.limit
|
||||
)
|
||||
wcdbDebugLog(
|
||||
`[${requestId}] ChatService listMessagesAsync end formatted=${result.length} cost=${Date.now() - startedAt}ms`
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
||||
export async function listMessagesForExport(
|
||||
|
||||
@@ -58,7 +58,6 @@ function getDefaultDbRootCandidates(home: string): string[] {
|
||||
// 仅支持 WeChat 4.0:剔除 V3 时代的 "WeChat Files" 目录,
|
||||
// 只认 xwechat_files(含 Documents\ 和 AppData\Roaming\Tencent\ 两种合法位置)。
|
||||
const candidates = [
|
||||
...getWeflowDbPathCandidates(home),
|
||||
path.join(home, 'Documents', 'xwechat_files'),
|
||||
path.join(os.homedir(), 'AppData', 'Roaming', 'Tencent', 'xwechat_files')
|
||||
]
|
||||
@@ -66,25 +65,6 @@ function getDefaultDbRootCandidates(home: string): string[] {
|
||||
return unique(candidates)
|
||||
}
|
||||
|
||||
function getWeflowDbPathCandidates(home: string): string[] {
|
||||
const configPaths = [
|
||||
path.join(home, 'AppData', 'Roaming', 'weflow', 'WeFlow-config.json'),
|
||||
path.join(home, 'AppData', 'Roaming', 'WeFlow', 'WeFlow-config.json')
|
||||
]
|
||||
const candidates: string[] = []
|
||||
for (const configPath of configPaths) {
|
||||
try {
|
||||
const config = fs.readJsonSync(configPath) as { dbPath?: unknown }
|
||||
if (typeof config.dbPath === 'string' && config.dbPath.trim()) {
|
||||
candidates.push(config.dbPath.trim())
|
||||
}
|
||||
} catch {
|
||||
// WeFlow is optional; ignore missing or unreadable config.
|
||||
}
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
function unique(values: string[]): string[] {
|
||||
return Array.from(new Set(values))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user