import type { ApiMessage } from '../../api/types'; import type { PerformanceTypeKey } from '../../types'; import type { GlobalState, TabArgs } from '../types'; import { NewChatMembersProgress, RightColumnContent } from '../../types'; import { getCurrentTabId } from '../../util/establishMultitabRole'; import { getMessageVideo, getMessageWebPageVideo } from '../helpers'; import { selectCurrentTextSearch } from './localSearch'; import { selectCurrentManagement } from './management'; import { selectIsStatisticsShown } from './statistics'; import { selectTabState } from './tabs'; export function selectIsMediaViewerOpen( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { const { mediaViewer } = selectTabState(global, tabId); return Boolean(mediaViewer.mediaId || mediaViewer.avatarOwnerId); } export function selectRightColumnContentKey( global: T, isMobile?: boolean, ...[tabId = getCurrentTabId()]: TabArgs ) { const tabState = selectTabState(global, tabId); return tabState.editTopicPanel ? ( RightColumnContent.EditTopic ) : tabState.createTopicPanel ? ( RightColumnContent.CreateTopic ) : tabState.pollResults.messageId ? ( RightColumnContent.PollResults ) : !isMobile && selectCurrentTextSearch(global, tabId) ? ( RightColumnContent.Search ) : selectCurrentManagement(global, tabId) ? ( RightColumnContent.Management ) : tabState.isStatisticsShown && tabState.statistics.currentMessageId ? ( RightColumnContent.MessageStatistics ) : selectIsStatisticsShown(global, tabId) ? ( RightColumnContent.Statistics ) : tabState.boostStatistics ? ( RightColumnContent.BoostStatistics ) : tabState.stickerSearch.query !== undefined ? ( RightColumnContent.StickerSearch ) : tabState.gifSearch.query !== undefined ? ( RightColumnContent.GifSearch ) : tabState.newChatMembersProgress !== NewChatMembersProgress.Closed ? ( RightColumnContent.AddingMembers ) : tabState.isChatInfoShown && tabState.messageLists.length ? ( RightColumnContent.ChatInfo ) : undefined; } export function selectIsRightColumnShown( global: T, isMobile?: boolean, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectRightColumnContentKey(global, isMobile, tabId) !== undefined; } export function selectTheme(global: T) { const { theme } = global.settings.byKey; return theme; } export function selectIsForumPanelOpen( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { const tabState = selectTabState(global, tabId); return Boolean(tabState.forumPanelChatId) && ( tabState.globalSearch.query === undefined || Boolean(tabState.globalSearch.isClosing) ); } export function selectIsForumPanelClosed( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return !selectIsForumPanelOpen(global, tabId); } export function selectIsReactionPickerOpen( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { const { reactionPicker } = selectTabState(global, tabId); return Boolean(reactionPicker?.position); } export function selectPerformanceSettings(global: T) { return global.settings.performance; } export function selectPerformanceSettingsValue( global: T, key: PerformanceTypeKey, ) { return global.settings.performance[key]; } export function selectCanAutoPlayMedia(global: T, message: ApiMessage) { const video = getMessageVideo(message) || getMessageWebPageVideo(message); if (!video) { return undefined; } const canAutoPlayVideos = selectPerformanceSettingsValue(global, 'autoplayVideos'); const canAutoPlayGifs = selectPerformanceSettingsValue(global, 'autoplayGifs'); const asGif = video.isGif || video.isRound; return (canAutoPlayVideos && !asGif) || (canAutoPlayGifs && asGif); } export function selectShouldLoopStickers(global: T) { return selectPerformanceSettingsValue(global, 'loopAnimatedStickers'); } export function selectCanPlayAnimatedEmojis(global: T) { return selectPerformanceSettingsValue(global, 'animatedEmoji'); } export function selectCanAnimateInterface(global: T) { return selectPerformanceSettingsValue(global, 'pageTransitions'); } export function selectIsContextMenuTranslucent(global: T) { return selectPerformanceSettingsValue(global, 'contextMenuBlur'); }