mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
修复
This commit is contained in:
@@ -177,26 +177,258 @@ class DualReportService {
|
||||
return `${month}/${day} ${hour}:${minute}`
|
||||
}
|
||||
|
||||
private extractEmojiUrl(content: string): string | undefined {
|
||||
if (!content) return undefined
|
||||
const attrMatch = /cdnurl\s*=\s*['"]([^'"]+)['"]/i.exec(content)
|
||||
if (attrMatch) {
|
||||
let url = attrMatch[1].replace(/&/g, '&')
|
||||
try {
|
||||
if (url.includes('%')) {
|
||||
url = decodeURIComponent(url)
|
||||
}
|
||||
} catch { }
|
||||
return url
|
||||
private getRecordField(record: Record<string, any> | undefined | null, keys: string[]): any {
|
||||
if (!record) return undefined
|
||||
for (const key of keys) {
|
||||
if (Object.prototype.hasOwnProperty.call(record, key) && record[key] !== undefined && record[key] !== null) {
|
||||
return record[key]
|
||||
}
|
||||
}
|
||||
const tagMatch = /cdnurl[^>]*>([^<]+)/i.exec(content)
|
||||
return tagMatch?.[1]
|
||||
return undefined
|
||||
}
|
||||
|
||||
private extractEmojiMd5(content: string): string | undefined {
|
||||
private coerceNumber(raw: any): number {
|
||||
if (raw === undefined || raw === null || raw === '') return NaN
|
||||
if (typeof raw === 'number') return raw
|
||||
if (typeof raw === 'bigint') return Number(raw)
|
||||
if (Buffer.isBuffer(raw)) return parseInt(raw.toString('utf-8'), 10)
|
||||
if (raw instanceof Uint8Array) return parseInt(Buffer.from(raw).toString('utf-8'), 10)
|
||||
const parsed = parseInt(String(raw), 10)
|
||||
return Number.isFinite(parsed) ? parsed : NaN
|
||||
}
|
||||
|
||||
private coerceString(raw: any): string {
|
||||
if (raw === undefined || raw === null) return ''
|
||||
if (typeof raw === 'string') return raw
|
||||
if (Buffer.isBuffer(raw)) return this.decodeBinaryContent(raw)
|
||||
if (raw instanceof Uint8Array) return this.decodeBinaryContent(Buffer.from(raw))
|
||||
return String(raw)
|
||||
}
|
||||
|
||||
private coerceBoolean(raw: any): boolean | undefined {
|
||||
if (raw === undefined || raw === null || raw === '') return undefined
|
||||
if (typeof raw === 'boolean') return raw
|
||||
if (typeof raw === 'number') return raw !== 0
|
||||
|
||||
const normalized = String(raw).trim().toLowerCase()
|
||||
if (!normalized) return undefined
|
||||
|
||||
if (['1', 'true', 'yes', 'me', 'self', 'mine', 'sent', 'out', 'outgoing'].includes(normalized)) return true
|
||||
if (['0', 'false', 'no', 'friend', 'peer', 'other', 'recv', 'received', 'in', 'incoming'].includes(normalized)) return false
|
||||
return undefined
|
||||
}
|
||||
|
||||
private normalizeEmojiMd5(raw: string): string | undefined {
|
||||
if (!raw) return undefined
|
||||
const trimmed = raw.trim()
|
||||
if (!trimmed) return undefined
|
||||
const match = /([a-fA-F0-9]{16,64})/.exec(trimmed)
|
||||
return match ? match[1].toLowerCase() : undefined
|
||||
}
|
||||
|
||||
private normalizeEmojiUrl(raw: string): string | undefined {
|
||||
if (!raw) return undefined
|
||||
let url = raw.trim().replace(/&/g, '&')
|
||||
if (!url) return undefined
|
||||
try {
|
||||
if (url.includes('%')) {
|
||||
url = decodeURIComponent(url)
|
||||
}
|
||||
} catch { }
|
||||
return url || undefined
|
||||
}
|
||||
|
||||
private extractEmojiUrl(content: string | undefined): string | undefined {
|
||||
if (!content) return undefined
|
||||
const match = /md5="([^"]+)"/i.exec(content) || /<md5>([^<]+)<\/md5>/i.exec(content)
|
||||
return match?.[1]
|
||||
const direct = this.normalizeEmojiUrl(content)
|
||||
if (direct && /^https?:\/\//i.test(direct)) return direct
|
||||
|
||||
const attrMatch = /(?:cdnurl|thumburl)\s*=\s*['"]([^'"]+)['"]/i.exec(content)
|
||||
|| /(?:cdnurl|thumburl)\s*=\s*([^'"\s>]+)/i.exec(content)
|
||||
if (attrMatch) return this.normalizeEmojiUrl(attrMatch[1])
|
||||
|
||||
const tagMatch = /<(?:cdnurl|thumburl)>([^<]+)<\/(?:cdnurl|thumburl)>/i.exec(content)
|
||||
|| /(?:cdnurl|thumburl)[^>]*>([^<]+)/i.exec(content)
|
||||
return this.normalizeEmojiUrl(tagMatch?.[1] || '')
|
||||
}
|
||||
|
||||
private extractEmojiMd5(content: string | undefined): string | undefined {
|
||||
if (!content) return undefined
|
||||
const direct = this.normalizeEmojiMd5(content)
|
||||
if (direct && direct.length >= 24) return direct
|
||||
|
||||
const match = /md5\s*=\s*['"]([a-fA-F0-9]{16,64})['"]/i.exec(content)
|
||||
|| /md5\s*=\s*([a-fA-F0-9]{16,64})/i.exec(content)
|
||||
|| /<md5>([a-fA-F0-9]{16,64})<\/md5>/i.exec(content)
|
||||
return this.normalizeEmojiMd5(match?.[1] || '')
|
||||
}
|
||||
|
||||
private resolveEmojiOwner(item: any, content: string): boolean | undefined {
|
||||
const sentFlag = this.coerceBoolean(this.getRecordField(item, [
|
||||
'isMe',
|
||||
'is_me',
|
||||
'isSent',
|
||||
'is_sent',
|
||||
'isSend',
|
||||
'is_send',
|
||||
'fromMe',
|
||||
'from_me'
|
||||
]))
|
||||
if (sentFlag !== undefined) return sentFlag
|
||||
|
||||
const sideRaw = this.coerceString(this.getRecordField(item, ['side', 'sender', 'from', 'owner', 'role', 'direction'])).trim().toLowerCase()
|
||||
if (sideRaw) {
|
||||
if (['me', 'self', 'mine', 'out', 'outgoing', 'sent'].includes(sideRaw)) return true
|
||||
if (['friend', 'peer', 'other', 'in', 'incoming', 'received', 'recv'].includes(sideRaw)) return false
|
||||
}
|
||||
|
||||
const prefixMatch = /^\s*([01])\s*:\s*/.exec(content)
|
||||
if (prefixMatch) return prefixMatch[1] === '1'
|
||||
return undefined
|
||||
}
|
||||
|
||||
private stripEmojiOwnerPrefix(content: string): string {
|
||||
if (!content) return ''
|
||||
return content.replace(/^\s*[01]\s*:\s*/, '')
|
||||
}
|
||||
|
||||
private parseEmojiCandidate(item: any): { isMe?: boolean; md5?: string; url?: string; count: number } {
|
||||
const rawContent = this.coerceString(this.getRecordField(item, [
|
||||
'content',
|
||||
'xml',
|
||||
'message_content',
|
||||
'messageContent',
|
||||
'msg',
|
||||
'payload',
|
||||
'raw'
|
||||
]))
|
||||
const content = this.stripEmojiOwnerPrefix(rawContent)
|
||||
|
||||
const countRaw = this.getRecordField(item, ['count', 'cnt', 'times', 'total', 'num'])
|
||||
const parsedCount = this.coerceNumber(countRaw)
|
||||
const count = Number.isFinite(parsedCount) && parsedCount > 0 ? parsedCount : 0
|
||||
|
||||
const directMd5 = this.normalizeEmojiMd5(this.coerceString(this.getRecordField(item, [
|
||||
'md5',
|
||||
'emojiMd5',
|
||||
'emoji_md5',
|
||||
'emd5'
|
||||
])))
|
||||
const md5 = directMd5 || this.extractEmojiMd5(content)
|
||||
|
||||
const directUrl = this.normalizeEmojiUrl(this.coerceString(this.getRecordField(item, [
|
||||
'cdnUrl',
|
||||
'cdnurl',
|
||||
'emojiUrl',
|
||||
'emoji_url',
|
||||
'url',
|
||||
'thumbUrl',
|
||||
'thumburl'
|
||||
])))
|
||||
const url = directUrl || this.extractEmojiUrl(content)
|
||||
|
||||
return {
|
||||
isMe: this.resolveEmojiOwner(item, rawContent),
|
||||
md5,
|
||||
url,
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
private getRowInt(row: Record<string, any>, keys: string[], fallback = 0): number {
|
||||
const raw = this.getRecordField(row, keys)
|
||||
const parsed = this.coerceNumber(raw)
|
||||
return Number.isFinite(parsed) ? parsed : fallback
|
||||
}
|
||||
|
||||
private decodeRowMessageContent(row: Record<string, any>): string {
|
||||
const messageContent = this.getRecordField(row, [
|
||||
'message_content',
|
||||
'messageContent',
|
||||
'content',
|
||||
'msg_content',
|
||||
'msgContent',
|
||||
'WCDB_CT_message_content',
|
||||
'WCDB_CT_messageContent'
|
||||
])
|
||||
const compressContent = this.getRecordField(row, [
|
||||
'compress_content',
|
||||
'compressContent',
|
||||
'compressed_content',
|
||||
'WCDB_CT_compress_content',
|
||||
'WCDB_CT_compressContent'
|
||||
])
|
||||
return this.decodeMessageContent(messageContent, compressContent)
|
||||
}
|
||||
|
||||
private async scanEmojiTopFallback(
|
||||
sessionId: string,
|
||||
beginTimestamp: number,
|
||||
endTimestamp: number,
|
||||
rawWxid: string,
|
||||
cleanedWxid: string
|
||||
): Promise<{ my?: { md5: string; url?: string; count: number }; friend?: { md5: string; url?: string; count: number } }> {
|
||||
const cursorResult = await wcdbService.openMessageCursor(sessionId, 500, true, beginTimestamp, endTimestamp)
|
||||
if (!cursorResult.success || !cursorResult.cursor) return {}
|
||||
|
||||
const tallyMap = new Map<string, { isMe: boolean; md5: string; url?: string; count: number }>()
|
||||
try {
|
||||
let hasMore = true
|
||||
while (hasMore) {
|
||||
const batch = await wcdbService.fetchMessageBatch(cursorResult.cursor)
|
||||
if (!batch.success || !Array.isArray(batch.rows)) break
|
||||
|
||||
for (const row of batch.rows) {
|
||||
const localType = this.getRowInt(row, ['local_type', 'localType', 'type', 'msg_type', 'msgType', 'WCDB_CT_local_type'], 0)
|
||||
if (localType !== 47) continue
|
||||
|
||||
const rawContent = this.decodeRowMessageContent(row)
|
||||
const content = this.stripEmojiOwnerPrefix(rawContent)
|
||||
const directMd5 = this.normalizeEmojiMd5(this.coerceString(this.getRecordField(row, ['emoji_md5', 'emojiMd5', 'md5'])))
|
||||
const md5 = directMd5 || this.extractEmojiMd5(content)
|
||||
if (!md5) continue
|
||||
|
||||
const directUrl = this.normalizeEmojiUrl(this.coerceString(this.getRecordField(row, [
|
||||
'emoji_cdn_url',
|
||||
'emojiCdnUrl',
|
||||
'cdnurl',
|
||||
'cdn_url',
|
||||
'emoji_url',
|
||||
'emojiUrl',
|
||||
'url',
|
||||
'thumburl',
|
||||
'thumb_url'
|
||||
])))
|
||||
const url = directUrl || this.extractEmojiUrl(content)
|
||||
const isMe = this.resolveIsSent(row, rawWxid, cleanedWxid)
|
||||
const mapKey = `${isMe ? '1' : '0'}:${md5}`
|
||||
const existing = tallyMap.get(mapKey)
|
||||
if (existing) {
|
||||
existing.count += 1
|
||||
if (!existing.url && url) existing.url = url
|
||||
} else {
|
||||
tallyMap.set(mapKey, { isMe, md5, url, count: 1 })
|
||||
}
|
||||
}
|
||||
hasMore = batch.hasMore === true
|
||||
}
|
||||
} finally {
|
||||
await wcdbService.closeMessageCursor(cursorResult.cursor)
|
||||
}
|
||||
|
||||
let myTop: { md5: string; url?: string; count: number } | undefined
|
||||
let friendTop: { md5: string; url?: string; count: number } | undefined
|
||||
for (const entry of tallyMap.values()) {
|
||||
if (entry.isMe) {
|
||||
if (!myTop || entry.count > myTop.count) {
|
||||
myTop = { md5: entry.md5, url: entry.url, count: entry.count }
|
||||
}
|
||||
} else if (!friendTop || entry.count > friendTop.count) {
|
||||
friendTop = { md5: entry.md5, url: entry.url, count: entry.count }
|
||||
}
|
||||
}
|
||||
|
||||
return { my: myTop, friend: friendTop }
|
||||
}
|
||||
|
||||
private async getDisplayName(username: string, fallback: string): Promise<string> {
|
||||
@@ -376,33 +608,46 @@ class DualReportService {
|
||||
|
||||
if (cppData.emojis && Array.isArray(cppData.emojis)) {
|
||||
for (const item of cppData.emojis) {
|
||||
const rawContent = item.content || ''
|
||||
const isMe = rawContent.startsWith('1:')
|
||||
const content = rawContent.substring(2) // Remove "1:" or "0:" prefix
|
||||
const count = item.count || 0
|
||||
const candidate = this.parseEmojiCandidate(item)
|
||||
if (!candidate.md5 || candidate.isMe === undefined || candidate.count <= 0) continue
|
||||
|
||||
if (isMe) {
|
||||
if (count > myTopCount) {
|
||||
const md5 = this.extractEmojiMd5(content)
|
||||
if (md5) {
|
||||
myTopCount = count
|
||||
myTopEmojiMd5 = md5
|
||||
myTopEmojiUrl = this.extractEmojiUrl(content)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (count > friendTopCount) {
|
||||
const md5 = this.extractEmojiMd5(content)
|
||||
if (md5) {
|
||||
friendTopCount = count
|
||||
friendTopEmojiMd5 = md5
|
||||
friendTopEmojiUrl = this.extractEmojiUrl(content)
|
||||
}
|
||||
if (candidate.isMe) {
|
||||
if (candidate.count > myTopCount) {
|
||||
myTopCount = candidate.count
|
||||
myTopEmojiMd5 = candidate.md5
|
||||
myTopEmojiUrl = candidate.url
|
||||
}
|
||||
} else if (candidate.count > friendTopCount) {
|
||||
friendTopCount = candidate.count
|
||||
friendTopEmojiMd5 = candidate.md5
|
||||
friendTopEmojiUrl = candidate.url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const needsEmojiFallback = stats.emojiCount > 0 && (!myTopEmojiMd5 || !friendTopEmojiMd5)
|
||||
if (needsEmojiFallback) {
|
||||
const fallback = await this.scanEmojiTopFallback(friendUsername, startTime, endTime, rawWxid, cleanedWxid)
|
||||
|
||||
if (!myTopEmojiMd5 && fallback.my?.md5) {
|
||||
myTopEmojiMd5 = fallback.my.md5
|
||||
myTopEmojiUrl = myTopEmojiUrl || fallback.my.url
|
||||
myTopCount = fallback.my.count
|
||||
}
|
||||
if (!friendTopEmojiMd5 && fallback.friend?.md5) {
|
||||
friendTopEmojiMd5 = fallback.friend.md5
|
||||
friendTopEmojiUrl = friendTopEmojiUrl || fallback.friend.url
|
||||
friendTopCount = fallback.friend.count
|
||||
}
|
||||
}
|
||||
|
||||
const [myEmojiUrlResult, friendEmojiUrlResult] = await Promise.all([
|
||||
myTopEmojiMd5 && !myTopEmojiUrl ? wcdbService.getEmoticonCdnUrl(dbPath, myTopEmojiMd5) : Promise.resolve(null),
|
||||
friendTopEmojiMd5 && !friendTopEmojiUrl ? wcdbService.getEmoticonCdnUrl(dbPath, friendTopEmojiMd5) : Promise.resolve(null)
|
||||
])
|
||||
if (myEmojiUrlResult?.success && myEmojiUrlResult.url) myTopEmojiUrl = myEmojiUrlResult.url
|
||||
if (friendEmojiUrlResult?.success && friendEmojiUrlResult.url) friendTopEmojiUrl = friendEmojiUrlResult.url
|
||||
|
||||
stats.myTopEmojiMd5 = myTopEmojiMd5
|
||||
stats.myTopEmojiUrl = myTopEmojiUrl
|
||||
stats.friendTopEmojiMd5 = friendTopEmojiMd5
|
||||
|
||||
@@ -82,29 +82,18 @@
|
||||
}
|
||||
|
||||
.first-chat-scene {
|
||||
background: linear-gradient(180deg,
|
||||
color-mix(in srgb, var(--primary) 60%, #000) 0%,
|
||||
color-mix(in srgb, var(--primary) 40%, #fff) 50%,
|
||||
var(--ar-bg-color) 100%);
|
||||
border-radius: 20px;
|
||||
padding: 28px 24px 24px;
|
||||
color: var(--text-primary);
|
||||
background: color-mix(in srgb, var(--ar-card-bg) 92%, #fff 8%);
|
||||
border-radius: 16px;
|
||||
padding: 18px 16px 16px;
|
||||
color: var(--ar-text-main);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin-top: 16px;
|
||||
border: 1px solid var(--border-color);
|
||||
border: 1px solid var(--bg-tertiary, rgba(0, 0, 0, 0.06));
|
||||
}
|
||||
|
||||
.first-chat-scene::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background-image:
|
||||
radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--primary) 20%, transparent), transparent 40%),
|
||||
radial-gradient(circle at 80% 10%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 35%),
|
||||
radial-gradient(circle at 50% 80%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 45%);
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.scene-title {
|
||||
@@ -112,7 +101,7 @@
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
margin-bottom: 8px;
|
||||
color: var(--text-primary);
|
||||
color: var(--ar-text-main);
|
||||
}
|
||||
|
||||
.scene-subtitle {
|
||||
@@ -121,13 +110,13 @@
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
opacity: 0.9;
|
||||
color: var(--text-secondary);
|
||||
color: var(--ar-text-sub);
|
||||
}
|
||||
|
||||
.scene-messages {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.scene-message {
|
||||
@@ -141,30 +130,53 @@
|
||||
}
|
||||
|
||||
.scene-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 12px;
|
||||
background: var(--primary-light);
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 50%;
|
||||
background: var(--ar-card-bg);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
color: var(--primary);
|
||||
color: var(--ar-text-sub);
|
||||
border: 1px solid var(--bg-tertiary, rgba(0, 0, 0, 0.08));
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.scene-content-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
max-width: min(78%, 720px);
|
||||
}
|
||||
|
||||
.scene-message.sent .scene-content-wrapper {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.scene-bubble {
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
background: color-mix(in srgb, var(--ar-card-bg-hover) 90%, #fff 10%);
|
||||
color: var(--ar-text-main);
|
||||
padding: 10px 14px;
|
||||
border-radius: 14px;
|
||||
max-width: 60%;
|
||||
box-shadow: var(--shadow-md);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 12px;
|
||||
width: fit-content;
|
||||
min-width: 68px;
|
||||
max-width: 100%;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
|
||||
border: 1px solid var(--bg-tertiary, rgba(0, 0, 0, 0.06));
|
||||
}
|
||||
|
||||
.scene-message.sent .scene-bubble {
|
||||
background: color-mix(in srgb, var(--primary) 15%, var(--bg-secondary));
|
||||
border-color: color-mix(in srgb, var(--primary) 30%, var(--border-color));
|
||||
background: color-mix(in srgb, var(--primary) 12%, var(--ar-card-bg-hover));
|
||||
border-color: color-mix(in srgb, var(--primary) 26%, var(--bg-tertiary, rgba(0, 0, 0, 0.06)));
|
||||
}
|
||||
|
||||
.scene-meta {
|
||||
@@ -176,13 +188,24 @@
|
||||
|
||||
.scene-content {
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
line-height: 1.65;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
line-break: auto;
|
||||
}
|
||||
|
||||
.scene-avatar.fallback {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.scene-avatar.with-image {
|
||||
background: transparent;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.scene-message.sent .scene-avatar {
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
border-color: color-mix(in srgb, var(--primary) 30%, var(--bg-tertiary, rgba(0, 0, 0, 0.08)));
|
||||
}
|
||||
|
||||
.dual-stat-grid {
|
||||
@@ -512,5 +535,20 @@
|
||||
grid-template-columns: 1fr;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.scene-avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.scene-content-wrapper {
|
||||
max-width: min(86%, 500px);
|
||||
}
|
||||
|
||||
.scene-bubble {
|
||||
max-width: 100%;
|
||||
min-width: 56px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +205,13 @@ function DualReportWindow() {
|
||||
)
|
||||
|
||||
const stripCdata = (text: string) => text.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
||||
const compactMessageText = (text: string) => (
|
||||
text
|
||||
.replace(/\r\n/g, '\n')
|
||||
.replace(/\s*\n+\s*/g, ' ')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.trim()
|
||||
)
|
||||
|
||||
const extractXmlText = (content: string) => {
|
||||
const titleMatch = content.match(/<title>([\s\S]*?)<\/title>/i)
|
||||
@@ -219,18 +226,18 @@ function DualReportWindow() {
|
||||
}
|
||||
|
||||
const formatMessageContent = (content?: string) => {
|
||||
const raw = String(content || '').trim()
|
||||
const raw = compactMessageText(String(content || '').trim())
|
||||
if (!raw) return '(空)'
|
||||
|
||||
// 1. 尝试提取 XML 关键字段
|
||||
const titleMatch = raw.match(/<title>([\s\S]*?)<\/title>/i)
|
||||
if (titleMatch?.[1]) return decodeEntities(stripCdata(titleMatch[1]).trim())
|
||||
if (titleMatch?.[1]) return compactMessageText(decodeEntities(stripCdata(titleMatch[1]).trim()))
|
||||
|
||||
const descMatch = raw.match(/<des>([\s\S]*?)<\/des>/i)
|
||||
if (descMatch?.[1]) return decodeEntities(stripCdata(descMatch[1]).trim())
|
||||
if (descMatch?.[1]) return compactMessageText(decodeEntities(stripCdata(descMatch[1]).trim()))
|
||||
|
||||
const summaryMatch = raw.match(/<summary>([\s\S]*?)<\/summary>/i)
|
||||
if (summaryMatch?.[1]) return decodeEntities(stripCdata(summaryMatch[1]).trim())
|
||||
if (summaryMatch?.[1]) return compactMessageText(decodeEntities(stripCdata(summaryMatch[1]).trim()))
|
||||
|
||||
// 2. 检查是否是 XML 结构
|
||||
const hasXmlTag = /<\s*[a-zA-Z]+[^>]*>/.test(raw)
|
||||
@@ -241,7 +248,7 @@ function DualReportWindow() {
|
||||
// 3. 最后的尝试:移除所有 XML 标签,看是否还有有意义的文本
|
||||
const stripped = raw.replace(/<[^>]+>/g, '').trim()
|
||||
if (stripped && stripped.length > 0 && stripped.length < 50) {
|
||||
return decodeEntities(stripped)
|
||||
return compactMessageText(decodeEntities(stripped))
|
||||
}
|
||||
|
||||
return '(多媒体/卡片消息)'
|
||||
@@ -279,6 +286,19 @@ function DualReportWindow() {
|
||||
|
||||
const mostActive = reportData.heatmap ? getMostActiveTime(reportData.heatmap) : null
|
||||
const responseAvgMinutes = reportData.response ? Math.max(0, Math.round(reportData.response.avg / 60)) : 0
|
||||
const getSceneAvatarUrl = (isSentByMe: boolean) => (isSentByMe ? reportData.selfAvatarUrl : reportData.friendAvatarUrl)
|
||||
const getSceneAvatarFallback = (isSentByMe: boolean) => (isSentByMe ? '我' : reportData.friendName.substring(0, 1))
|
||||
const renderSceneAvatar = (isSentByMe: boolean) => {
|
||||
const avatarUrl = getSceneAvatarUrl(isSentByMe)
|
||||
if (avatarUrl) {
|
||||
return (
|
||||
<div className="scene-avatar with-image">
|
||||
<img src={avatarUrl} alt={isSentByMe ? 'me-avatar' : 'friend-avatar'} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <div className="scene-avatar fallback">{getSceneAvatarFallback(isSentByMe)}</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="annual-report-window dual-report-window">
|
||||
@@ -317,9 +337,7 @@ function DualReportWindow() {
|
||||
<div className="scene-messages">
|
||||
{firstChatMessages.map((msg, idx) => (
|
||||
<div key={idx} className={`scene-message ${msg.isSentByMe ? 'sent' : 'received'}`}>
|
||||
<div className="scene-avatar">
|
||||
{msg.isSentByMe ? '我' : reportData.friendName.substring(0, 1)}
|
||||
</div>
|
||||
{renderSceneAvatar(msg.isSentByMe)}
|
||||
<div className="scene-content-wrapper">
|
||||
<div className="scene-meta">
|
||||
{formatFullDate(msg.createTime).split(' ')[1]}
|
||||
@@ -355,9 +373,7 @@ function DualReportWindow() {
|
||||
<div className="scene-messages">
|
||||
{yearFirstChat.firstThreeMessages.map((msg, idx) => (
|
||||
<div key={idx} className={`scene-message ${msg.isSentByMe ? 'sent' : 'received'}`}>
|
||||
<div className="scene-avatar">
|
||||
{msg.isSentByMe ? '我' : reportData.friendName.substring(0, 1)}
|
||||
</div>
|
||||
{renderSceneAvatar(msg.isSentByMe)}
|
||||
<div className="scene-content-wrapper">
|
||||
<div className="scene-meta">
|
||||
{formatFullDate(msg.createTime).split(' ')[1]}
|
||||
|
||||
Reference in New Issue
Block a user