群聊
This commit is contained in:
@@ -61,20 +61,36 @@ export const messageTypeConfigs: Record<number, MessageTypeConfig> = {
|
|||||||
label: '群通知',
|
label: '群通知',
|
||||||
icon: 'fas fa-users',
|
icon: 'fas fa-users',
|
||||||
summaryFn: (msg) => {
|
summaryFn: (msg) => {
|
||||||
|
// 优先使用后端发送的 content(后端已正确设置个性化内容)
|
||||||
|
if (msg.content) {
|
||||||
|
return msg.content
|
||||||
|
}
|
||||||
|
|
||||||
const extra = typeof msg.extra === 'string' ? JSON.parse(msg.extra || '{}') : (msg.extra || {})
|
const extra = typeof msg.extra === 'string' ? JSON.parse(msg.extra || '{}') : (msg.extra || {})
|
||||||
// 根据事件类型生成更具体的文案
|
// 根据事件类型生成更具体的文案(仅在无 content 时使用)
|
||||||
if (extra.event === 'member_join') {
|
if (extra.type === 'member_invite' || extra.event === 'member_invite') {
|
||||||
return `用户加入了群聊`
|
const operatorName = extra.operator_name || '未知用户'
|
||||||
} else if (extra.event === 'member_leave') {
|
const targetNames = extra.target_names || []
|
||||||
return `用户退出了群聊`
|
if (targetNames.length > 0) {
|
||||||
} else if (extra.event === 'member_remove') {
|
return `${operatorName} 邀请了 ${targetNames.join('、')} 加入群聊`
|
||||||
return `用户被移出群聊`
|
}
|
||||||
|
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') {
|
} else if (extra.event === 'group_update') {
|
||||||
return `群信息已更新`
|
return `群信息已更新`
|
||||||
} else if (extra.event === 'role_change') {
|
} else if (extra.event === 'role_change') {
|
||||||
return `成员角色已变更`
|
return `成员角色已变更`
|
||||||
}
|
}
|
||||||
return extra.title || msg.content || '[群通知]'
|
return extra.title || '[群通知]'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[MessageType.FILE]: {
|
[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) {
|
if (contact) {
|
||||||
chatStore.updateContactLastMsg(contact.id, getMsgSummary(message), Date.now())
|
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)
|
conversationStore.handleMessageUpdate(message, message.isSelf === true, isCurrentChat)
|
||||||
if (!message.isSelf) {
|
if (!message.isSelf) {
|
||||||
if (!isCurrentChat) {
|
if (!isCurrentChat) {
|
||||||
@@ -889,12 +888,36 @@ function handleWebSocketMessage(message: ChatMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 浏览器原生通知(仅在标签页隐藏时)
|
||||||
if ('Notification' in window && Notification.permission === 'granted' && document.hidden) {
|
if ('Notification' in window && Notification.permission === 'granted' && document.hidden) {
|
||||||
new Notification(contact.remark_name || contact.user?.name || '新消息', {
|
new Notification(contact.remark_name || contact.user?.name || '新消息', {
|
||||||
body: getMsgSummary(message),
|
body: getMsgSummary(message),
|
||||||
icon: '/favicon.ico'
|
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 {
|
} else {
|
||||||
// 不在会话列表时收到消息,显示提示
|
// 不在会话列表时收到消息,显示提示
|
||||||
|
|||||||
@@ -117,3 +117,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user