diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index d780c9e..13faa4c 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -188,6 +188,18 @@ const conversationSlice = (set, get) => ({ conversationsList: [...conversationsList], })); }, + updateConversationItem: (conversation) => { + const { conversationsList } = get(); + const targetId = conversation.sn; + const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId)); + targetIndex !== -1 + ? conversationsList.splice(targetIndex, 1, { + ...conversationsList[targetIndex], + ...conversation, + }) + : null; + return set({ conversationsList: [...conversationsList] }); + }, }); const messageSlice = (set, get) => ({ @@ -204,7 +216,7 @@ const messageSlice = (set, get) => ({ // msgUpdate console.log('UPDATE_SENT_MESSAGE_ITEM-----------------------------------------------------------------'); // 更新会话中的消息 - const { activeConversations } = get(); + const { activeConversations, conversationsList } = get(); const targetId = message.conversationid; const targetMsgs = (activeConversations[String(targetId)] || []).map((ele) => { // 更新状态 @@ -224,17 +236,17 @@ const messageSlice = (set, get) => ({ } // 更新列表的时间 - // if (message.type !== 'error') { - // const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId)); - // conversationsList.splice(targetIndex, 1, { - // ...conversationsList[targetIndex], - // last_received_time: message.date, - // }); - // } + if (message.status === 'received') { // 'delivered' + const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId)); + conversationsList.splice(targetIndex, 1, { + ...conversationsList[targetIndex], + last_received_time: message.deliverTime, // todo: 需要+8 hours + }); + } return set({ activeConversations: { ...activeConversations, [String(targetId)]: targetMsgs }, - // conversationsList: [...conversationsList], + conversationsList: [...conversationsList], }); }, sentOrReceivedNewMessage: (targetId, message) => {