diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 211997f..123ebd8 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -224,8 +224,18 @@ const conversationSlice = (set, get) => ({ * 搜索结果 */ setConversationsList: (conversationsList) => { - const { activeConversations, } = get(); + const { activeConversations, currentConversation } = get(); + // 让当前会话显示在页面上 + let _tmpCurrentMsgs = []; + if (currentConversation.sn) { + _tmpCurrentMsgs = activeConversations[currentConversation.sn]; + } const conversationsMapped = conversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); + if (currentConversation.sn) { + const hasCurrent = Object.keys(conversationsMapped).findIndex(sn => Number(sn) === Number(currentConversation.sn)) !== -1; + conversationsMapped[currentConversation.sn] = _tmpCurrentMsgs; + const _len = hasCurrent ? 0 : conversationsList.unshift(currentConversation); + } const conversationsTopStateMapped = groupBy(conversationsList, 'top_state'); @@ -243,7 +253,7 @@ const conversationSlice = (set, get) => ({ return set({ closedConversationsList, activeConversations: { ...activeConversations, ...listMapped } }); }, addToConversationList: (newList, position='top') => { - const { activeConversations, conversationsList, } = get(); + const { activeConversations, conversationsList, currentConversation } = get(); // const conversationsIds = Object.keys(activeConversations); const conversationsIds = conversationsList.map((chatItem) => `${chatItem.sn}`); const newConversations = newList.filter((conversation) => !conversationsIds.includes(`${conversation.sn}`)); @@ -255,15 +265,22 @@ const conversationSlice = (set, get) => ({ const updateList = replaceObjectsByKey(conversationsList, newList, 'sn'); const mergedList = position==='top' ? [...newList, ...withoutNew] : [...updateList, ...newConversations]; - const mergedListMapped = groupBy(mergedList, 'top_state'); + const mergedListMsgs = { ...newConversationsMapped, ...activeConversations, }; + // 让当前会话显示在页面上 + if (currentConversation.sn) { + const hasCurrent = -1 !== Object.keys(mergedListMsgs).findIndex(sn => Number(sn) === Number(currentConversation.sn)); + const _len = hasCurrent ? 0 : mergedList.unshift(currentConversation); + } const refreshTotalNotify = mergedList.reduce((r, c) => r+(c.unread_msg_count === UNREAD_MARK ? 0 : c.unread_msg_count), 0); + const mergedListMapped = groupBy(mergedList, 'top_state'); + return set((state) => ({ topList: mergedListMapped[1] || [], pageList: mergedListMapped[0] || [], conversationsList: mergedList, - activeConversations: { ...newConversationsMapped, ...activeConversations, }, + activeConversations: mergedListMsgs, totalNotify: refreshTotalNotify, // totalNotify: state.totalNotify + newConversations.map((ele) => ele.unread_msg_count).reduce((acc, cur) => acc + (cur || 0), 0), }));