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