(
msg: {
id?: number
senderName: string
content: string | null
timestamp: number
},
locale?: string
)
| 43 | * 输出格式: "2025/3/3 07:25:04 张三: 消息内容" |
| 44 | */ |
| 45 | export function formatMessageCompact( |
| 46 | msg: { |
| 47 | id?: number |
| 48 | senderName: string |
| 49 | content: string | null |
| 50 | timestamp: number |
| 51 | }, |
| 52 | locale?: string |
| 53 | ): string { |
| 54 | const localeStr = isChineseLocale(locale) ? 'zh-CN' : 'en-US' |
| 55 | const time = new Date(msg.timestamp * 1000).toLocaleString(localeStr) |
| 56 | let content = msg.content || (t('noContent', locale) as string) |
| 57 | |
| 58 | if (content.length > MAX_MESSAGE_CONTENT_LENGTH) { |
| 59 | content = content.slice(0, MAX_MESSAGE_CONTENT_LENGTH) + '...' |
| 60 | } |
| 61 | |
| 62 | return `${time} ${msg.senderName}: ${content}` |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * 格式化时间范围用于返回结果 |
no test coverage detected