Merge pull request #839 from xunchahaha/dev

Dev
This commit is contained in:
xuncha
2026-04-25 14:37:05 +08:00
committed by GitHub
2 changed files with 32 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ interface ChatLabHeader {
interface ChatLabMeta { interface ChatLabMeta {
name: string name: string
platform: string platform: string
type: 'group' | 'private' type: ApiSessionType
groupId?: string groupId?: string
groupAvatar?: string groupAvatar?: string
ownerId?: string ownerId?: string
@@ -68,6 +68,7 @@ interface ApiMediaOptions {
} }
type MediaKind = 'image' | 'voice' | 'video' | 'emoji' type MediaKind = 'image' | 'voice' | 'video' | 'emoji'
type ApiSessionType = 'group' | 'private' | 'channel' | 'other'
interface ApiExportedMedia { interface ApiExportedMedia {
kind: MediaKind kind: MediaKind
@@ -781,6 +782,17 @@ class HttpService {
} }
} }
private getApiSessionType(username: string): ApiSessionType {
const normalized = String(username || '').trim()
const lowered = normalized.toLowerCase()
if (!normalized) return 'other'
if (lowered.endsWith('@chatroom')) return 'group'
if (lowered.startsWith('gh_')) return 'channel'
if (lowered.includes('@openim')) return 'channel'
if (lowered.startsWith('weixin') && lowered !== 'weixin') return 'channel'
return 'private'
}
private async handleMessages(url: URL, res: http.ServerResponse): Promise<void> { private async handleMessages(url: URL, res: http.ServerResponse): Promise<void> {
const talker = (url.searchParams.get('talker') || '').trim() const talker = (url.searchParams.get('talker') || '').trim()
const limit = this.parseIntParam(url.searchParams.get('limit'), 100, 1, 10000) const limit = this.parseIntParam(url.searchParams.get('limit'), 100, 1, 10000)
@@ -910,7 +922,7 @@ class HttpService {
id: s.username, id: s.username,
name: s.displayName || s.username, name: s.displayName || s.username,
platform: 'wechat', platform: 'wechat',
type: s.username.endsWith('@chatroom') ? 'group' : 'private', type: this.getApiSessionType(s.username),
messageCount: s.messageCountHint || undefined, messageCount: s.messageCountHint || undefined,
lastMessageAt: s.lastTimestamp lastMessageAt: s.lastTimestamp
})) }))
@@ -925,6 +937,7 @@ class HttpService {
username: s.username, username: s.username,
displayName: s.displayName, displayName: s.displayName,
type: s.type, type: s.type,
sessionType: this.getApiSessionType(s.username),
lastTimestamp: s.lastTimestamp, lastTimestamp: s.lastTimestamp,
unreadCount: s.unreadCount unreadCount: s.unreadCount
})) }))
@@ -1882,7 +1895,7 @@ class HttpService {
meta: { meta: {
name: talkerName, name: talkerName,
platform: 'wechat', platform: 'wechat',
type: isGroup ? 'group' : 'private', type: this.getApiSessionType(talkerId),
groupId: isGroup ? talkerId : undefined, groupId: isGroup ? talkerId : undefined,
groupAvatar: isGroup ? sessionAvatarInfo?.avatarUrl : undefined, groupAvatar: isGroup ? sessionAvatarInfo?.avatarUrl : undefined,
ownerId: myWxid || undefined ownerId: myWxid || undefined
@@ -2045,6 +2058,12 @@ class HttpService {
* 获取消息内容 * 获取消息内容
*/ */
private getMessageContent(msg: Message): string | null { private getMessageContent(msg: Message): string | null {
const normalizeTextContent = (value: string | null | undefined): string | null => {
const text = String(value || '')
if (!text) return null
return text.replace(/^[\s]*([a-zA-Z0-9_@-]+):(?!\/\/)(?:\s*(?:\r?\n|<br\s*\/?>)\s*|\s*)/i, '').trim()
}
if (msg.localType === 49) { if (msg.localType === 49) {
return this.getType49Content(msg) return this.getType49Content(msg)
} }
@@ -2057,7 +2076,7 @@ class HttpService {
// 根据类型返回占位符 // 根据类型返回占位符
switch (msg.localType) { switch (msg.localType) {
case 1: case 1:
return msg.rawContent || null return normalizeTextContent(msg.parsedContent || msg.rawContent)
case 3: case 3:
return '[图片]' return '[图片]'
case 34: case 34:
@@ -2073,7 +2092,7 @@ class HttpService {
case 49: case 49:
return this.getType49Content(msg) return this.getType49Content(msg)
default: default:
return msg.rawContent || null return normalizeTextContent(msg.parsedContent || msg.rawContent) || null
} }
} }

View File

@@ -1325,13 +1325,19 @@ class MessagePushService {
} }
private getMessageDisplayContent(message: Message): string | null { private getMessageDisplayContent(message: Message): string | null {
const normalizeTextContent = (value: string | null | undefined): string | null => {
const text = String(value || '')
if (!text) return null
return text.replace(/^[\s]*([a-zA-Z0-9_@-]+):(?!\/\/)(?:\s*(?:\r?\n|<br\s*\/?>)\s*|\s*)/i, '').trim()
}
const cleanOfficialPrefix = (value: string | null): string | null => { const cleanOfficialPrefix = (value: string | null): string | null => {
if (!value) return value if (!value) return value
return value.replace(/^\s*\[\]\s*/u, '').trim() || value return value.replace(/^\s*\[\]\s*/u, '').trim() || value
} }
switch (Number(message.localType || 0)) { switch (Number(message.localType || 0)) {
case 1: case 1:
return cleanOfficialPrefix(message.rawContent || null) return cleanOfficialPrefix(normalizeTextContent(message.parsedContent || message.rawContent))
case 3: case 3:
return '[图片]' return '[图片]'
case 34: case 34:
@@ -1347,7 +1353,7 @@ class MessagePushService {
case 49: case 49:
return cleanOfficialPrefix(message.linkTitle || message.fileName || '[消息]') return cleanOfficialPrefix(message.linkTitle || message.fileName || '[消息]')
default: default:
return cleanOfficialPrefix(message.parsedContent || message.rawContent || null) return cleanOfficialPrefix(normalizeTextContent(message.parsedContent || message.rawContent) || null)
} }
} }