|
|
@@ -1,6 +1,5 @@
|
|
|
-import store from '..'
|
|
|
import { titleNotify } from '../../utils'
|
|
|
-import { filterCallingMessage } from '../../utils/common'
|
|
|
+import { filterCallingMessage, isMessageInConversation } from '../../utils/common'
|
|
|
import { getOpenIM } from '@/utils/openIM';
|
|
|
import da from "element-ui/src/locale/lang/da";
|
|
|
|
|
|
@@ -43,12 +42,15 @@ const conversationModules = {
|
|
|
return state.currentConversation.conversationType
|
|
|
},
|
|
|
totalUnreadCount: state => {
|
|
|
+ const currentConversationID = state.currentConversation.conversationID
|
|
|
+ const isWindowFocused = typeof document.hasFocus === 'function' ? document.hasFocus() : !document.hidden
|
|
|
const result = state.conversationList.reduce((count, conversation) => {
|
|
|
- // 当前会话不计算总未读
|
|
|
- if (!store.getters.hidden && state.currentConversation.conversationID === conversation.conversationID) {
|
|
|
+ const unreadCount = conversation.unreadCount || 0
|
|
|
+ // 窗口聚焦且正在查看的会话不计入未读(该会话会在收到消息时自动标记已读)
|
|
|
+ if (isWindowFocused && currentConversationID && currentConversationID === conversation.conversationID) {
|
|
|
return count
|
|
|
}
|
|
|
- return count + conversation.unreadCount
|
|
|
+ return count + unreadCount
|
|
|
}, 0)
|
|
|
titleNotify(result)
|
|
|
return result
|
|
|
@@ -140,6 +142,26 @@ const conversationModules = {
|
|
|
state.nextReqMessageID = ''
|
|
|
state.isCompleted = false
|
|
|
},
|
|
|
+ patchCurrentConversation(state, conversation) {
|
|
|
+ if (state.currentConversation.conversationID === conversation.conversationID) {
|
|
|
+ state.currentConversation = { ...state.currentConversation, ...conversation }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mergeConversationList(state, changedConversations) {
|
|
|
+ if (!Array.isArray(changedConversations) || changedConversations.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const list = [...state.conversationList]
|
|
|
+ changedConversations.forEach(changed => {
|
|
|
+ const index = list.findIndex(item => item.conversationID === changed.conversationID)
|
|
|
+ if (index >= 0) {
|
|
|
+ list[index] = changed
|
|
|
+ } else {
|
|
|
+ list.unshift(changed)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ state.conversationList = list
|
|
|
+ },
|
|
|
/**
|
|
|
* 更新会话列表
|
|
|
* 调用时机:触发会话列表更新事件时。C
|
|
|
@@ -218,58 +240,41 @@ const conversationModules = {
|
|
|
* @returns
|
|
|
*/
|
|
|
pushCurrentMessageList(state, data) {
|
|
|
- // 还没当前会话,则跳过
|
|
|
- console.log("触发消息列表更新",state.currentConversation)
|
|
|
if (!state.currentConversation.conversationID) {
|
|
|
return
|
|
|
}
|
|
|
- console.log("会话详细信息",state.currentConversation)
|
|
|
- console.log("消息详细信息",data)
|
|
|
- if (Array.isArray(data)) {
|
|
|
- // 筛选出当前会话的消息
|
|
|
- const result = data.filter(item => item.recvID===JSON.parse(state.currentConversation.latestMsg).recvID&& item.sendID === JSON.parse(state.currentConversation.latestMsg).sendID)
|
|
|
- console.log("收到消息1")
|
|
|
- console.log("state.currentConversation.conversationID会话id",state.currentConversation.conversationID)
|
|
|
- console.log("result[0]",result[0])
|
|
|
- if(result[0].ex!=null&&result[0].ex!=""){
|
|
|
- try{
|
|
|
- var json=JSON.parse(result[0].ex);
|
|
|
- console.log("消息json",json)
|
|
|
- if(json.type!=null&&json.type!=""){
|
|
|
- state.type=json.type;
|
|
|
- state.orderId=json.orderId;
|
|
|
- state.imType=json.imType;
|
|
|
- state.followId=json.followId;
|
|
|
- state.orderType=json.orderType;
|
|
|
- }
|
|
|
- }
|
|
|
- catch(e){
|
|
|
- }
|
|
|
+ const appendMessages = (messages) => {
|
|
|
+ if (!messages.length) {
|
|
|
+ return
|
|
|
}
|
|
|
- state.currentMessageList = [...state.currentMessageList, ...result]
|
|
|
- filterCallingMessage(state.currentMessageList)
|
|
|
- //} else if ("si_"+data.sendID+"_"+data.recvID === state.currentConversation.conversationID) {
|
|
|
- } else if (data.recvID===JSON.parse(state.currentConversation.latestMsg).recvID&& data.sendID === JSON.parse(state.currentConversation.latestMsg).sendID) {
|
|
|
- console.log("会话id22222",state.currentConversation.conversationID)
|
|
|
- state.currentMessageList = [...state.currentMessageList, data]
|
|
|
- console.log("收到消息2")
|
|
|
- console.log(data)
|
|
|
- if(data.ex!=null&&data.ex!=""){
|
|
|
- var json=JSON.parse(data.ex);
|
|
|
- console.log(json)
|
|
|
- try{
|
|
|
- if(json.type!=null&&json.type!=""){
|
|
|
- state.type=json.type;
|
|
|
- state.orderId=json.orderId;
|
|
|
- state.imType=json.imType;
|
|
|
- state.followId=json.followId;
|
|
|
- state.orderType=json.orderType;
|
|
|
+ const firstMessage = messages[0]
|
|
|
+ if (firstMessage.ex) {
|
|
|
+ try {
|
|
|
+ const json = JSON.parse(firstMessage.ex)
|
|
|
+ if (json.type) {
|
|
|
+ state.type = json.type
|
|
|
+ state.orderId = json.orderId
|
|
|
+ state.imType = json.imType
|
|
|
+ state.followId = json.followId
|
|
|
+ state.orderType = json.orderType
|
|
|
}
|
|
|
+ } catch (e) {
|
|
|
+ // ignore invalid ex
|
|
|
}
|
|
|
- catch(e){
|
|
|
- }
|
|
|
}
|
|
|
- filterCallingMessage(state.currentMessageList)
|
|
|
+ const existingIds = new Set(state.currentMessageList.map(item => item.clientMsgID))
|
|
|
+ const newMessages = messages.filter(item => !existingIds.has(item.clientMsgID))
|
|
|
+ if (newMessages.length) {
|
|
|
+ state.currentMessageList = [...state.currentMessageList, ...newMessages]
|
|
|
+ filterCallingMessage(state.currentMessageList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Array.isArray(data)) {
|
|
|
+ const result = data.filter(item => isMessageInConversation(item, state.currentConversation))
|
|
|
+ appendMessages(result)
|
|
|
+ } else if (isMessageInConversation(data, state.currentConversation)) {
|
|
|
+ appendMessages([data])
|
|
|
}
|
|
|
},
|
|
|
/**
|