|
|
|
@ -268,8 +268,11 @@ const conversationSlice = (set, get) => ({
|
|
|
|
|
const targetId = conversation.sn;
|
|
|
|
|
const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
|
|
|
|
|
conversationsList.splice(targetIndex, 1);
|
|
|
|
|
const mergedListMapped = groupBy(conversationsList, 'top_state');
|
|
|
|
|
|
|
|
|
|
return set({
|
|
|
|
|
topList: mergedListMapped['1'] || [],
|
|
|
|
|
pageList: mergedListMapped['0'] || [],
|
|
|
|
|
conversationsList: [...conversationsList],
|
|
|
|
|
activeConversations: { ...activeConversations, [`${targetId}`]: [] },
|
|
|
|
|
currentConversation: {},
|
|
|
|
@ -287,11 +290,14 @@ const conversationSlice = (set, get) => ({
|
|
|
|
|
unread_msg_count: 0,
|
|
|
|
|
})
|
|
|
|
|
: null;
|
|
|
|
|
const mergedListMapped = groupBy(conversationsList, 'top_state');
|
|
|
|
|
|
|
|
|
|
return set((state) => ({
|
|
|
|
|
totalNotify: state.totalNotify - (conversation.unread_msg_count || 0),
|
|
|
|
|
currentConversation: Object.assign({}, conversation, targetItemFromList),
|
|
|
|
|
referenceMsg: {},
|
|
|
|
|
topList: mergedListMapped['1'] || [],
|
|
|
|
|
pageList: mergedListMapped['0'] || [],
|
|
|
|
|
conversationsList: [...conversationsList],
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
@ -306,7 +312,13 @@ const conversationSlice = (set, get) => ({
|
|
|
|
|
...conversation,
|
|
|
|
|
})
|
|
|
|
|
: null;
|
|
|
|
|
return set({ conversationsList: [...conversationsList] });
|
|
|
|
|
const mergedListMapped = groupBy(conversationsList, 'top_state');
|
|
|
|
|
|
|
|
|
|
return set({
|
|
|
|
|
topList: mergedListMapped['1'] || [],
|
|
|
|
|
pageList: mergedListMapped['0'] || [],
|
|
|
|
|
conversationsList: [...conversationsList]
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -379,10 +391,14 @@ const messageSlice = (set, get) => ({
|
|
|
|
|
},
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
const mergedList = [...newConversations, ...conversationsList]
|
|
|
|
|
const mergedListMapped = groupBy(mergedList, 'top_state');
|
|
|
|
|
|
|
|
|
|
return set({
|
|
|
|
|
topList: mergedListMapped['1'] || [],
|
|
|
|
|
pageList: mergedListMapped['0'] || [],
|
|
|
|
|
conversationsList: mergedList,
|
|
|
|
|
activeConversations: { ...activeConversations, [String(targetId)]: targetMsgs },
|
|
|
|
|
conversationsList: [...newConversations, ...conversationsList],
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
sentOrReceivedNewMessage: (targetId, message) => {
|
|
|
|
@ -425,6 +441,8 @@ const messageSlice = (set, get) => ({
|
|
|
|
|
// console.log('find in list, i:', targetIndex);
|
|
|
|
|
// console.log('find in list, chat updated and Top: \n', JSON.stringify(newConversation, null, 2));
|
|
|
|
|
// console.log('list updated : \n', JSON.stringify(conversationsList, null, 2));
|
|
|
|
|
const mergedListMapped = groupBy(conversationsList, 'top_state');
|
|
|
|
|
|
|
|
|
|
const isCurrent = Number(targetId) === Number(currentConversation.sn);
|
|
|
|
|
const updatedCurrent = isCurrent
|
|
|
|
|
? {
|
|
|
|
@ -436,6 +454,8 @@ const messageSlice = (set, get) => ({
|
|
|
|
|
: {...currentConversation, last_message: message,};
|
|
|
|
|
return set({
|
|
|
|
|
currentConversation: updatedCurrent,
|
|
|
|
|
topList: mergedListMapped['1'] || [],
|
|
|
|
|
pageList: mergedListMapped['0'] || [],
|
|
|
|
|
conversationsList: [...conversationsList],
|
|
|
|
|
totalNotify: totalNotify + (message.sender === 'me' ? 0 : 1),
|
|
|
|
|
activeConversations: { ...activeConversations, [String(targetId)]: [...targetMsgs, message] },
|
|
|
|
|