|
|
|
@ -13,21 +13,26 @@ const MessagesWrapper = () => {
|
|
|
|
|
|
|
|
|
|
const [currentConversation, updateCurrentConversation, setCurrentConversation] = useConversationStore(useShallow((state) => [state.currentConversation, state.updateCurrentConversation, state.setCurrentConversation]));
|
|
|
|
|
const conversationsList = useConversationStore(useShallow((state) => state.conversationsList));
|
|
|
|
|
const activeConversations = useConversationStore(useShallow((state) => state.activeConversations));
|
|
|
|
|
const activeMessages = useConversationStore(useShallow((state) => (state.currentConversation.sn && state.activeConversations[state.currentConversation.sn] ? state.activeConversations[state.currentConversation.sn]: [])));
|
|
|
|
|
const addToConversationList = useConversationStore((state) => state.addToConversationList);
|
|
|
|
|
|
|
|
|
|
const receivedMessageList = useConversationStore((state) => state.receivedMessageList);
|
|
|
|
|
const setMsgLoading = useConversationStore((state) => state.setMsgLoading);
|
|
|
|
|
|
|
|
|
|
const refreshTotalNotify = useConversationStore(useShallow((state) => state.refreshTotalNotify));
|
|
|
|
|
|
|
|
|
|
const [longList, setLongList] = useState([]);
|
|
|
|
|
const [longListLoading, setLongListLoading] = useState(false);
|
|
|
|
|
const [shouldScrollBottom, setShouldScrollBottom] = useState(true);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setLongList(activeMessages);
|
|
|
|
|
setShouldScrollBottom(true);
|
|
|
|
|
if (currentConversation.sn && activeMessages.length < 20) {
|
|
|
|
|
getFirstPageMessages(currentConversation);
|
|
|
|
|
}
|
|
|
|
|
if (currentConversation.opi_sn && currentConversation.whatsapp_phone_number && activeMessages.length > 0) {
|
|
|
|
|
fetchCleanUnreadMsgCount({ opisn: currentConversation.opi_sn, whatsappid: currentConversation.whatsapp_phone_number });
|
|
|
|
|
refreshTotalNotify();
|
|
|
|
|
}
|
|
|
|
|
const thisLastTime = activeMessages.length > 0 ? activeMessages[0].orgmsgtime : '';
|
|
|
|
|
const loadNextPage = !(activeMessages.length === 0 || activeMessages.length < MESSAGE_PAGE_SIZE);
|
|
|
|
@ -37,7 +42,7 @@ const MessagesWrapper = () => {
|
|
|
|
|
}, [activeMessages, currentConversation.sn]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getMessages = async (item) => {
|
|
|
|
|
const getFirstPageMessages = async (item) => {
|
|
|
|
|
setMsgLoading(true);
|
|
|
|
|
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number, lasttime: '' });
|
|
|
|
|
setMsgLoading(false);
|
|
|
|
@ -47,15 +52,6 @@ const MessagesWrapper = () => {
|
|
|
|
|
updateCurrentConversation({ lasttime: thisLastTime, loadNextPage });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const messagesList = activeConversations[`${currentConversation.sn}`] || [];
|
|
|
|
|
if (currentConversation.sn && messagesList.length < 20) {
|
|
|
|
|
getMessages(currentConversation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [currentConversation.sn]);
|
|
|
|
|
|
|
|
|
|
const getMoreMessages = async () => {
|
|
|
|
|
setShouldScrollBottom(false);
|
|
|
|
|
setLongListLoading(true);
|
|
|
|
|