From 33b4249bd590d62b97aa99d2bdf6a00f5fbf224a Mon Sep 17 00:00:00 2001 From: jackwener Date: Thu, 16 Apr 2026 17:22:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF/?= =?UTF-8?q?=E6=92=A4=E5=9B=9E=E6=B6=88=E6=81=AF=E8=A7=A3=E6=9E=90=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - type 10000 (系统消息): 解析 标签,显示 [系统] 内容 - type 10002 (撤回): 解析 ,显示 [撤回] 内容 - type 34 (语音) / 43 (视频): 之前漏了,现在显示 [语音]/[视频] - 避免 raw XML 出现在 history/watch 输出中 --- src/daemon/query.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/daemon/query.rs b/src/daemon/query.rs index 0904a85..30bcc81 100644 --- a/src/daemon/query.rs +++ b/src/daemon/query.rs @@ -647,8 +647,12 @@ fn fmt_content(local_id: i64, local_type: i64, content: &str, is_group: bool) -> let base = (local_type as u64 & 0xFFFFFFFF) as i64; match base { 3 => return format!("[图片] local_id={}", local_id), + 34 => return "[语音]".into(), + 43 => return "[视频]".into(), 47 => return "[表情]".into(), 50 => return "[通话]".into(), + 10000 => return parse_sysmsg(content).unwrap_or_else(|| "[系统消息]".into()), + 10002 => return parse_revoke(content).unwrap_or_else(|| "[撤回了一条消息]".into()), _ => {} } @@ -666,6 +670,37 @@ fn fmt_content(local_id: i64, local_type: i64, content: &str, is_group: bool) -> text.to_string() } +/// 解析撤回消息 XML,提取被撤回的内容摘要 +/// `...` +fn parse_revoke(xml: &str) -> Option { + let inner = extract_xml_text(xml, "content")?; + // 有时 content 是 "xxx recalled a message" 英文,有时是中文 + if inner.is_empty() { + return Some("[撤回了一条消息]".into()); + } + // 尝试简化:如果是 XML 格式的撤回内容,直接显示摘要 + Some(format!("[撤回] {}", inner + .chars() + .take(30) + .collect::())) +} + +/// 解析系统消息 XML(群通知等) +fn parse_sysmsg(xml: &str) -> Option { + // 常见格式:... + // 尝试提取 content 标签 + if let Some(s) = extract_xml_text(xml, "content") { + if !s.is_empty() { + return Some(format!("[系统] {}", s.chars().take(50).collect::())); + } + } + // 纯文本系统消息(无 XML) + if !xml.starts_with('<') { + return Some(format!("[系统] {}", xml.chars().take(50).collect::())); + } + Some("[系统消息]".into()) +} + fn parse_appmsg(text: &str) -> Option { // 简单 XML 解析,避免引入重量级 XML 库(或直接用 minidom) // 这里用基本字符串搜索实现