diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index e54330e66..a7810ae5e 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -381,6 +381,20 @@ async function getFullChannelInfo( ) || {}; const botCommands = botInfo ? buildApiChatBotCommands(botInfo) : undefined; + if (result?.chats?.length > 1) { + updateLocalDb(result); + + const [, mtpLinkedChat] = result.chats; + const chat = buildApiChatFromPreview(mtpLinkedChat, undefined, true); + if (chat) { + onUpdate({ + '@type': 'updateChat', + id: chat.id, + chat, + }); + } + } + return { fullInfo: { about, diff --git a/src/components/middle/HeaderMenuContainer.tsx b/src/components/middle/HeaderMenuContainer.tsx index 9b16d80bd..5cf4a8488 100644 --- a/src/components/middle/HeaderMenuContainer.tsx +++ b/src/components/middle/HeaderMenuContainer.tsx @@ -23,7 +23,7 @@ import DeleteChatModal from '../common/DeleteChatModal'; import './HeaderMenuContainer.scss'; type DispatchProps = Pick; export type OwnProps = { @@ -49,6 +49,7 @@ type StateProps = { isPrivate?: boolean; isMuted?: boolean; canDeleteChat?: boolean; + hasLinkedChat?: boolean; }; const HeaderMenuContainer: FC = ({ @@ -66,6 +67,7 @@ const HeaderMenuContainer: FC = ({ isPrivate, isMuted, canDeleteChat, + hasLinkedChat, onSubscribeChannel, onSearchClick, onClose, @@ -74,6 +76,7 @@ const HeaderMenuContainer: FC = ({ enterMessageSelectMode, sendBotCommand, restartBot, + openLinkedChat, }) => { const [isMenuOpen, setIsMenuOpen] = useState(true); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); @@ -109,6 +112,11 @@ const HeaderMenuContainer: FC = ({ closeMenu(); }, [chatId, closeMenu, isMuted, updateChatMutedState]); + const handleLinkedChatClick = useCallback(() => { + openLinkedChat({ id: chatId }); + closeMenu(); + }, [chatId, closeMenu, openLinkedChat]); + const handleSubscribe = useCallback(() => { onSubscribeChannel(); closeMenu(); @@ -181,6 +189,14 @@ const HeaderMenuContainer: FC = ({ {lang(isMuted ? 'ChatsUnmute' : 'ChatsMute')} )} + {hasLinkedChat && ( + + {lang('ViewDiscussion')} + + )} ( isMuted: selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global)), isPrivate: isChatPrivate(chat.id), canDeleteChat: getCanDeleteChat(chat), + hasLinkedChat: Boolean(chat?.fullInfo?.linkedChatId), }; }, (setGlobal, actions): DispatchProps => pick(actions, [ @@ -230,5 +247,6 @@ export default memo(withGlobal( 'enterMessageSelectMode', 'sendBotCommand', 'restartBot', + 'openLinkedChat', ]), )(HeaderMenuContainer)); diff --git a/src/global/types.ts b/src/global/types.ts index a858aaa16..674873b0a 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -452,7 +452,7 @@ export type ActionTypes = ( 'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' | 'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' | // chats - 'preloadTopChatMessages' | 'loadChats' | 'loadMoreChats' | 'openChat' | 'openChatWithInfo' | + 'preloadTopChatMessages' | 'loadChats' | 'loadMoreChats' | 'openChat' | 'openChatWithInfo' | 'openLinkedChat' | 'openSupportChat' | 'openTipsChat' | 'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' | 'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' | diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 5d2b341e0..b670b8e75 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -124,6 +124,22 @@ addReducer('openChat', (global, actions, payload) => { } }); +addReducer('openLinkedChat', (global, actions, payload) => { + const { id } = payload!; + const chat = selectChat(global, id); + if (!chat) { + return; + } + + (async () => { + const chatFullInfo = await callApi('fetchFullChat', chat); + + if (chatFullInfo?.fullInfo?.linkedChatId) { + actions.openChat({ id: chatFullInfo.fullInfo.linkedChatId }); + } + })(); +}); + addReducer('openSupportChat', (global, actions) => { const chat = selectSupportChat(global);