排查转发bug同类问题:修复查找聊天记录崩溃 + 复制功能复制出"undefined"
审查了所有"读取消息content做数据处理"的地方,找到两处和转发bug同一根因 (手机端扁平非Drafty内容格式)的真实问题: 1. 查找聊天记录(HistorySearchModal)的搜索结果渲染,对手机端发送的图片/文件/ 语音/视频/名片消息命中关键词时会让整个应用崩溃——Drafty.toPlainText在这 类扁平内容上返回undefined,highlightMatches对undefined调用.toLowerCase() 直接抛异常,而这个应用完全没有错误边界(ErrorBoundary)兜底,等于白屏。 已用真实搜索接口返回确认snapshot里其实带着head字段(此前SearchHit类型 没建模),据此在渲染前识别这几种扁平内容并显示[图片]/[文件]/[语音]/[名片] 这样的占位文案,不再无脑喂给renderDrafty;顺手给highlightMatches补了防御 性判空,避免类似疏漏再次崩溃整个应用。 2. 消息右键菜单"复制"功能,对手机端发送的扁平文本消息(如群公告自动发布的 那条)和图片/文件/语音/视频消息,复制到剪贴板的是字面字符串"undefined"。 文本类修成正确提取真实文本;附件类直接从"复制"这个操作里去掉(参考名片/ 通话记录消息已有的排除逻辑),复制一段JSON式的附件数据本来就没有意义。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
eb0a6eba7e
commit
105ff76959
@@ -65,6 +65,14 @@ export interface SearchHit {
|
||||
// other Drafty consumer in this app, discovered here because a real search hit for a plain-text
|
||||
// message rendered as blank space until this was fixed (see HistorySearchModal's SnapshotContent).
|
||||
content?: DraftyContent | string;
|
||||
// Confirmed LIVE (2026-09-24, a real mobile-sent flat-text hit): the snapshot also carries the
|
||||
// original message's `head`, same as favorites.ts's own snapshot already documents. Needed to
|
||||
// recognize a mobile-sent flat content shape (`{text:...}`/`{file_id,...}`/etc., tagged only by
|
||||
// `head['x-im-type']`) BEFORE handing `content` to renderDrafty -- that flat shape isn't a real
|
||||
// Drafty document, and used to crash the whole search modal (no `.txt`/`.text` field `renderDrafty`
|
||||
// recognizes -> `Drafty.toPlainText` returns `undefined` -> highlightMatches() called `.toLowerCase()`
|
||||
// on it). See HistorySearchModal's SnapshotContent for the fix.
|
||||
head?: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user