新消息-新增会话; style: 激活的会话; 会话新消息在列表中置顶

dev/chat
Lei OT 1 year ago
parent 2effad3ef9
commit 7ba43ebd4f

@ -192,7 +192,7 @@ export const whatsappMsgTypeMapped = {
export const parseRenderMessageItem = (msg) => { export const parseRenderMessageItem = (msg) => {
console.log('parseRenderMessageItem', msg); console.log('parseRenderMessageItem', msg);
return { return {
date: msg?.sendTime || '', date: msg?.sendTime || msg?.createTime || '',
...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}), ...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}),
conversationid: msg.conversationid, conversationid: msg.conversationid,
...(typeof whatsappMsgTypeMapped[msg.type].type === 'function' ? whatsappMsgTypeMapped[msg.type].type(msg) : { type: whatsappMsgTypeMapped[msg.type].type || 'text' }), ...(typeof whatsappMsgTypeMapped[msg.type].type === 'function' ? whatsappMsgTypeMapped[msg.type].type(msg) : { type: whatsappMsgTypeMapped[msg.type].type || 'text' }),
@ -201,6 +201,9 @@ export const parseRenderMessageItem = (msg) => {
// status: msg?.status || 'waiting', // status: msg?.status || 'waiting',
// title: msg.customerProfile.name, // title: msg.customerProfile.name,
// replyButton: true, // replyButton: true,
customer_name: msg?.customerProfile?.name || '',
whatsapp_name: msg?.customerProfile?.name || '',
whatsapp_phone_number: msg.from,
}; };
}; };
/** /**

@ -38,23 +38,22 @@ const ConversationReducer = (state = initialState, action) => {
// 清空未读 // 清空未读
const { conversationsList } = state; const { conversationsList } = state;
const targetId = action.payload.sn; const targetId = action.payload.sn;
const newConversationList = conversationsList.map((ele) => { const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
if (String(ele.sn) === String(targetId)) { conversationsList.splice(targetIndex, 1, {
return { ...ele, unread_msg_count: 0 }; ...conversationsList[targetIndex],
} unread_msg_count: 0,
return ele;
}); });
return { ...state, currentConversation: action.payload, conversationsList: newConversationList }; return { ...state, currentConversation: action.payload, conversationsList: [...conversationsList] };
} }
case NAME_SPACE + 'SET_ACTIVE_CONVERSATIONS': { case NAME_SPACE + 'SET_ACTIVE_CONVERSATIONS': {
const { activeConversations } = state; const { activeConversations } = state;
return { ...state, activeConversations: { ...activeConversations, ...action.payload } }; return { ...state, activeConversations: { ...activeConversations, ...action.payload } };
} }
case NAME_SPACE + 'UPDATE_SENT_MESSAGE_ITEM': { case NAME_SPACE + 'UPDATE_SENT_MESSAGE_ITEM': {
console.log('UPDATE_SENT_MESSAGE_ITEM-----------------------------------------------------------------'); console.log('UPDATE_SENT_MESSAGE_ITEM-----------------------------------------------------------------', action);
// 更新会话中的消息 // 更新会话中的消息
const { activeConversations, conversationsList } = state; const { activeConversations, conversationsList, } = state;
const message = action.payload; const message = action.payload;
const targetId = message.conversationid; const targetId = message.conversationid;
const targetMsgs = (activeConversations[String(targetId)] || []).map((ele) => { const targetMsgs = (activeConversations[String(targetId)] || []).map((ele) => {
@ -72,17 +71,18 @@ const ConversationReducer = (state = initialState, action) => {
} }
// 更新列表的时间 // 更新列表的时间
const newConversationList = conversationsList.map((ele) => { if (message.type !== 'error') {
if (String(ele.sn) === String(targetId) && message.type !== 'error') { const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
return { ...ele, last_received_time: message.date }; conversationsList.splice(targetIndex, 1, {
} ...conversationsList[targetIndex],
return ele; last_received_time: message.date,
}); });
}
return { return {
...state, ...state,
activeConversations: { ...state.activeConversations, [String(targetId)]: targetMsgs }, activeConversations: { ...state.activeConversations, [String(targetId)]: targetMsgs },
conversationsList: newConversationList, conversationsList: [...conversationsList],
}; };
} }
case NAME_SPACE + 'RECEIVED_MESSAGE_LIST': { case NAME_SPACE + 'RECEIVED_MESSAGE_LIST': {
@ -97,21 +97,29 @@ const ConversationReducer = (state = initialState, action) => {
const { activeConversations, conversationsList, currentConversation } = state; const { activeConversations, conversationsList, currentConversation } = state;
const { targetId, message } = action.payload; const { targetId, message } = action.payload;
const targetMsgs = activeConversations[String(targetId)] || []; const targetMsgs = activeConversations[String(targetId)] || [];
console.log(activeConversations, String(targetId), 'sent sent sent'); const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
const newConversationList = conversationsList.map((ele) => { const newConversation =
if (String(ele.sn) === String(targetId)) { targetId !== -1
return { ? {
...ele, ...conversationsList[targetIndex],
last_received_time: message.date, last_received_time: message.date,
unread_msg_count: String(ele.sn) !== String(currentConversation.sn) ? ele.unread_msg_count + 1 : ele.unread_msg_count, unread_msg_count:
}; String(targetId) !== String(currentConversation.sn) && message.sender !== 'me'
} ? conversationsList[targetIndex].unread_msg_count + 1
return ele; : conversationsList[targetIndex].unread_msg_count,
}); }
: {
...message,
sn: targetId,
last_received_time: message.date,
unread_msg_count: message.sender === 'me' ? 0 : 1,
};
conversationsList.splice(targetIndex, 1);
conversationsList.unshift(newConversation);
return { return {
...state, ...state,
activeConversations: { ...activeConversations, [String(targetId)]: [...targetMsgs, message] }, activeConversations: { ...activeConversations, [String(targetId)]: [...targetMsgs, message] },
conversationsList: newConversationList, conversationsList: [...conversationsList],
currentConversation: { currentConversation: {
...state.currentConversation, ...state.currentConversation,
last_received_time: String(targetId) === String(currentConversation.sn) ? message.date : currentConversation.last_received_time, last_received_time: String(targetId) === String(currentConversation.sn) ? message.date : currentConversation.last_received_time,

@ -43,6 +43,7 @@ const Conversations = () => {
// statusColor: '#ccd5ae', // statusColor: '#ccd5ae',
// statusColorType: 'badge', // statusColorType: 'badge',
// statusText: 'online' // statusText: 'online'
className: String(item.sn) === String(currentConversation.sn) ? 'text-primary underline __active' : '',
})) }))
); );

Loading…
Cancel
Save