|
|
|
@ -2,7 +2,7 @@ import { create } from 'zustand';
|
|
|
|
|
import { RealTimeAPI } from '@/channel/realTimeAPI';
|
|
|
|
|
import { olog, isEmpty } from '@/utils/commons';
|
|
|
|
|
import { receivedMsgTypeMapped, handleNotification } from '@/channel/whatsappUtils';
|
|
|
|
|
import { fetchConversationsList, fetchTemplates, fetchConversationsSearch } from '@/actions/ConversationActions';
|
|
|
|
|
import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK } from '@/actions/ConversationActions';
|
|
|
|
|
import { devtools } from 'zustand/middleware';
|
|
|
|
|
import { WS_URL } from '@/config';
|
|
|
|
|
|
|
|
|
@ -171,6 +171,7 @@ const conversationSlice = (set, get) => ({
|
|
|
|
|
addToConversationList: (newList) => {
|
|
|
|
|
const { activeConversations, conversationsList } = get();
|
|
|
|
|
const conversationsIds = Object.keys(activeConversations);
|
|
|
|
|
// const conversationsIds = conversationsList.map((chatItem) => `${chatItem.sn}`);
|
|
|
|
|
const newConversations = newList.filter((conversation) => !conversationsIds.includes(`${conversation.sn}`));
|
|
|
|
|
const newConversationsMapped = newConversations.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
|
|
|
|
|
|
|
|
|
@ -178,7 +179,7 @@ const conversationSlice = (set, get) => ({
|
|
|
|
|
const withoutNew = conversationsList.filter((item) => !newListIds.includes(`${item.sn}`));
|
|
|
|
|
|
|
|
|
|
const mergedList = [...newList, ...withoutNew];
|
|
|
|
|
const refreshTotalNotify = mergedList.reduce((r, c) => r+(c.unread_msg_count === 999 ? 0 : c.unread_msg_count), 0);
|
|
|
|
|
const refreshTotalNotify = mergedList.reduce((r, c) => r+(c.unread_msg_count === UNREAD_MARK ? 0 : c.unread_msg_count), 0);
|
|
|
|
|
|
|
|
|
|
return set((state) => ({
|
|
|
|
|
conversationsList: mergedList,
|
|
|
|
@ -237,7 +238,7 @@ const messageSlice = (set, get) => ({
|
|
|
|
|
totalNotify: 0,
|
|
|
|
|
msgListLoading: false,
|
|
|
|
|
activeConversations: {},
|
|
|
|
|
refreshTotalNotify: () => set((state) => ({ totalNotify: state.conversationsList.reduce((r, c) => r+(c.unread_msg_count === 999 ? 0 : c.unread_msg_count), 0) })),
|
|
|
|
|
refreshTotalNotify: () => set((state) => ({ totalNotify: state.conversationsList.reduce((r, c) => r+(c.unread_msg_count === UNREAD_MARK ? 0 : c.unread_msg_count), 0) })),
|
|
|
|
|
setMsgLoading: (msgListLoading) => set({ msgListLoading }),
|
|
|
|
|
receivedMessageList: (conversationid, msgList) =>
|
|
|
|
|
set((state) => ({
|
|
|
|
|