Merge branch 'main' of github.com:hainatravel/global-sales

hotfix/new-conversation
Jimmy Liow 1 year ago
commit 25112a255a

@ -307,7 +307,7 @@ const messageSlice = (set, get) => ({
// msgRender:
const { activeConversations, conversationsList, currentConversation, totalNotify } = get();
const targetMsgs = activeConversations[String(targetId)] || [];
const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
const targetIndex = conversationsList.findIndex((ele) => Number(ele.sn) === Number(targetId));
const lastReceivedTime = (message.type !== 'system' && message.sender !== 'me') ? dayjs(message.date).add(8, 'hours').format(DATETIME_FORMAT) : null;
const newConversation =
targetIndex !== -1
@ -315,7 +315,7 @@ const messageSlice = (set, get) => ({
...conversationsList[targetIndex],
last_received_time: lastReceivedTime || conversationsList[targetIndex].last_received_time,
unread_msg_count:
String(targetId) !== String(currentConversation.sn) && message.sender !== 'me'
Number(targetId) !== Number(currentConversation.sn) && message.sender !== 'me'
? conversationsList[targetIndex].unread_msg_count + 1
: conversationsList[targetIndex].unread_msg_count,
}
@ -332,6 +332,8 @@ const messageSlice = (set, get) => ({
};
conversationsList.splice(targetIndex, 1);
conversationsList.unshift(newConversation);
console.log('find in list, i:', targetIndex);
console.log('find in list, chat updated and Top: \n', JSON.stringify(newConversation, null, 2));
const isCurrent = Number(targetId) === Number(currentConversation.sn);
const updatedCurrent = isCurrent
? {
@ -345,9 +347,9 @@ const messageSlice = (set, get) => ({
console.log('is current and update', isCurrent, JSON.stringify(updatedCurrent, null, 2));
return set({
currentConversation: updatedCurrent,
conversationsList: [...conversationsList],
totalNotify: totalNotify + (message.sender === 'me' ? 0 : 1),
activeConversations: { ...activeConversations, [String(targetId)]: [...targetMsgs, message] },
conversationsList: [...conversationsList],
});
},
});

Loading…
Cancel
Save