|
|
|
@ -46,7 +46,7 @@ const Conversations = () => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
|
const { userId } = loginUser;
|
|
|
|
|
const { activeConversations, currentConversation, conversationsList, addToConversationList, setCurrentConversation, receivedMessageList, } = useConversationStore();
|
|
|
|
|
const { activeConversations, currentConversation, conversationsList, addToConversationList, setCurrentConversation, receivedMessageList, setMsgLoading } = useConversationStore();
|
|
|
|
|
const [chatlist, setChatlist] = useState([]);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setChatlist(
|
|
|
|
@ -97,11 +97,15 @@ const Conversations = () => {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const getMessages = async (item) => {
|
|
|
|
|
setMsgLoading(true);
|
|
|
|
|
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number });
|
|
|
|
|
receivedMessageList(item.sn, data);
|
|
|
|
|
};
|
|
|
|
|
const switchConversation = async (item) => {
|
|
|
|
|
const messagesList = activeConversations[`${item.sn}`] || [];
|
|
|
|
|
if (messagesList.length < 20) {
|
|
|
|
|
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number });
|
|
|
|
|
receivedMessageList(item.sn, data);
|
|
|
|
|
await getMessages(item);
|
|
|
|
|
}
|
|
|
|
|
if (String(item.sn) === String(currentConversation.sn)) {
|
|
|
|
|
return false;
|
|
|
|
|