Middle Header Menu: Open discussion (#1438)

This commit is contained in:
Alexander Zinchuk 2021-09-13 20:02:39 +03:00
parent 0c9fe4643a
commit 61a8ec1d75
4 changed files with 50 additions and 2 deletions

View File

@ -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,

View File

@ -23,7 +23,7 @@ import DeleteChatModal from '../common/DeleteChatModal';
import './HeaderMenuContainer.scss';
type DispatchProps = Pick<GlobalActions, (
'updateChatMutedState' | 'enterMessageSelectMode' | 'sendBotCommand' | 'restartBot'
'updateChatMutedState' | 'enterMessageSelectMode' | 'sendBotCommand' | 'restartBot' | 'openLinkedChat'
)>;
export type OwnProps = {
@ -49,6 +49,7 @@ type StateProps = {
isPrivate?: boolean;
isMuted?: boolean;
canDeleteChat?: boolean;
hasLinkedChat?: boolean;
};
const HeaderMenuContainer: FC<OwnProps & StateProps & DispatchProps> = ({
@ -66,6 +67,7 @@ const HeaderMenuContainer: FC<OwnProps & StateProps & DispatchProps> = ({
isPrivate,
isMuted,
canDeleteChat,
hasLinkedChat,
onSubscribeChannel,
onSearchClick,
onClose,
@ -74,6 +76,7 @@ const HeaderMenuContainer: FC<OwnProps & StateProps & DispatchProps> = ({
enterMessageSelectMode,
sendBotCommand,
restartBot,
openLinkedChat,
}) => {
const [isMenuOpen, setIsMenuOpen] = useState(true);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
@ -109,6 +112,11 @@ const HeaderMenuContainer: FC<OwnProps & StateProps & DispatchProps> = ({
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<OwnProps & StateProps & DispatchProps> = ({
{lang(isMuted ? 'ChatsUnmute' : 'ChatsMute')}
</MenuItem>
)}
{hasLinkedChat && (
<MenuItem
icon="comments"
onClick={handleLinkedChatClick}
>
{lang('ViewDiscussion')}
</MenuItem>
)}
<MenuItem
icon="select"
onClick={handleSelectMessages}
@ -223,6 +239,7 @@ export default memo(withGlobal<OwnProps>(
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<OwnProps>(
'enterMessageSelectMode',
'sendBotCommand',
'restartBot',
'openLinkedChat',
]),
)(HeaderMenuContainer));

View File

@ -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' |

View File

@ -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);