import type { FC } from '../../lib/teact/teact'; import React, { memo } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../lib/teact/teactn'; import { createMessageHash } from '../../util/routing'; import useHistoryBack from '../../hooks/useHistoryBack'; import type { MessageList as GlobalMessageList } from '../../global/types'; type StateProps = { messageLists?: GlobalMessageList[]; }; // Actual `MessageList` components are unmounted when deep in the history, // so we need a separate component just for handling history const MessageListHistoryHandler: FC = ({ messageLists }) => { const { openChat } = getActions(); const closeChat = () => { openChat({ id: undefined }, { forceSyncOnIOs: true }); }; const MessageHistoryRecord: FC = ({ chatId, type, threadId }) => { useHistoryBack({ isActive: true, hash: createMessageHash(chatId, type, threadId), onBack: closeChat, }); }; return (
{messageLists?.map((messageList, i) => ( ))}
); }; export default memo(withGlobal( (global): StateProps => { return { messageLists: global.messages.messageLists, }; }, )(MessageListHistoryHandler));