群聊
This commit is contained in:
@@ -61,20 +61,36 @@ export const messageTypeConfigs: Record<number, MessageTypeConfig> = {
|
||||
label: '群通知',
|
||||
icon: 'fas fa-users',
|
||||
summaryFn: (msg) => {
|
||||
// 优先使用后端发送的 content(后端已正确设置个性化内容)
|
||||
if (msg.content) {
|
||||
return msg.content
|
||||
}
|
||||
|
||||
const extra = typeof msg.extra === 'string' ? JSON.parse(msg.extra || '{}') : (msg.extra || {})
|
||||
// 根据事件类型生成更具体的文案
|
||||
if (extra.event === 'member_join') {
|
||||
return `用户加入了群聊`
|
||||
} else if (extra.event === 'member_leave') {
|
||||
return `用户退出了群聊`
|
||||
} else if (extra.event === 'member_remove') {
|
||||
return `用户被移出群聊`
|
||||
// 根据事件类型生成更具体的文案(仅在无 content 时使用)
|
||||
if (extra.type === 'member_invite' || extra.event === 'member_invite') {
|
||||
const operatorName = extra.operator_name || '未知用户'
|
||||
const targetNames = extra.target_names || []
|
||||
if (targetNames.length > 0) {
|
||||
return `${operatorName} 邀请了 ${targetNames.join('、')} 加入群聊`
|
||||
}
|
||||
return `${operatorName} 邀请了成员加入群聊`
|
||||
} else if (extra.type === 'member_remove' || extra.event === 'member_remove') {
|
||||
const operatorName = extra.operator_name || '未知用户'
|
||||
const targetName = extra.target_name || '用户'
|
||||
return `${operatorName} 将 ${targetName} 移出了群聊`
|
||||
} else if (extra.type === 'member_leave' || extra.event === 'member_leave') {
|
||||
const targetName = extra.target_name || '用户'
|
||||
return `${targetName} 退出了群聊`
|
||||
} else if (extra.type === 'member_join' || extra.event === 'member_join') {
|
||||
const targetName = extra.target_name || '用户'
|
||||
return `${targetName} 加入了群聊`
|
||||
} else if (extra.event === 'group_update') {
|
||||
return `群信息已更新`
|
||||
} else if (extra.event === 'role_change') {
|
||||
return `成员角色已变更`
|
||||
}
|
||||
return extra.title || msg.content || '[群通知]'
|
||||
return extra.title || '[群通知]'
|
||||
}
|
||||
},
|
||||
[MessageType.FILE]: {
|
||||
@@ -136,3 +152,4 @@ export function isSystemOrNotifyMessage(messageType: number): boolean {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -870,12 +870,11 @@ function handleWebSocketMessage(message: ChatMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
const isCurrentChat = currentRoomId === roomId
|
||||
|
||||
if (contact) {
|
||||
chatStore.updateContactLastMsg(contact.id, getMsgSummary(message), Date.now())
|
||||
|
||||
const currentRoomId = chatStore.currentTarget ? getRoomId(chatStore.currentTarget) : null
|
||||
const isCurrentChat = currentRoomId === roomId
|
||||
|
||||
conversationStore.handleMessageUpdate(message, message.isSelf === true, isCurrentChat)
|
||||
if (!message.isSelf) {
|
||||
if (!isCurrentChat) {
|
||||
@@ -889,12 +888,36 @@ function handleWebSocketMessage(message: ChatMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// 浏览器原生通知(仅在标签页隐藏时)
|
||||
if ('Notification' in window && Notification.permission === 'granted' && document.hidden) {
|
||||
new Notification(contact.remark_name || contact.user?.name || '新消息', {
|
||||
body: getMsgSummary(message),
|
||||
icon: '/favicon.ico'
|
||||
})
|
||||
}
|
||||
|
||||
// 不在会话tab时显示toast通知
|
||||
if (currentTab.value !== 'chat') {
|
||||
const senderName = contact.remark_name || contact.user?.name || message.sender_user_id || '未知用户'
|
||||
toastStore.showToast(
|
||||
'收到新消息',
|
||||
'info',
|
||||
5000,
|
||||
`来自 ${senderName} 的新消息`,
|
||||
{
|
||||
label: '去查看',
|
||||
handler: async () => {
|
||||
currentTab.value = 'chat'
|
||||
// 尝试查找或创建会话
|
||||
await conversationStore.loadConversations()
|
||||
const conv = conversationStore.conversations.find(c => c.room_id === roomId || c.target_id === message.sender_user_id)
|
||||
if (conv) {
|
||||
await selectChatByConversation(conv)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 不在会话列表时收到消息,显示提示
|
||||
|
||||
@@ -117,3 +117,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user