Merge pull request #528 from BeiChen-CN/main

feat: 导出联系人标签和详细描述
This commit is contained in:
cc
2026-03-23 19:34:57 +08:00
committed by GitHub
5 changed files with 91 additions and 4 deletions

View File

@@ -153,6 +153,8 @@ export interface ContactInfo {
remark?: string
nickname?: string
alias?: string
labels?: string[]
detailDescription?: string
avatarUrl?: string
type: 'friend' | 'group' | 'official' | 'former_friend' | 'other'
}
@@ -1321,6 +1323,8 @@ class ChatService {
continue
}
const labels = this.parseContactLabels(row)
const detailDescription = this.getContactDetailDescription(row)
const displayName = row.remark || row.nick_name || row.alias || username
contacts.push({
@@ -1329,6 +1333,8 @@ class ChatService {
remark: row.remark || undefined,
nickname: row.nick_name || undefined,
alias: row.alias || undefined,
labels: labels.length > 0 ? labels : undefined,
detailDescription: detailDescription || undefined,
avatarUrl: undefined,
type,
lastContactTime: lastContactTimeMap.get(username) || 0
@@ -1880,6 +1886,59 @@ class ChatService {
return Number.isFinite(parsed) ? parsed : fallback
}
private parseContactLabels(row: Record<string, any>): string[] {
const raw = this.getRowField(row, [
'label_list', 'labelList', 'labels', 'label_names', 'labelNames', 'tags', 'tag_list', 'tagList'
])
const normalizedFromValue = (value: unknown): string[] => {
if (Array.isArray(value)) {
return Array.from(new Set(value.map((item) => String(item || '').trim()).filter(Boolean)))
}
const text = String(value || '').trim()
if (!text) return []
return Array.from(new Set(
text
.replace(/[;、|]+/g, ',')
.split(',')
.map((item) => item.trim())
.filter(Boolean)
))
}
const direct = normalizedFromValue(raw)
if (direct.length > 0) return direct
for (const [key, value] of Object.entries(row)) {
const normalizedKey = key.toLowerCase()
if (!normalizedKey.includes('label') && !normalizedKey.includes('tag')) continue
if (normalizedKey.includes('img') || normalizedKey.includes('head')) continue
const fallback = normalizedFromValue(value)
if (fallback.length > 0) return fallback
}
return []
}
private getContactDetailDescription(row: Record<string, any>): string {
const value = this.getRowField(row, [
'detail_description', 'detailDescription', 'description', 'desc', 'contact_description', 'contactDescription',
'profile', 'introduction', 'phone', 'mobile', 'telephone', 'tel', 'vcard', 'card_info', 'cardInfo'
])
const direct = String(value || '').trim()
if (direct) return direct
for (const [key, rawValue] of Object.entries(row)) {
const normalizedKey = key.toLowerCase()
const isCandidate = normalizedKey.includes('detail') || normalizedKey.includes('desc') || normalizedKey.includes('description') || normalizedKey.includes('profile') || normalizedKey.includes('intro') || normalizedKey.includes('phone') || normalizedKey.includes('mobile') || normalizedKey.includes('tel') || normalizedKey.includes('vcard') || normalizedKey.includes('card')
if (!isCandidate) continue
if (normalizedKey.includes('avatar') || normalizedKey.includes('img') || normalizedKey.includes('head')) continue
const text = String(rawValue || '').trim()
if (text) return text
}
return ''
}
private normalizeUnsignedIntegerToken(raw: any): string | undefined {
if (raw === undefined || raw === null || raw === '') return undefined