import type { GlobalState, TabArgs } from '../types'; import { selectCurrentMessageList } from './messages'; import { selectChatFullInfo } from './chats'; import { selectTabState } from './tabs'; import { getCurrentTabId } from '../../util/establishMultitabRole'; export function selectStatistics( global: T, chatId: string, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).statistics.byChatId[chatId]; } export function selectIsStatisticsShown( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { if (!selectTabState(global, tabId).isStatisticsShown) { return false; } const { chatId: currentChatId } = selectCurrentMessageList(global, tabId) || {}; return currentChatId ? selectChatFullInfo(global, currentChatId)?.canViewStatistics : undefined; } export function selectIsMessageStatisticsShown( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { if (!selectTabState(global, tabId).isStatisticsShown) { return false; } return Boolean(selectTabState(global, tabId).statistics.currentMessageId); }