fix: 从订单进入后没有置顶和选中

dev/chat
Lei OT 1 year ago
parent bf22a4fbdd
commit b1b2844238

@ -144,13 +144,16 @@ const conversationSlice = (set, get) => ({
return set({ conversationsList, activeConversations: conversationsMapped });
},
addToConversationList: (newList) => {
const { activeConversations } = get();
const { activeConversations, conversationsList } = get();
const conversationsIds = Object.keys(activeConversations);
const newConversations = newList.filter((conversation) => !conversationsIds.includes(`${conversation.sn}`));
const newConversationsMapped = newConversations.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
const newListIds = newList.map((chatItem) => `${chatItem.sn}`);
const withoutNew = conversationsList.filter(item => !newListIds.includes(`${item.sn}`));
return set((state) => ({
conversationsList: [...newConversations, ...state.conversationsList],
conversationsList: [...newList, ...withoutNew],
activeConversations: { ...activeConversations, ...newConversationsMapped },
totalNotify: state.totalNotify + newConversations.map((ele) => ele.unread_msg_count).reduce((acc, cur) => acc + (cur || 0), 0),
}));

@ -46,16 +46,23 @@ const Conversations = () => {
const getOrderConversationList = async (colisn) => {
const { whatsapp_phone_number } = switchToC;
const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || '';
let findCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn));
if (!isEmpty(whatsappID)) {
let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`);
let findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
let findCurrent = findCurrentOrderChats[findCurrentIndex];
if (findCurrentIndex !== -1) {
addToConversationList(findCurrentOrderChats);
} else if (!isEmpty(whatsappID)) {
const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID });
if (!isEmpty(data)) {
addToConversationList(data);
findCurrentIndex = 0; // data.length-1; // data.lastIndexOf((item) => item.coli_sn === Number(colisn));
findCurrent = data[findCurrentIndex];
} else {
// findCurrentIndex = conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); // data.findIndex((item) => item.sn === currentConversation.sn);
}
findCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); // data.findIndex((item) => item.sn === currentConversation.sn);
}
if (findCurrent !== -1) {
switchConversation(conversationsList[findCurrent]);
if (findCurrentIndex >= 0) {
switchConversation(findCurrent);
} else {
// reset chat window
setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn });

Loading…
Cancel
Save